* feat: add enabled column to UserFeatures and TeamFeatures for tri-state semantics - Add enabled Boolean column to UserFeatures model with default true - Add enabled Boolean column to TeamFeatures model with default true - Update FeaturesRepository to use tri-state semantics: - enabled=true: feature is explicitly enabled - enabled=false: feature is explicitly disabled (blocks inheritance) - No row: inherit from team/org level - Update SQL queries to check enabled=true for feature access - Add enableFeatureForTeam method to interface and implementation Co-Authored-By: eunjae@cal.com <hey@eunjae.dev> * update comments * add integration tests * add more test * select enabled only * no @default(true) * fix types and tests * add missing enabled * add missing enabled * rename enableFeatureForTeam to updateFeatureForTeam and support FeatureState * refactor: rename updateFeatureForTeam to setTeamFeatureState Co-Authored-By: eunjae@cal.com <hey@eunjae.dev> * fix integration test * fix tests * add more tests * add missing enabled --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
31 lines
854 B
TypeScript
31 lines
854 B
TypeScript
import { PERMISSION_REGISTRY } from "@calcom/features/pbac/domain/types/permission-registry";
|
|
import { prisma } from "@calcom/prisma";
|
|
|
|
// Create array of all permissions from PERMISSION_REGISTRY
|
|
export const createAllPermissionsArray = () => {
|
|
const allPermissions: { resource: string; action: string }[] = [];
|
|
|
|
Object.entries(PERMISSION_REGISTRY).forEach(([resource, resourceConfig]) => {
|
|
if (resource === "*") {
|
|
return;
|
|
}
|
|
Object.entries(resourceConfig).forEach(([action, _details]) => {
|
|
allPermissions.push({ resource, action });
|
|
});
|
|
});
|
|
|
|
return allPermissions;
|
|
};
|
|
|
|
export const enablePBACForTeam = async (teamId: number) => {
|
|
await prisma.teamFeatures.create({
|
|
data: {
|
|
featureId: "pbac",
|
|
teamId: teamId,
|
|
assignedBy: "e2e",
|
|
assignedAt: new Date(),
|
|
enabled: true,
|
|
},
|
|
});
|
|
};
|