* saml * addGuests.handler.ts * rename canAccess to canAccessOrganization and use organization.read * update usages * team update handler * team member invite * event type update * remove isTeamAdmin util * updateInternalNotesPresets * setInviteExpiration * event type update * deleteInvite * createInvite * team publish * fixes * final * address feedback * update test
50 lines
1.1 KiB
TypeScript
50 lines
1.1 KiB
TypeScript
import { canAccessOrganization } from "@calcom/features/ee/sso/lib/saml";
|
|
import prisma from "@calcom/prisma";
|
|
import type { TrpcSessionUser } from "@calcom/trpc/server/types";
|
|
|
|
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 canAccessOrganization(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;
|