fix: can't edit ooo (#18020)

* fix: can't edit ooo

* fix: unauthorized users can edit ooo
This commit is contained in:
Kartik Saini
2024-12-09 23:39:56 +00:00
committed by GitHub
parent 950879b9c7
commit 9c9d7fe0c3
2 changed files with 7 additions and 1 deletions
@@ -2453,6 +2453,7 @@
"start_date_must_be_before_end_date": "Start date must be before end date",
"start_date_must_be_in_the_future": "Start date must be in the future",
"user_not_found": "User not found",
"cannot_redirect_to_self": "Cannot redirect to self",
"out_of_office_entry_already_exists": "Out of office entry already exists",
"out_of_office_id_required": "Out of office entry id required",
"booking_redirect_infinite_not_allowed": "There is already a booking redirect from that user to you.",
@@ -40,6 +40,10 @@ export const outOfOfficeCreateOrUpdate = async ({ ctx, input }: TBookingRedirect
let toUserId: number | null = null;
if (input.toTeamUserId === ctx.user.id) {
throw new TRPCError({ code: "BAD_REQUEST", message: "cannot_redirect_to_self" });
}
if (input.toTeamUserId) {
const user = await prisma.user.findUnique({
where: {
@@ -108,7 +112,7 @@ export const outOfOfficeCreateOrUpdate = async ({ ctx, input }: TBookingRedirect
},
});
if (isDuplicateOutOfOfficeEntry) {
if (isDuplicateOutOfOfficeEntry && isDuplicateOutOfOfficeEntry?.uuid !== input.uuid) {
throw new TRPCError({ code: "CONFLICT", message: "out_of_office_entry_already_exists" });
}
@@ -132,6 +136,7 @@ export const outOfOfficeCreateOrUpdate = async ({ ctx, input }: TBookingRedirect
const createdOrUpdatedOutOfOffice = await prisma.outOfOfficeEntry.upsert({
where: {
uuid: input.uuid ?? "",
userId: ctx.user.id,
},
create: {
uuid: uuidv4(),