Files
c0302bfc51 fix: get bookings handler for pbac and fallback roles (#25434)
* fix: getTeamIdsWithPermission

* fix get bookings handler for pbac and fallback roles

* add tests

* fix fallback roll query

* push integration test fixes

* Check for pbac features

* fix

* restore role behaviour

* fix fallabck roles no pbac enabled

* debug: add logging to investigate PBAC query failures

Co-Authored-By: [email protected] <[email protected]>

* re-write integration tests

* fix: use >= comparison with bigint cast for PBAC permission count

Co-Authored-By: [email protected] <[email protected]>

* Restore permission repo

* re-write from scratch

* fix tests + file

* imrpove perf by makign CTE and moving to left join

* fix org scoped taems

* clean up

* fix: update PermissionCheckService mock to use function instead of arrow function

Co-Authored-By: [email protected] <[email protected]>

* refactor: rename scopedOrgId to orgId

Co-Authored-By: [email protected] <[email protected]>

* refactor: use MembershipRole enum instead of hardcoded strings

Co-Authored-By: [email protected] <[email protected]>

---------

Co-authored-by: Anik Dhabal Babu <[email protected]>
Co-authored-by: Udit Takkar <[email protected]>
Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-authored-by: Eunjae Lee <[email protected]>
Co-authored-by: Benny Joo <[email protected]>
2026-01-16 15:03:15 +00:00

86 lines
2.4 KiB
TypeScript

import type { MembershipRole } from "@calcom/prisma/enums";
import type { TeamPermissions } from "../models/Permission";
import type { PermissionString, Resource, CrudAction, CustomAction } from "../types/permission-registry";
export interface IPermissionRepository {
getUserMemberships(userId: number): Promise<TeamPermissions[]>;
getMembershipByMembershipId(membershipId: number): Promise<{
id: number;
teamId: number;
userId: number;
customRoleId: string | null;
team: {
parentId: number | null;
};
} | null>;
getMembershipByUserAndTeam(
userId: number,
teamId: number
): Promise<{
id: number;
teamId: number;
userId: number;
customRoleId: string | null;
team: {
parentId: number | null;
};
} | null>;
getOrgMembership(
userId: number,
orgId: number
): Promise<{
id: number;
teamId: number;
userId: number;
customRoleId: string | null;
} | null>;
getTeamById(teamId: number): Promise<{
id: number;
parentId: number | null;
} | null>;
checkRolePermission(roleId: string, permission: PermissionString): Promise<boolean>;
checkRolePermissions(roleId: string, permissions: PermissionString[]): Promise<boolean>;
/**
* Gets all permissions for a specific resource in a team context
*/
getResourcePermissions(
userId: number,
teamId: number,
resource: Resource
): Promise<(CrudAction | CustomAction)[]>;
/**
* Gets all permissions for a specific resource by role ID
*/
getResourcePermissionsByRoleId(roleId: string, resource: Resource): Promise<(CrudAction | CustomAction)[]>;
/**
* Gets all team IDs where the user has a specific permission
* @param orgId Optional organization ID to scope results to. When provided, only returns teams within this organization.
*/
getTeamIdsWithPermission(params: {
userId: number;
permission: PermissionString;
fallbackRoles: MembershipRole[];
orgId?: number;
}): Promise<number[]>;
/**
* Gets all team IDs where the user has all of the specified permissions
* @param orgId Optional organization ID to scope results to. When provided, only returns teams within this organization.
*/
getTeamIdsWithPermissions(params: {
userId: number;
permissions: PermissionString[];
fallbackRoles: MembershipRole[];
orgId?: number;
}): Promise<number[]>;
}