Fix admin viewer unable to see all organizations#22940
Conversation
The /organization/list endpoint only checked for PROXY_ADMIN role, causing PROXY_ADMIN_VIEW_ONLY users to fall into the else branch which restricts results to orgs the user is a member of. Use the existing _user_has_admin_view() helper to include both roles.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Greptile SummaryThis PR fixes a bug where Fix is correct and minimal: swapping the hardcoded role check for the shared helper is the right approach and keeps the logic consistent with the rest of the management endpoints. No tests included: the PR does not add any test to verify that a Confidence Score: 4/5
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[GET /organization/list] --> B{_user_has_admin_view?}
B -- "PROXY_ADMIN or\nPROXY_ADMIN_VIEW_ONLY" --> C[find_many — all orgs\nwith optional filters]
B -- "Other role" --> D[find_many — org memberships\nfor this user]
D --> E{Any memberships?}
E -- No --> F[Return empty list]
E -- Yes --> G{org_id filter provided?}
G -- "Yes, user is member" --> H[find_many filtered by org_id]
G -- "Yes, user not member" --> F
G -- No --> I[find_many filtered by membership IDs]
C --> J[Return organizations]
H --> J
I --> J
Last reviewed commit: 8d539db |
| # if proxy admin or admin viewer - get all orgs (with optional filters) | ||
| if _user_has_admin_view(user_api_key_dict): |
There was a problem hiding this comment.
No test coverage for the fix
The PR claims to fix a bug for PROXY_ADMIN_VIEW_ONLY users, but no test is added to verify the behaviour. Per the project's review policy, a bug-fix PR should include evidence that the issue is resolved (e.g. a unit/integration test asserting that a PROXY_ADMIN_VIEW_ONLY key returns all organisations from this endpoint).
A minimal test could mock prisma_client and assert that calling list_organization with a PROXY_ADMIN_VIEW_ONLY UserAPIKeyAuth returns all organisations rather than only the user's memberships.
Context Used: Rule from dashboard - What: Ensure that any PR claiming to fix an issue includes evidence that the issue is resolved, such... (source)
Type
🐛 Bug Fix
Changes
The /organization/list endpoint only checked for PROXY_ADMIN role, causing PROXY_ADMIN_VIEW_ONLY users to fall into the else branch which restricts results to orgs the user is a member of. Use the existing _user_has_admin_view() helper to include both roles.