Skip to content

[INFRA-1174] fix(security): scope project stats and grouping keys - #10065

Merged
sriramveeraghanta merged 3 commits into
previewfrom
fix/infra-1174-scope-workspace-project-stats
Oct 18, 2026
Merged

sriramveeraghanta merged 3 commits into
previewfrom
fix/infra-1174-scope-workspace-project-stats

Conversation

@dheeru0198

@dheeru0198 dheeru0198 commented Oct 16, 2026 •

Copy link
Copy Markdown
Member

Description

Three workspace-level endpoints built project-derived values from every project in the workspace instead of the projects the caller can see.

  • ProjectStatsEndpoint (project-stats) now applies the project list visibility rules from ProjectViewSet.list: workspace admins see every project, members see projects they belong to plus public ones, guests only projects they belong to. The analytics overview "Active projects" widget is unchanged for admins.
  • AdvanceAnalyticsEndpoint overview: when project_ids is passed, member counts are taken only from those projects that pass get_analytics_filters' project_filters (URL workspace, caller is an active member, not deleted/archived), like the other overview counts.
  • issue_group_values takes an optional user. Group keys come from the given project or, workspace-wide, from the projects the user is an active member of. This covers project, state, cycle, module and label keys. WorkspaceUserProfileIssuesEndpoint (user-issues) passes request.user. With a project_id, group_by=project_id now returns only that project.
  • The public board copy (plane/space/utils/grouper.py) takes project, state, label, cycle and module keys only from the board's project.

Behaviour change: members and guests get fewer rows from project-stats. Workspace-level grouped user-issues responses no longer include empty groups for projects, states, cycles, modules or labels outside the caller's projects. Public board issues grouped by project return only the board's project.

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • Feature (non-breaking change which adds functionality)
  • Improvement (change that would cause existing functionality to not work as expected)
  • Code refactoring
  • Performance improvements
  • Documentation update

Screenshots and Media (if applicable)

Test Scenarios

  • project-stats as a workspace member → own and public projects only; as a guest → own projects only; as an admin → every project.
  • advance-analytics/?tab=overview&project_ids=<project the caller is not in>,<project in another workspace> → total_users.count == 0; with the caller's own project → that project's member count.
  • user-issues/<id>/?group_by=project_id|state_id|cycle_id → keys include the caller's project, state and cycle, and exclude ones from a project the caller is not in.
  • Public board issues/?group_by=project_id|state_id|cycle_id → keys from the board's project only; project_id returns exactly that project.
  • issue_group_values called with neither project_id nor user → ValueError (plane/tests/unit/utils/test_grouper.py).
  • plane/tests/contract/app/test_workspace_stats_grouping_project_scope_app.py: 11 passed; 6 fail without the fix (the 2 positive controls pass either way), and the public project_id case fails without the space grouper change. Together with the paginator, order_queryset, project, workspace, cycle-issue, module-issue and issue-list guest suites: 52 passed.

References

  • INFRA-1174
  • INFRA-1127
  • INFRA-1191

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Project statistics now reflect what each viewer can access: workspace admins see all projects, members see their projects and public projects, and guests see only projects they belong to.
    • Analytics member counts include active, non-bot members of projects the viewer can access and exclude deleted project memberships.
    • Grouped issue results now respect the viewer’s project access, including when grouping by project, state, or cycle.

Project stats follow the project list visibility rules, the advance analytics overview
counts members only of the caller's projects in the workspace, and workspace-level issue
grouping builds project/state/cycle/module/label keys from the caller's projects.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Copilot AI balanced review requested due to automatic review settings October 16, 2026 21:10

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

@coderabbitai

coderabbitai Bot commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 312d6f38-fd1f-4543-8d70-f4a3f2f52d49
📥 Commits

Reviewing files that changed from the base of the PR and between f931003 and faaa2a0.

📒 Files selected for processing: 2
  • apps/api/plane/tests/unit/utils/test_grouper.py
  • apps/api/plane/utils/grouper.py

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 3 remain after this review.

📝 Walkthrough

Project statistics, analytics member counts, and issue grouping now apply project scopes based on requester roles or active project memberships.

Changes: Workspace project scope

Layer / File(s) Summary
Project statistics visibility
apps/api/plane/app/views/analytic/base.py, apps/api/plane/tests/contract/app/test_workspace_stats_grouping_project_scope_app.py
Admins retain all workspace projects. Members see projects they belong to and public projects. Guests and other non-admin roles see only projects they belong to. Contract tests cover these visibility rules.
Issue grouping project scope
apps/api/plane/utils/grouper.py, apps/api/plane/app/views/workspace/user.py, apps/api/plane/tests/contract/app/test_workspace_stats_grouping_project_scope_app.py, apps/api/plane/tests/unit/utils/test_grouper.py
issue_group_values scopes choices to the explicit project or the user's active workspace project memberships. Workspace profile issue paths pass the requesting user. Tests cover grouping keys and the error when neither a project nor a user is supplied.
Analytics member-count scope
apps/api/plane/app/views/analytic/advance.py, apps/api/plane/tests/contract/app/test_workspace_stats_grouping_project_scope_app.py
When project IDs are supplied, analytics counts use matching projects with non-deleted project memberships. Contract tests check counts for projects within and outside the caller's membership scope.

Priority: ➖ Normal

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix

Merge Risk: ⚪ Minimal · up to faaa2

The reviewed scope changes preserve the intended project visibility and analytics counts, and grouped issue paths provide the required scope. No actionable merge-blocking risk remains.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 18.18% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 22 functions across 6 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Title check Passed The title clearly and concisely describes the main security changes: scoping project statistics and grouping keys.
Description check Passed The description follows the repository template. It explains the changes, marks the bug-fix type, documents test scenarios and results, and lists related references. The screenshots section is not app…
Full details: Description check

Explanation

The description follows the repository template. It explains the changes, marks the bug-fix type, documents test scenarios and results, and lists related references. The screenshots section is not applicable.

  • Fix all pre-merge checks with AI
✨ Finishing Touches: 💡 1
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@lovelace3 lovelace3 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No blocking findings.

Verified

  • test_workspace_stats_grouping_project_scope_app.py: 8 passed at the head. With advance.py, analytic/base.py, workspace/user.py and grouper.py reset to the merge-base, 6 fail and the 2 positive controls pass, which matches the description. Worktree restored and clean. Neighbouring suites (unit/utils/test_paginator.py, test_order_queryset.py, test_avatar_url_annotation.py): 18 passed.
  • project-stats now uses the same visibility as ProjectViewSet.list (guest: member projects only; member: member projects or network=2; admin: all).
  • Every other issue_group_values caller passes project_id: the project, cycle, module and archived issue lists, and space has its own copy. Their keys are unchanged, apart from group_by=project_id now returning only that project. user-issues is the only workspace-wide caller, and its issue queryset is already limited to the caller's active project memberships, so no issue loses its group.
  • The overview total_users with project_ids is now limited by project_filters (URL workspace, active membership, not archived or deleted). The other overview counts already were.

Minor (non-blocking): inline note on the helper default.

project_ids = (
[project_id]
if project_id
else ProjectMember.objects.filter(workspace__slug=slug, member=user, is_active=True).values("project_id")

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: with neither project_id nor user, this becomes ProjectMember.filter(member=None), which is member_id IS NULL, so every key list comes back empty. GroupedOffsetPaginator.__query_grouper only keeps results whose key is in group_by_fields, so for a non-m2m group_by such a caller would return 200 with every issue silently dropped. No current caller hits this: user-issues passes user, and the others pass project_id. The shared helper does make it easy to hit later, though. Consider raising (or asserting) when both are missing, instead of defaulting user=None.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in faaa2a0 (raises when neither project_id nor user is given).

dheeru0198 and others added 2 commits October 17, 2026 11:06
- issue_group_values raises ValueError when called with neither project_id nor user
- Add a unit test for it

Co-Authored-By: Claude Opus 5.5 <[email protected]>
- Public board grouping (space issue_group_values) takes project, state, label,
  cycle and module keys only from the board's project.
- Test: public issues endpoint grouped by project/state/cycle returns only keys
  from the board's project.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

@lovelace3 lovelace3 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Follow-up on fe59389.

All earlier findings resolved; no new findings.

  • Minor, issue_group_values silently returned empty keys when given neither project_id nor user: resolved. It now raises ValueError. I checked every caller for the case where the new raise would turn a legitimate request into a 500, and none hits it:
    • The issue, cycle, module and archived-issue lists, where group_by and sub_group_by both pass project_id from a <uuid:project_id> URL kwarg, so it is never empty.
    • user-issues, which passes user=request.user.
    • Space has its own copy of the helper. That copy always receives deploy_board.entity_identifier.
    • A throwaway probe hit all five endpoints with group/sub-group combinations: all 200.
  • New in fe59389, space grouper: group_by=project_id on a public board used to return every project id in the workspace as group keys. It now returns only the board's project. For state, label, module and cycle the change is behaviour-neutral, because space always passed project_id and the old code already filtered on it. No issue loses its group, since the public queryset is already limited to the board's project.

Tests: test_workspace_stats_grouping_project_scope_app.py + unit/utils/test_grouper.py, 12 passed. With both grouper.py files reverted to f931003, 2 fail: the public-board project_id case and the unit test. The state_id / cycle_id public-board cases pass on the old code as well, which is expected given the note above, so they are guards rather than regression tests.

@sriramveeraghanta
sriramveeraghanta merged commit a8d6573 into preview Oct 18, 2026
16 checks passed
@sriramveeraghanta
sriramveeraghanta deleted the fix/infra-1174-scope-workspace-project-stats branch October 18, 2026 10:58
sriramveeraghanta pushed a commit that referenced this pull request Oct 22, 2026
…0065)

* [INFRA-1174] fix(security): scope project stats and grouping keys

Project stats follow the project list visibility rules, the advance analytics overview
counts members only of the caller's projects in the workspace, and workspace-level issue
grouping builds project/state/cycle/module/label keys from the caller's projects.

* [INFRA-1174] fix(security): address review feedback

- issue_group_values raises ValueError when called with neither project_id nor user
- Add a unit test for it

* [INFRA-1174] fix(security): address review feedback

- Public board grouping (space issue_group_values) takes project, state, label,
  cycle and module keys only from the board's project.
- Test: public issues endpoint grouped by project/state/cycle returns only keys
  from the board's project.
Pawel-Kranzberg added a commit to OSM-Piatnica/pi-plane that referenced this pull request Oct 25, 2026
fix(security): scope project stats and grouping keys (upstream makeplane#10065)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants