refactor: implement PBAC for team member listing in listSimpleMembers handler (#24005)
* refactor: implement PBAC for team member listing - Replace membership-based team filtering with getTeamIdsWithPermission - Use team.listMembers permission for access control - Maintain fallback to original logic when PBAC fails - Add comprehensive PBAC refactoring guide for future use Fixes team fetching logic to use Permission-Based Access Control while preserving existing functionality and privacy checks. Co-Authored-By: [email protected] <[email protected]> * docs: move PBAC refactoring guide to packages/features/pbac/ Move the PBAC refactoring guide to the appropriate location within the PBAC feature package for better organization and discoverability. Co-Authored-By: [email protected] <[email protected]> * refactor: remove unnecessary try-catch wrapper The getTeamIdsWithPermission method already handles all errors internally and returns an empty array instead of throwing exceptions, making the try-catch wrapper redundant. Simplified to use direct fallback logic based on empty array return. Co-Authored-By: [email protected] <[email protected]> * refactor: simplify PBAC implementation - Remove flawed fallback logic that assumed empty array meant PBAC failure - Use direct string 'team.listMembers' instead of PermissionMapper - Remove unused imports (PermissionMapper, Resource, CustomAction) - Empty array from getTeamIdsWithPermission is legitimate (no permissions) Co-Authored-By: [email protected] <[email protected]> * docs: simplify PBAC refactoring guide - Reduce from 260 to 87 lines by removing bloated content - Focus on core pattern: direct permission strings, no fallback logic - Align with actual PR implementation - Remove verbose theoretical sections and complex patterns 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:
1 parent
b2239374bc
commit
788fbdbe5e
2 files changed
+89
-19
No files matched your search
@@ -2,8 +2,8 @@
|
||||
* Simplified version of legacyListMembers.handler.ts that returns basic member info.
|
||||
* Used for filtering people on /bookings.
|
||||
*/
|
||||
import { PermissionCheckService } from "@calcom/features/pbac/services/permission-check.service";
|
||||
import type { PrismaClient } from "@calcom/prisma";
|
||||
import { MembershipRole } from "@calcom/prisma/enums";
|
||||
import type { TrpcSessionUser } from "@calcom/trpc/server/types";
|
||||
|
||||
type ListSimpleMembersOptions = {
|
||||
@@ -22,24 +22,8 @@ export const listSimpleMembers = async ({ ctx }: ListSimpleMembersOptions) => {
|
||||
return [];
|
||||
}
|
||||
|
||||
// query all teams the user is a member of and the team is not private
|
||||
const teamsToQuery = (
|
||||
await prisma.membership.findMany({
|
||||
where: {
|
||||
userId: ctx.user.id,
|
||||
accepted: true,
|
||||
NOT: [
|
||||
{
|
||||
role: MembershipRole.MEMBER,
|
||||
team: {
|
||||
isPrivate: true,
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
select: { teamId: true },
|
||||
})
|
||||
).map((membership) => membership.teamId);
|
||||
const permissionCheckService = new PermissionCheckService();
|
||||
const teamsToQuery = await permissionCheckService.getTeamIdsWithPermission(ctx.user.id, "team.listMembers");
|
||||
|
||||
if (!teamsToQuery.length) {
|
||||
return [];
|
||||
|
||||
Reference in new issue
Block a user