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

* refactor(teams): improve membership validation for org admins

- Add organization scope validation to removeMember handler
- Ensure team operations are scoped to users organization context
- Update related tests

* test(teams): align removeMember tests with updated interface

- Add organizationId to test contexts
- Add team.findMany mock for org validation
- Add test cases for org scope validation

* refactor(teams): use TeamRepository for org validation in LegacyRemoveMemberService

- 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>

---------

Co-authored-by: [email protected] <[email protected]>
Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
authored and GitHub committed 2026-01-19 11:26:05 -03:00
1 parent 62216f2db6
commit ea66a9093c
7 files changed
+148 -22

No files matched your search

@@ -614,6 +614,16 @@ export class TeamRepository {
});
}
async findByIdsAndOrgId({ teamIds, orgId }: { teamIds: number[]; orgId: number }) {
return await this.prismaClient.team.findMany({
where: {
id: { in: teamIds },
OR: [{ id: orgId }, { parentId: orgId }],
},
select: { id: true },
});
}
async findTeamBySlugWithAdminRole(teamSlug: string, userId: number) {
return this.prismaClient.team.findFirst({
select: { id: true },