+1








1b5d50c45c
Co-authored-by: Alex van Andel <me@alexvanandel.com> Co-authored-by: Keith Williams <keithwillcode@gmail.com> Co-authored-by: CarinaWolli <wollencarina@gmail.com> Co-authored-by: Udit Takkar <53316345+Udit-takkar@users.noreply.github.com> Co-authored-by: Kiran K <mailtokirankk@gmail.com> Co-authored-by: Peer Richelsen <peeroke@gmail.com> Co-authored-by: sean-brydon <55134778+sean-brydon@users.noreply.github.com> Co-authored-by: zomars <zomars@me.com> Co-authored-by: Carina Wollendorfer <30310907+CarinaWolli@users.noreply.github.com>
50 lines
1.0 KiB
TypeScript
50 lines
1.0 KiB
TypeScript
import { canAccess } from "@calcom/features/ee/sso/lib/saml";
|
|
import prisma from "@calcom/prisma";
|
|
import type { TrpcSessionUser } from "@calcom/trpc/server/trpc";
|
|
|
|
import { TRPCError } from "@trpc/server";
|
|
|
|
const userCanCreateTeamGroupMapping = async (
|
|
user: NonNullable<TrpcSessionUser>,
|
|
organizationId: number | null,
|
|
teamId?: number
|
|
) => {
|
|
if (!organizationId) {
|
|
throw new TRPCError({
|
|
code: "BAD_REQUEST",
|
|
message: "Could not find organization id",
|
|
});
|
|
}
|
|
|
|
const { message, access } = await canAccess(user, organizationId);
|
|
if (!access) {
|
|
throw new TRPCError({
|
|
code: "BAD_REQUEST",
|
|
message,
|
|
});
|
|
}
|
|
|
|
if (teamId) {
|
|
const orgTeam = await prisma.team.findFirst({
|
|
where: {
|
|
id: teamId,
|
|
parentId: organizationId,
|
|
},
|
|
select: {
|
|
id: true,
|
|
},
|
|
});
|
|
|
|
if (!orgTeam) {
|
|
throw new TRPCError({
|
|
code: "BAD_REQUEST",
|
|
message: "Could not find team",
|
|
});
|
|
}
|
|
}
|
|
|
|
return { organizationId };
|
|
};
|
|
|
|
export default userCanCreateTeamGroupMapping;
|