From e55f95cb605da909967fc4daf58c73d7fe6685da Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Tue, 28 Jan 2025 20:06:20 -0500 Subject: [PATCH] PR feedback --- server/routes/api/attachments/attachments.ts | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/server/routes/api/attachments/attachments.ts b/server/routes/api/attachments/attachments.ts index 058082cbda..d2288c2151 100644 --- a/server/routes/api/attachments/attachments.ts +++ b/server/routes/api/attachments/attachments.ts @@ -3,6 +3,7 @@ import { v4 as uuidv4 } from "uuid"; import { AttachmentPreset } from "@shared/types"; import { bytesToHumanReadable, getFileNameFromUrl } from "@shared/utils/files"; import { AttachmentValidation } from "@shared/validations"; +import { createContext } from "@server/context"; import { AuthorizationError, InvalidRequestError, @@ -118,10 +119,8 @@ router.post( validate(T.AttachmentsCreateFromUrlSchema), async (ctx: APIContext) => { const { url, documentId, preset } = ctx.input.body; - const { auth, transaction } = ctx.state; - const { user } = auth; + const { user, type } = ctx.state.auth; - // All user types can upload an avatar so no additional authorization is needed. if (preset !== AttachmentPreset.DocumentAttachment || !documentId) { throw ValidationError( "Only document attachments can be created from a URL" @@ -130,7 +129,6 @@ router.post( const document = await Document.findByPk(documentId, { userId: user.id, - transaction, }); authorize(user, "update", document); @@ -148,7 +146,12 @@ router.post( // before the job is scheduled. const attachment = await sequelize.transaction(async (transaction) => Attachment.createWithCtx( - { ...ctx, transaction }, + createContext({ + authType: type, + user, + ip: ctx.ip, + transaction, + }), { id: modelId, key,