refactor: allow system admins to create event-type without membership (#15774)

This commit is contained in:
Lauris Skraucis
2024-07-16 06:08:28 +00:00
committed by GitHub
parent 1a5a539106
commit 77519a077c
3 changed files with 9 additions and 1 deletions
@@ -60,6 +60,7 @@ export class EventTypesService_2024_04_15 {
const profileId = user.movedToProfile?.id || null;
return {
id: user.id,
role: user.role,
organizationId: user.organizationId,
organization: { isOrgAdmin },
profile: { id: profileId },
@@ -94,6 +94,7 @@ export class EventTypesService_2024_06_14 {
const profileId = user.movedToProfile?.id || null;
return {
id: user.id,
role: user.role,
organizationId: user.organizationId,
organization: { isOrgAdmin },
profile: { id: profileId },
@@ -15,6 +15,7 @@ import type { TCreateInputSchema } from "./create.schema";
type SessionUser = NonNullable<TrpcSessionUser>;
type User = {
id: SessionUser["id"];
role: SessionUser["role"];
organizationId: SessionUser["organizationId"];
organization: {
isOrgAdmin: SessionUser["organization"]["isOrgAdmin"];
@@ -61,7 +62,12 @@ export const createHandler = async ({ ctx, input }: CreateOptions) => {
},
});
if (!hasMembership?.role || !(["ADMIN", "OWNER"].includes(hasMembership.role) || isOrgAdmin)) {
const isSystemAdmin = ctx.user.role === "ADMIN";
if (
!isSystemAdmin &&
(!hasMembership?.role || !(["ADMIN", "OWNER"].includes(hasMembership.role) || isOrgAdmin))
) {
console.warn(`User ${userId} does not have permission to create this new event type`);
throw new TRPCError({ code: "UNAUTHORIZED" });
}