refactor: do a permission check in removeHostsFromEventTypes trpc handler (#24176)
This commit is contained in:
+17
-3
@@ -1,5 +1,6 @@
|
||||
import { isOrganisationAdmin } from "@calcom/lib/server/queries/organisations";
|
||||
import { PermissionCheckService } from "@calcom/features/pbac/services/permission-check.service";
|
||||
import prisma from "@calcom/prisma";
|
||||
import { MembershipRole } from "@calcom/prisma/enums";
|
||||
|
||||
import { TRPCError } from "@trpc/server";
|
||||
|
||||
@@ -16,8 +17,21 @@ type RemoveHostsFromEventTypes = {
|
||||
export async function removeHostsFromEventTypesHandler({ ctx, input }: RemoveHostsFromEventTypes) {
|
||||
if (!ctx.user.organizationId) throw new TRPCError({ code: "UNAUTHORIZED" });
|
||||
|
||||
if (!(await isOrganisationAdmin(ctx.user?.id, ctx.user.organizationId)))
|
||||
throw new TRPCError({ code: "UNAUTHORIZED" });
|
||||
// Check if user has permission to manage event types in the organization
|
||||
const permissionCheckService = new PermissionCheckService();
|
||||
const hasPermission = await permissionCheckService.checkPermission({
|
||||
userId: ctx.user.id,
|
||||
teamId: ctx.user.organizationId,
|
||||
permission: "eventType.update",
|
||||
fallbackRoles: [MembershipRole.OWNER, MembershipRole.ADMIN],
|
||||
});
|
||||
|
||||
if (!hasPermission) {
|
||||
throw new TRPCError({
|
||||
code: "UNAUTHORIZED",
|
||||
message: "You are not authorized to manage event types in this organization",
|
||||
});
|
||||
}
|
||||
|
||||
const { userIds, eventTypeIds } = input;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user