* fix: apply PBAC to routing form CRUD
* apply permission checks to the UI
* moving prisma call to repository [WIP]
* rename repository and fix type error
* update implementation
* fix formMutation handler
* remove unused import
* revert some rename
* add RolePermission for 'routingForm'
* Revert "revert some rename"
This reverts commit 0ef3114c0d27b821271b36296de531654b37749f.
* clean up PrismaRoutingFormRepository
* fix unit test
* remove no longer necessary code
* fix type definition
* explicit permission handling
* do not disable un-editable routing form
* fix: correct property name from readonly to readOnly in ListLinkItem
- Fix TypeScript error in routing forms component
- Change readonly={readOnly} to readOnly={readOnly} to match component interface
- Resolves type check failure in CI
Co-Authored-By: [email protected] <[email protected]>
---------
Co-authored-by: Hariom Balhara <[email protected]>
Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
57 lines
1.6 KiB
TypeScript
57 lines
1.6 KiB
TypeScript
import type { PermissionString } from "@calcom/features/pbac/domain/types/permission-registry";
|
|
import { PermissionCheckService } from "@calcom/features/pbac/services/permission-check.service";
|
|
import { PrismaRoutingFormRepository } from "@calcom/lib/server/repository/PrismaRoutingFormRepository";
|
|
import { MembershipRole } from "@calcom/prisma/enums";
|
|
|
|
import { TRPCError } from "@trpc/server";
|
|
|
|
export async function checkPermissionOnExistingRoutingForm({
|
|
formId,
|
|
userId,
|
|
permission,
|
|
fallbackRoles,
|
|
}: {
|
|
formId: string;
|
|
userId: number;
|
|
permission: PermissionString;
|
|
fallbackRoles: MembershipRole[];
|
|
}) {
|
|
// First get the form to check its team context
|
|
const form = await PrismaRoutingFormRepository.findById(formId, {
|
|
select: { teamId: true, userId: true },
|
|
});
|
|
|
|
if (!form) {
|
|
throw new TRPCError({
|
|
code: "NOT_FOUND",
|
|
message: "Form not found",
|
|
});
|
|
}
|
|
|
|
// Check PBAC permissions for personal-scoped routing forms only
|
|
if (!form.teamId && form.userId !== userId) {
|
|
throw new TRPCError({
|
|
code: "FORBIDDEN",
|
|
message: "You don't have permission to this personal-scoped routing form",
|
|
});
|
|
}
|
|
|
|
// Check PBAC permissions for team-scoped routing forms only
|
|
if (form.teamId) {
|
|
const permissionService = new PermissionCheckService();
|
|
const hasPermission = await permissionService.checkPermission({
|
|
userId: userId,
|
|
teamId: form.teamId,
|
|
permission,
|
|
fallbackRoles,
|
|
});
|
|
|
|
if (!hasPermission) {
|
|
throw new TRPCError({
|
|
code: "FORBIDDEN",
|
|
message: `You don't have "${permission}" permission for this routing form`,
|
|
});
|
|
}
|
|
}
|
|
}
|