Skip to content

fix(teams): add organization scope to membership operations #26964

Merged
keithwillcode merged 4 commits intomainfrom
refactor/team-membership-validation
Jan 19, 2026
Merged

fix(teams): add organization scope to membership operations #26964
keithwillcode merged 4 commits intomainfrom
refactor/team-membership-validation

Conversation

@pedroccastro
Copy link
Copy Markdown
Contributor

@pedroccastro pedroccastro commented Jan 17, 2026

What does this PR do?

Adds organization scope validation to the removeMember handler when PBAC is disabled. Org admin operations now verify that target teams belong to the admin's organization before proceeding.

Changes

Layer File(s) Change
Interface IRemoveMemberService.ts Add organizationId to context
Handler removeMember.handler.ts Pass organization context to service
Service LegacyRemoveMemberService.ts Validate team ownership before granting permission
Tests removeMember.handler.test.ts Update tests for new context fields

Technical Details

New validation in LegacyRemoveMemberService.checkRemovePermissions():

// Verify all target teams belong to admin's organization
const teams = await prisma.team.findMany({
  where: {
    id: { in: teamIds },
    OR: [{ id: organizationId }, { parentId: organizationId }],
  },
});

How should this be tested?

  1. As org admin, remove member from own team → should work
  2. As org admin, remove member from own org → should work
  3. As org admin, attempt to remove member from unrelated team → should return UNAUTHORIZED
  4. As non-admin with OWNER/ADMIN role, remove member → should work (existing flow)

Mandatory Tasks

  • I have self-reviewed the code.
  • N/A I have updated the developer docs in /docs if this PR makes changes that would require a documentation change
  • I confirm automated tests are in place that prove my fix is effective or that my feature works.

- Add organization scope validation to removeMember handler
- Ensure team operations are scoped to users organization context
- Update related tests
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jan 17, 2026

E2E results are ready!

- Add organizationId to test contexts
- Add team.findMany mock for org validation
- Add test cases for org scope validation
@pull-request-size pull-request-size Bot added size/L and removed size/M labels Jan 17, 2026
@pedroccastro pedroccastro marked this pull request as ready for review January 19, 2026 12:27
@graphite-app graphite-app Bot added foundation core area: core, team members only labels Jan 19, 2026
@graphite-app graphite-app Bot requested a review from a team January 19, 2026 12:27
Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

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

No issues found across 5 files

keithwillcode and others added 2 commits January 19, 2026 13:57
…eMemberService

- Add findByIdsAndOrgId method to TeamRepository
- Inject TeamRepository into LegacyRemoveMemberService via constructor
- Update RemoveMemberServiceFactory to instantiate and inject TeamRepository
- Update tests to mock TeamRepository instead of direct prisma calls

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@keithwillcode keithwillcode merged commit ea66a90 into main Jan 19, 2026
48 checks passed
@keithwillcode keithwillcode deleted the refactor/team-membership-validation branch January 19, 2026 14:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants