* 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 <me@alexvanandel.com> Co-authored-by: Sean Brydon <sean@cal.com>
22 lines
898 B
TypeScript
22 lines
898 B
TypeScript
import { FeaturesRepository } from "@calcom/features/flags/features.repository";
|
|
import { prisma } from "@calcom/prisma";
|
|
|
|
import type { IRemoveMemberService } from "./IRemoveMemberService";
|
|
import { LegacyRemoveMemberService } from "./LegacyRemoveMemberService";
|
|
import { PBACRemoveMemberService } from "./PBACRemoveMemberService";
|
|
|
|
export class RemoveMemberServiceFactory {
|
|
/**
|
|
* Creates the appropriate RemoveMemberService based on whether PBAC is enabled
|
|
* Caches the service per team/org to avoid repeated feature flag checks
|
|
*/
|
|
static async create(teamId: number): Promise<IRemoveMemberService> {
|
|
const featuresRepository = new FeaturesRepository(prisma);
|
|
const isPBACEnabled = await featuresRepository.checkIfTeamHasFeature(teamId, "pbac");
|
|
|
|
const service = isPBACEnabled ? new PBACRemoveMemberService() : new LegacyRemoveMemberService();
|
|
|
|
return service;
|
|
}
|
|
}
|