* 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: hariom@cal.com <hariombalhara@gmail.com>
---------
Co-authored-by: Hariom Balhara <hariombalhara@gmail.com>
Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
56 lines
1.4 KiB
TypeScript
56 lines
1.4 KiB
TypeScript
import { entityPrismaWhereClause } from "@calcom/lib/entityPermissionUtils.server";
|
|
import type { PrismaClient } from "@calcom/prisma";
|
|
import { MembershipRole } from "@calcom/prisma/enums";
|
|
import type { TrpcSessionUser } from "@calcom/trpc/server/types";
|
|
|
|
import { TRPCError } from "@trpc/server";
|
|
|
|
import { getSerializableForm } from "../lib/getSerializableForm";
|
|
import type { TFormQueryInputSchema } from "./formQuery.schema";
|
|
import { checkPermissionOnExistingRoutingForm } from "./permissions";
|
|
|
|
interface FormsHandlerOptions {
|
|
ctx: {
|
|
prisma: PrismaClient;
|
|
user: NonNullable<TrpcSessionUser>;
|
|
};
|
|
input: TFormQueryInputSchema;
|
|
}
|
|
|
|
export const formQueryHandler = async ({ ctx, input }: FormsHandlerOptions) => {
|
|
const { prisma, user } = ctx;
|
|
const form = await prisma.app_RoutingForms_Form.findFirst({
|
|
where: {
|
|
AND: [
|
|
entityPrismaWhereClause({ userId: user.id }),
|
|
{
|
|
id: input.id,
|
|
},
|
|
],
|
|
},
|
|
include: {
|
|
team: { select: { slug: true, name: true } },
|
|
_count: {
|
|
select: {
|
|
responses: true,
|
|
},
|
|
},
|
|
},
|
|
});
|
|
|
|
if (!form) {
|
|
return null;
|
|
}
|
|
|
|
await checkPermissionOnExistingRoutingForm({
|
|
formId: input.id,
|
|
userId: user.id,
|
|
permission: "routingForm.read",
|
|
fallbackRoles: [MembershipRole.MEMBER, MembershipRole.ADMIN, MembershipRole.OWNER],
|
|
});
|
|
|
|
return await getSerializableForm({ form });
|
|
};
|
|
|
|
export default formQueryHandler;
|