fix: Allow organization admins to access subteams without direct membership #24305
+87
−15
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What does this PR do?
This PR fixes a permission inheritance issue where organization admins could not access subteams despite having admin privileges at the organization level.
Problem: The
get.handler.ts
only checked for direct team membership usingMembershipRepository.findUniqueByUserIdAndTeamId()
, which prevented org admins from accessing subteams they weren't explicitly added to as members.Solution:
UserRepository.isAdminOfTeamOrParentOrg()
when direct membership is not foundKey Changes:
packages/trpc/server/routers/viewer/teams/get.handler.ts
as any
type casts with propervi.mocked()
usageMandatory Tasks (DO NOT REMOVE)
How should this be tested?
Test Setup:
Expected Behavior:
Verification:
TZ=UTC yarn test packages/trpc/server/routers/viewer/teams/get.handler.test.ts
yarn type-check:ci --force
Human Review Checklist
isAdminOfTeamOrParentOrg()
works correctly for your organization structureRequested by: @joeauyeung
Link to Devin run: https://app.devin.ai/sessions/b23656890ad8435fb46ee43d14c3ebf1