Files
b2239374bc fix: Remove team members as org admin (#24020)
* Fallback to org admin

* Prevent accidental privilege escalation as code changes in the future

* When org admin, we don't actually need to do the db query

* Use findMany and Map to drill down permission adjustments

* Exclude .MEMBER from overriding role, we likely don't want to demote

* refactor logic

* Add tests for services/factories + removeHandler

* fix type check

---------

Co-authored-by: Alex van Andel <[email protected]>
Co-authored-by: Sean Brydon <[email protected]>
2025-09-24 09:33:31 +01:00

32 lines
872 B
TypeScript

import type { MembershipRole } from "@calcom/prisma/enums";
export interface RemoveMemberContext {
userId: number;
isOrgAdmin: boolean;
memberIds: number[];
teamIds: number[];
isOrg: boolean;
}
export interface RemoveMemberPermissionResult {
hasPermission: boolean;
userRoles?: Map<number, MembershipRole | null>;
}
export interface IRemoveMemberService {
/**
* Checks if the user has permission to remove members from teams
*/
checkRemovePermissions(context: RemoveMemberContext): Promise<RemoveMemberPermissionResult>;
/**
* Validates that the removal can proceed (e.g., owner checks)
*/
validateRemoval(context: RemoveMemberContext, hasPermission: boolean): Promise<void>;
/**
* Performs the actual removal of members from teams
*/
removeMembers(memberIds: number[], teamIds: number[], isOrg: boolean): Promise<void>;
}