fix: create event type (#11046)
This commit is contained in:
1 parent
f73d38b632
commit
6dd77d0494
6 files changed
+21
-7
No files matched your search
@@ -66,6 +66,7 @@ type Props = {
|
||||
formMethods: UseFormReturn<FormValues>;
|
||||
isUpdateMutationLoading?: boolean;
|
||||
availability?: AvailabilityOption;
|
||||
isUserOrganizationAdmin: boolean;
|
||||
};
|
||||
|
||||
function getNavigation(props: {
|
||||
@@ -133,6 +134,7 @@ function EventTypeSingleLayout({
|
||||
isUpdateMutationLoading,
|
||||
formMethods,
|
||||
availability,
|
||||
isUserOrganizationAdmin,
|
||||
}: Props) {
|
||||
const utils = trpc.useContext();
|
||||
const { t } = useLocale();
|
||||
@@ -142,7 +144,8 @@ function EventTypeSingleLayout({
|
||||
const hasPermsToDelete =
|
||||
currentUserMembership?.role !== "MEMBER" ||
|
||||
!currentUserMembership ||
|
||||
eventType.schedulingType === SchedulingType.MANAGED;
|
||||
eventType.schedulingType === SchedulingType.MANAGED ||
|
||||
isUserOrganizationAdmin;
|
||||
|
||||
const deleteMutation = trpc.viewer.eventTypes.delete.useMutation({
|
||||
onSuccess: async () => {
|
||||
|
||||
@@ -443,7 +443,8 @@ const EventTypePage = (props: EventTypeSetupProps) => {
|
||||
isUpdateMutationLoading={updateMutation.isLoading}
|
||||
formMethods={formMethods}
|
||||
disableBorder={tabName === "apps" || tabName === "workflows" || tabName === "webhooks"}
|
||||
currentUserMembership={currentUserMembership}>
|
||||
currentUserMembership={currentUserMembership}
|
||||
isUserOrganizationAdmin={props.isUserOrganizationAdmin}>
|
||||
<Form
|
||||
form={formMethods}
|
||||
id="event-type-form"
|
||||
|
||||
@@ -21,6 +21,7 @@ interface getEventTypeByIdProps {
|
||||
userId: number;
|
||||
prisma: PrismaClient;
|
||||
isTrpcCall?: boolean;
|
||||
isUserOrganizationAdmin: boolean;
|
||||
}
|
||||
|
||||
export default async function getEventTypeById({
|
||||
@@ -28,6 +29,7 @@ export default async function getEventTypeById({
|
||||
userId,
|
||||
prisma,
|
||||
isTrpcCall = false,
|
||||
isUserOrganizationAdmin,
|
||||
}: getEventTypeByIdProps) {
|
||||
const userSelect = Prisma.validator<Prisma.UserSelect>()({
|
||||
name: true,
|
||||
@@ -408,6 +410,7 @@ export default async function getEventTypeById({
|
||||
team: eventTypeObject.team || null,
|
||||
teamMembers,
|
||||
currentUserMembership,
|
||||
isUserOrganizationAdmin,
|
||||
};
|
||||
return finalObj;
|
||||
}
|
||||
@@ -24,6 +24,7 @@ type CreateOptions = {
|
||||
|
||||
export const createHandler = async ({ ctx, input }: CreateOptions) => {
|
||||
const { schedulingType, teamId, metadata, ...rest } = input;
|
||||
|
||||
const userId = ctx.user.id;
|
||||
const isManagedEventType = schedulingType === SchedulingType.MANAGED;
|
||||
// Get Users default conferencing app
|
||||
@@ -68,7 +69,9 @@ export const createHandler = async ({ ctx, input }: CreateOptions) => {
|
||||
},
|
||||
});
|
||||
|
||||
if (!hasMembership?.role || !["ADMIN", "OWNER"].includes(hasMembership.role)) {
|
||||
const isOrgAdmin = !!ctx.user?.organization?.isOrgAdmin;
|
||||
|
||||
if (!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" });
|
||||
}
|
||||
|
||||
@@ -18,5 +18,6 @@ export const getHandler = ({ ctx, input }: GetOptions) => {
|
||||
userId: ctx.user.id,
|
||||
prisma: ctx.prisma,
|
||||
isTrpcCall: true,
|
||||
isUserOrganizationAdmin: !!ctx.user?.organization?.isOrgAdmin,
|
||||
});
|
||||
};
|
||||
@@ -40,10 +40,13 @@ export const eventOwnerProcedure = authedProcedure
|
||||
|
||||
const isAuthorized = (function () {
|
||||
if (event.team) {
|
||||
return event.team.members
|
||||
.filter((member) => member.role === MembershipRole.OWNER || member.role === MembershipRole.ADMIN)
|
||||
.map((member) => member.userId)
|
||||
.includes(ctx.user.id);
|
||||
const isOrgAdmin = !!ctx.user?.organization?.isOrgAdmin;
|
||||
return (
|
||||
event.team.members
|
||||
.filter((member) => member.role === MembershipRole.OWNER || member.role === MembershipRole.ADMIN)
|
||||
.map((member) => member.userId)
|
||||
.includes(ctx.user.id) || isOrgAdmin
|
||||
);
|
||||
}
|
||||
return event.userId === ctx.user.id || event.users.find((user) => user.id === ctx.user.id);
|
||||
})();
|
||||
|
||||
Reference in new issue
Block a user