Files
calendar/packages/features/ee/dsync/lib/server/userCanCreateTeamGroupMapping.ts
T
Benny JooandGitHub 8d7cdf9d3b refactor: use permission check service for isTeamAdmin (#24026)
* 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
2025-09-25 08:54:16 +01:00

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;