diff --git a/api/src/attachment/controllers/attachment.controller.spec.ts b/api/src/attachment/controllers/attachment.controller.spec.ts index 34b19ef0..e8c96d88 100644 --- a/api/src/attachment/controllers/attachment.controller.spec.ts +++ b/api/src/attachment/controllers/attachment.controller.spec.ts @@ -39,7 +39,11 @@ import { attachment, attachmentFile } from '../mocks/attachment.mock'; import { AttachmentRepository } from '../repositories/attachment.repository'; import { Attachment, AttachmentModel } from '../schemas/attachment.schema'; import { AttachmentService } from '../services/attachment.service'; -import { AttachmentResourceRef } from '../types'; +import { + AttachmentAccess, + AttachmentCreatedByRef, + AttachmentResourceRef, +} from '../types'; import { AttachmentController } from './attachment.controller'; @@ -138,8 +142,8 @@ describe('AttachmentController', () => { name: attachmentFile.originalname, location: expect.stringMatching(new RegExp(`^/${name}`)), resourceRef: AttachmentResourceRef.BlockAttachment, - access: 'public', - createdByRef: 'User', + access: AttachmentAccess.Public, + createdByRef: AttachmentCreatedByRef.User, createdBy: '9'.repeat(24), }); expect(result).toEqualPayload( @@ -147,7 +151,7 @@ describe('AttachmentController', () => { { ...attachment, resourceRef: AttachmentResourceRef.BlockAttachment, - createdByRef: 'User', + createdByRef: AttachmentCreatedByRef.User, createdBy: '9'.repeat(24), }, ], diff --git a/api/src/attachment/controllers/attachment.controller.ts b/api/src/attachment/controllers/attachment.controller.ts index 278fa7c4..8f794e03 100644 --- a/api/src/attachment/controllers/attachment.controller.ts +++ b/api/src/attachment/controllers/attachment.controller.ts @@ -46,6 +46,7 @@ import { import { AttachmentGuard } from '../guards/attachment-ability.guard'; import { Attachment } from '../schemas/attachment.schema'; import { AttachmentService } from '../services/attachment.service'; +import { AttachmentAccess, AttachmentCreatedByRef } from '../types'; @UseInterceptors(CsrfInterceptor) @Controller('attachment') @@ -131,7 +132,10 @@ export class AttachmentController extends BaseController { @UploadedFiles() files: { file: Express.Multer.File[] }, @Req() req: Request, @Query() - { resourceRef, access = 'public' }: AttachmentContextParamDto, + { + resourceRef, + access = AttachmentAccess.Public, + }: AttachmentContextParamDto, ): Promise { if (!files || !Array.isArray(files?.file) || files.file.length === 0) { throw new BadRequestException('No file was selected'); @@ -153,7 +157,7 @@ export class AttachmentController extends BaseController { resourceRef, access, createdBy: userId, - createdByRef: 'User', + createdByRef: AttachmentCreatedByRef.User, }); if (attachment) { diff --git a/api/src/attachment/dto/attachment.dto.ts b/api/src/attachment/dto/attachment.dto.ts index d5e0f68a..c10d0096 100644 --- a/api/src/attachment/dto/attachment.dto.ts +++ b/api/src/attachment/dto/attachment.dto.ts @@ -27,9 +27,6 @@ import { AttachmentAccess, AttachmentCreatedByRef, AttachmentResourceRef, - TAttachmentAccess, - TAttachmentCreatedByRef, - TAttachmentResourceRef, } from '../types'; export class AttachmentMetadataDto { @@ -76,7 +73,7 @@ export class AttachmentMetadataDto { @IsString() @IsNotEmpty() @IsIn(Object.values(AttachmentResourceRef)) - resourceRef: TAttachmentResourceRef; + resourceRef: AttachmentResourceRef; /** * Attachment Owner Type @@ -88,7 +85,7 @@ export class AttachmentMetadataDto { @IsString() @IsNotEmpty() @IsIn(Object.values(AttachmentCreatedByRef)) - createdByRef: TAttachmentCreatedByRef; + createdByRef: AttachmentCreatedByRef; /** * Attachment Access @@ -100,7 +97,7 @@ export class AttachmentMetadataDto { @IsString() @IsNotEmpty() @IsIn(Object.values(AttachmentAccess)) - access: TAttachmentAccess; + access: AttachmentAccess; /** * Attachment Owner : Subscriber or User ID @@ -147,7 +144,7 @@ export class AttachmentContextParamDto { @IsString() @IsIn(Object.values(AttachmentResourceRef)) @IsNotEmpty() - resourceRef: TAttachmentResourceRef; + resourceRef: AttachmentResourceRef; @ApiPropertyOptional({ description: 'Attachment Access', @@ -156,5 +153,5 @@ export class AttachmentContextParamDto { @IsString() @IsIn(Object.values(AttachmentAccess)) @IsOptional() - access?: TAttachmentAccess; + access?: AttachmentAccess; } diff --git a/api/src/attachment/guards/attachment-ability.guard.ts b/api/src/attachment/guards/attachment-ability.guard.ts index be5deea3..224f0947 100644 --- a/api/src/attachment/guards/attachment-ability.guard.ts +++ b/api/src/attachment/guards/attachment-ability.guard.ts @@ -26,7 +26,7 @@ import { Action } from '@/user/types/action.type'; import { TModel } from '@/user/types/model.type'; import { AttachmentService } from '../services/attachment.service'; -import { AttachmentResourceRef, TAttachmentResourceRef } from '../types'; +import { AttachmentResourceRef } from '../types'; import { isAttachmentResourceRef, isAttachmentResourceRefArray, @@ -42,7 +42,7 @@ export class AttachmentGuard implements CanActivate { private permissionMap: Record< Action, - Record + Record > = { // Read attachments by ref [Action.READ]: { @@ -169,7 +169,7 @@ export class AttachmentGuard implements CanActivate { private async isAuthorized( action: Action, user: Express.User & User, - resourceRef: TAttachmentResourceRef, + resourceRef: AttachmentResourceRef, ): Promise { if (!action) { throw new TypeError('Invalid action'); diff --git a/api/src/attachment/mocks/attachment.mock.ts b/api/src/attachment/mocks/attachment.mock.ts index cbc885b8..025b929b 100644 --- a/api/src/attachment/mocks/attachment.mock.ts +++ b/api/src/attachment/mocks/attachment.mock.ts @@ -9,7 +9,11 @@ import { Stream } from 'node:stream'; import { Attachment } from '../schemas/attachment.schema'; -import { AttachmentResourceRef } from '../types'; +import { + AttachmentAccess, + AttachmentCreatedByRef, + AttachmentResourceRef, +} from '../types'; export const attachment: Attachment = { name: 'Screenshot from 2022-03-11 08-41-27-2a9799a8b6109c88fd9a7a690c1101934c.png', @@ -18,12 +22,12 @@ export const attachment: Attachment = { location: '/Screenshot from 2022-03-11 08-41-27-2a9799a8b6109c88fd9a7a690c1101934c.png', resourceRef: AttachmentResourceRef.BlockAttachment, - access: 'public', + access: AttachmentAccess.Public, id: '65940d115178607da65c82b6', createdAt: new Date(), updatedAt: new Date(), createdBy: '1', - createdByRef: 'User', + createdByRef: AttachmentCreatedByRef.User, }; export const attachmentFile: Express.Multer.File = { @@ -49,12 +53,12 @@ export const attachments: Attachment[] = [ '/app/src/attachment/uploads/Screenshot from 2022-03-11 08-41-27-2a9799a8b6109c88fd9a7a690c1101934c.png', channel: { ['some-channel']: {} }, resourceRef: AttachmentResourceRef.BlockAttachment, - access: 'public', + access: AttachmentAccess.Public, id: '65940d115178607da65c82b7', createdAt: new Date(), updatedAt: new Date(), createdBy: '1', - createdByRef: 'User', + createdByRef: AttachmentCreatedByRef.User, }, { name: 'Screenshot from 2022-03-18 08-58-15-af61e7f71281f9fd3f1ad7ad10107741c.png', @@ -64,11 +68,11 @@ export const attachments: Attachment[] = [ '/app/src/attachment/uploads/Screenshot from 2022-03-18 08-58-15-af61e7f71281f9fd3f1ad7ad10107741c.png', channel: { ['some-channel']: {} }, resourceRef: AttachmentResourceRef.BlockAttachment, - access: 'public', + access: AttachmentAccess.Public, id: '65940d115178607da65c82b8', createdAt: new Date(), updatedAt: new Date(), createdBy: '1', - createdByRef: 'User', + createdByRef: AttachmentCreatedByRef.User, }, ]; diff --git a/api/src/attachment/schemas/attachment.schema.ts b/api/src/attachment/schemas/attachment.schema.ts index 7d8e6b8e..a4675379 100644 --- a/api/src/attachment/schemas/attachment.schema.ts +++ b/api/src/attachment/schemas/attachment.schema.ts @@ -27,9 +27,6 @@ import { AttachmentAccess, AttachmentCreatedByRef, AttachmentResourceRef, - TAttachmentAccess, - TAttachmentCreatedByRef, - TAttachmentResourceRef, } from '../types'; import { MIME_REGEX } from '../utilities'; @@ -94,19 +91,19 @@ export class AttachmentStub extends BaseSchema { * Type of the createdBy (depending on the createdBy type) */ @Prop({ type: String, enum: Object.values(AttachmentCreatedByRef) }) - createdByRef: TAttachmentCreatedByRef; + createdByRef: AttachmentCreatedByRef; /** * Resource reference of the attachment */ @Prop({ type: String, enum: Object.values(AttachmentResourceRef) }) - resourceRef: TAttachmentResourceRef; + resourceRef: AttachmentResourceRef; /** * Access level of the attachment */ @Prop({ type: String, enum: Object.values(AttachmentAccess) }) - access: TAttachmentAccess; + access: AttachmentAccess; /** * Optional property representing the URL of the attachment. diff --git a/api/src/attachment/services/attachment.service.ts b/api/src/attachment/services/attachment.service.ts index f4721b2b..94e55985 100644 --- a/api/src/attachment/services/attachment.service.ts +++ b/api/src/attachment/services/attachment.service.ts @@ -30,7 +30,7 @@ import { BaseService } from '@/utils/generics/base-service'; import { AttachmentMetadataDto } from '../dto/attachment.dto'; import { AttachmentRepository } from '../repositories/attachment.repository'; import { Attachment } from '../schemas/attachment.schema'; -import { AttachmentResourceRef, TAttachmentResourceRef } from '../types'; +import { AttachmentResourceRef } from '../types'; import { fileExists, generateUniqueFilename, @@ -163,7 +163,7 @@ export class AttachmentService extends BaseService { * @param ref The attachment resource reference * @returns The root directory path */ - getRootDirByResourceRef(ref: TAttachmentResourceRef) { + getRootDirByResourceRef(ref: AttachmentResourceRef) { return ref === AttachmentResourceRef.SubscriberAvatar || ref === AttachmentResourceRef.UserAvatar ? config.parameters.avatarDir diff --git a/api/src/attachment/types/index.ts b/api/src/attachment/types/index.ts index ae2ae728..66c613f7 100644 --- a/api/src/attachment/types/index.ts +++ b/api/src/attachment/types/index.ts @@ -17,8 +17,6 @@ export enum AttachmentCreatedByRef { Subscriber = 'Subscriber', } -export type TAttachmentCreatedByRef = `${AttachmentCreatedByRef}`; - /** * Defines the various resource references in which an attachment can exist. * These resource references influence how the attachment is uploaded, stored, and accessed: @@ -32,15 +30,11 @@ export enum AttachmentResourceRef { MessageAttachment = 'Message', // Files sent or received via messages, uploaded programmatically, accessible to users with inbox permissions.; } -export type TAttachmentResourceRef = `${AttachmentResourceRef}`; - export enum AttachmentAccess { Public = 'public', Private = 'private', } -export type TAttachmentAccess = `${AttachmentAccess}`; - export class AttachmentFile { /** * File original file name diff --git a/api/src/attachment/utilities/index.ts b/api/src/attachment/utilities/index.ts index 79649f76..13dead20 100644 --- a/api/src/attachment/utilities/index.ts +++ b/api/src/attachment/utilities/index.ts @@ -15,7 +15,7 @@ import { v4 as uuidv4 } from 'uuid'; import { config } from '@/config'; -import { AttachmentResourceRef, TAttachmentResourceRef } from '../types'; +import { AttachmentResourceRef } from '../types'; export const MIME_REGEX = /^[a-z-]+\/[0-9a-z\-.]+$/gm; @@ -84,13 +84,13 @@ export const generateUniqueFilename = (originalname: string) => { /** * Checks if the given ref is of type TAttachmentResourceRef. * - * @param ref - The ref to check. + * @param resourceRef - The ref to check. * @returns True if the ref is of type TAttachmentResourceRef, otherwise false. */ export const isAttachmentResourceRef = ( - ref: any, -): ref is TAttachmentResourceRef => { - return Object.values(AttachmentResourceRef).includes(ref); + resourceRef: any, +): resourceRef is AttachmentResourceRef => { + return Object.values(AttachmentResourceRef).includes(resourceRef); }; AttachmentResourceRef; @@ -102,7 +102,7 @@ AttachmentResourceRef; */ export const isAttachmentResourceRefArray = ( refList: any, -): refList is TAttachmentResourceRef[] => { +): refList is AttachmentResourceRef[] => { return ( Array.isArray(refList) && refList.length > 0 && diff --git a/api/src/channel/lib/Handler.ts b/api/src/channel/lib/Handler.ts index 037f64fd..a803ae5b 100644 --- a/api/src/channel/lib/Handler.ts +++ b/api/src/channel/lib/Handler.ts @@ -23,7 +23,12 @@ import { v4 as uuidv4 } from 'uuid'; import { Attachment } from '@/attachment/schemas/attachment.schema'; import { AttachmentService } from '@/attachment/services/attachment.service'; -import { AttachmentFile, AttachmentResourceRef } from '@/attachment/types'; +import { + AttachmentAccess, + AttachmentCreatedByRef, + AttachmentFile, + AttachmentResourceRef, +} from '@/attachment/types'; import { SubscriberCreateDto } from '@/chat/dto/subscriber.dto'; import { AttachmentRef } from '@/chat/schemas/types/attachment'; import { @@ -260,8 +265,8 @@ export default abstract class ChannelHandler< type, size, resourceRef: AttachmentResourceRef.MessageAttachment, - access: 'private', - createdByRef: 'Subscriber', + access: AttachmentAccess.Private, + createdByRef: AttachmentCreatedByRef.Subscriber, createdBy: subscriber.id, }); }), @@ -327,7 +332,7 @@ export default abstract class ChannelHandler< * @return True, if requester is authorized to download the attachment */ public async hasDownloadAccess(attachment: Attachment, _req: Request) { - return attachment.access === 'public'; + return attachment.access === AttachmentAccess.Public; } /** diff --git a/api/src/channel/lib/__test__/common.mock.ts b/api/src/channel/lib/__test__/common.mock.ts index 0f6f04a8..7146dc80 100644 --- a/api/src/channel/lib/__test__/common.mock.ts +++ b/api/src/channel/lib/__test__/common.mock.ts @@ -7,7 +7,11 @@ */ import { Attachment } from '@/attachment/schemas/attachment.schema'; -import { AttachmentResourceRef } from '@/attachment/types'; +import { + AttachmentAccess, + AttachmentCreatedByRef, + AttachmentResourceRef, +} from '@/attachment/types'; import { ButtonType } from '@/chat/schemas/types/button'; import { FileType, @@ -90,8 +94,8 @@ const attachment: Attachment = { }, }, resourceRef: AttachmentResourceRef.BlockAttachment, - access: 'public', - createdByRef: 'User', + access: AttachmentAccess.Public, + createdByRef: AttachmentCreatedByRef.User, createdBy: null, createdAt: new Date(), updatedAt: new Date(), diff --git a/api/src/chat/services/chat.service.ts b/api/src/chat/services/chat.service.ts index 78ef8866..6f7512fd 100644 --- a/api/src/chat/services/chat.service.ts +++ b/api/src/chat/services/chat.service.ts @@ -12,7 +12,11 @@ import mime from 'mime'; import { v4 as uuidv4 } from 'uuid'; import { AttachmentService } from '@/attachment/services/attachment.service'; -import { AttachmentResourceRef } from '@/attachment/types'; +import { + AttachmentAccess, + AttachmentCreatedByRef, + AttachmentResourceRef, +} from '@/attachment/types'; import EventWrapper from '@/channel/lib/EventWrapper'; import { config } from '@/config'; import { HelperService } from '@/helper/helper.service'; @@ -282,8 +286,8 @@ export class ChatService { size, type, resourceRef: AttachmentResourceRef.SubscriberAvatar, - access: 'private', - createdByRef: 'Subscriber', + access: AttachmentAccess.Private, + createdByRef: AttachmentCreatedByRef.Subscriber, createdBy: subscriber.id, }); diff --git a/api/src/extensions/channels/web/base-web-channel.ts b/api/src/extensions/channels/web/base-web-channel.ts index 3e0f911b..81b4ea4e 100644 --- a/api/src/extensions/channels/web/base-web-channel.ts +++ b/api/src/extensions/channels/web/base-web-channel.ts @@ -15,7 +15,11 @@ import { v4 as uuidv4 } from 'uuid'; import { Attachment } from '@/attachment/schemas/attachment.schema'; import { AttachmentService } from '@/attachment/services/attachment.service'; -import { AttachmentResourceRef } from '@/attachment/types'; +import { + AttachmentAccess, + AttachmentCreatedByRef, + AttachmentResourceRef, +} from '@/attachment/types'; import { ChannelService } from '@/channel/channel.service'; import ChannelHandler from '@/channel/lib/Handler'; import { ChannelName } from '@/channel/types'; @@ -627,8 +631,8 @@ export default abstract class BaseWebChannelHandler< size: Buffer.byteLength(data.file), type: data.type, resourceRef: AttachmentResourceRef.MessageAttachment, - access: 'private', - createdByRef: 'Subscriber', + access: AttachmentAccess.Private, + createdByRef: AttachmentCreatedByRef.Subscriber, createdBy: req.session?.web?.profile?.id, }); } catch (err) { @@ -694,8 +698,8 @@ export default abstract class BaseWebChannelHandler< size: file.size, type: file.mimetype, resourceRef: AttachmentResourceRef.MessageAttachment, - access: 'private', - createdByRef: 'Subscriber', + access: AttachmentAccess.Private, + createdByRef: AttachmentCreatedByRef.Subscriber, createdBy: req.session.web.profile?.id, }); } catch (err) { @@ -1355,7 +1359,7 @@ export default abstract class BaseWebChannelHandler< */ public async hasDownloadAccess(attachment: Attachment, req: Request) { const subscriberId = req.session?.web?.profile?.id as string; - if (attachment.access === 'public') { + if (attachment.access === AttachmentAccess.Public) { return true; } else if (!subscriberId) { this.logger.warn( @@ -1363,7 +1367,7 @@ export default abstract class BaseWebChannelHandler< ); return false; } else if ( - attachment.createdByRef === 'Subscriber' && + attachment.createdByRef === AttachmentCreatedByRef.Subscriber && subscriberId === attachment.createdBy ) { // Either subscriber wants to access the attachment he sent diff --git a/api/src/migration/migrations/1735836154221-v-2-2-0.migration.ts b/api/src/migration/migrations/1735836154221-v-2-2-0.migration.ts index b94a68af..2f699212 100644 --- a/api/src/migration/migrations/1735836154221-v-2-2-0.migration.ts +++ b/api/src/migration/migrations/1735836154221-v-2-2-0.migration.ts @@ -16,6 +16,7 @@ import attachmentSchema, { Attachment, } from '@/attachment/schemas/attachment.schema'; import { + AttachmentAccess, AttachmentCreatedByRef, AttachmentResourceRef, } from '@/attachment/types'; @@ -619,8 +620,8 @@ const migrateAttachmentContents = async ( $set: { resourceRef: AttachmentResourceRef.ContentAttachment, createdBy: adminUser.id, - createdByRef: 'User', - access: 'public', + createdByRef: AttachmentCreatedByRef.User, + access: AttachmentAccess.Public, }, }, ); @@ -682,8 +683,10 @@ const migrateAndPopulateAttachmentMessages = async ({ msg.message.attachment.payload.attachment_id as string, { resourceRef: AttachmentResourceRef.MessageAttachment, - access: 'private', - createdByRef: msg.sender ? 'Subscriber' : 'User', + access: AttachmentAccess.Private, + createdByRef: msg.sender + ? AttachmentCreatedByRef.Subscriber + : AttachmentCreatedByRef.User, createdBy: msg.sender ? msg.sender : adminUser.id, }, ); @@ -715,9 +718,13 @@ const migrateAndPopulateAttachmentMessages = async ({ type: response.headers['content-type'], channel: {}, resourceRef: AttachmentResourceRef.MessageAttachment, - access: msg.sender ? 'private' : 'public', + access: msg.sender + ? AttachmentAccess.Private + : AttachmentAccess.Public, createdBy: msg.sender ? msg.sender : adminUser.id, - createdByRef: msg.sender ? 'Subscriber' : 'User', + createdByRef: msg.sender + ? AttachmentCreatedByRef.Subscriber + : AttachmentCreatedByRef.User, }); if (attachment) { diff --git a/api/src/user/controllers/user.controller.ts b/api/src/user/controllers/user.controller.ts index 968855b8..a30dfba2 100644 --- a/api/src/user/controllers/user.controller.ts +++ b/api/src/user/controllers/user.controller.ts @@ -31,7 +31,11 @@ import { Session as ExpressSession } from 'express-session'; import { diskStorage, memoryStorage } from 'multer'; import { AttachmentService } from '@/attachment/services/attachment.service'; -import { AttachmentResourceRef } from '@/attachment/types'; +import { + AttachmentAccess, + AttachmentCreatedByRef, + AttachmentResourceRef, +} from '@/attachment/types'; import { config } from '@/config'; import { CsrfInterceptor } from '@/interceptors/csrf.interceptor'; import { LoggerService } from '@/logger/logger.service'; @@ -296,8 +300,8 @@ export class ReadWriteUserController extends ReadOnlyUserController { size: avatarFile.size, type: avatarFile.mimetype, resourceRef: AttachmentResourceRef.UserAvatar, - access: 'private', - createdByRef: 'User', + access: AttachmentAccess.Private, + createdByRef: AttachmentCreatedByRef.User, createdBy: req.user.id, }) : undefined; diff --git a/api/src/utils/test/fixtures/attachment.ts b/api/src/utils/test/fixtures/attachment.ts index 73fda51c..77ec0f93 100644 --- a/api/src/utils/test/fixtures/attachment.ts +++ b/api/src/utils/test/fixtures/attachment.ts @@ -10,7 +10,11 @@ import mongoose from 'mongoose'; import { AttachmentCreateDto } from '@/attachment/dto/attachment.dto'; import { AttachmentModel } from '@/attachment/schemas/attachment.schema'; -import { AttachmentResourceRef } from '@/attachment/types'; +import { + AttachmentAccess, + AttachmentCreatedByRef, + AttachmentResourceRef, +} from '@/attachment/types'; export const attachmentFixtures: AttachmentCreateDto[] = [ { @@ -24,8 +28,8 @@ export const attachmentFixtures: AttachmentCreateDto[] = [ }, }, resourceRef: AttachmentResourceRef.ContentAttachment, - access: 'public', - createdByRef: 'User', + access: AttachmentAccess.Public, + createdByRef: AttachmentCreatedByRef.User, createdBy: '9'.repeat(24), }, { @@ -39,8 +43,8 @@ export const attachmentFixtures: AttachmentCreateDto[] = [ }, }, resourceRef: AttachmentResourceRef.ContentAttachment, - access: 'public', - createdByRef: 'User', + access: AttachmentAccess.Public, + createdByRef: AttachmentCreatedByRef.User, createdBy: '9'.repeat(24), }, ]; diff --git a/frontend/src/app-components/attachment/AttachmentInput.tsx b/frontend/src/app-components/attachment/AttachmentInput.tsx index 7ed77c6d..f3fb71dc 100644 --- a/frontend/src/app-components/attachment/AttachmentInput.tsx +++ b/frontend/src/app-components/attachment/AttachmentInput.tsx @@ -13,7 +13,7 @@ import { forwardRef } from "react"; import { useGet } from "@/hooks/crud/useGet"; import { useHasPermission } from "@/hooks/useHasPermission"; import { EntityType } from "@/services/types"; -import { IAttachment, TAttachmentResourceRef } from "@/types/attachment.types"; +import { AttachmentResourceRef, IAttachment } from "@/types/attachment.types"; import { PermissionAction } from "@/types/permission.types"; import AttachmentThumbnail from "./AttachmentThumbnail"; @@ -29,7 +29,7 @@ type AttachmentThumbnailProps = { onChange?: (id: string | null, mimeType: string | null) => void; error?: boolean; helperText?: string; - resourceRef: TAttachmentResourceRef; + resourceRef: AttachmentResourceRef; }; const AttachmentInput = forwardRef( diff --git a/frontend/src/app-components/attachment/AttachmentUploader.tsx b/frontend/src/app-components/attachment/AttachmentUploader.tsx index 112f111c..858eee22 100644 --- a/frontend/src/app-components/attachment/AttachmentUploader.tsx +++ b/frontend/src/app-components/attachment/AttachmentUploader.tsx @@ -17,7 +17,7 @@ import { getDisplayDialogs, useDialog } from "@/hooks/useDialog"; import { useToast } from "@/hooks/useToast"; import { useTranslate } from "@/hooks/useTranslate"; import { EntityType } from "@/services/types"; -import { IAttachment, TAttachmentResourceRef } from "@/types/attachment.types"; +import { AttachmentResourceRef, IAttachment } from "@/types/attachment.types"; import { AttachmentDialog } from "./AttachmentDialog"; import AttachmentThumbnail from "./AttachmentThumbnail"; @@ -68,7 +68,7 @@ export type FileUploadProps = { enableMediaLibrary?: boolean; onChange?: (data?: IAttachment | null) => void; onUploadComplete?: () => void; - resourceRef: TAttachmentResourceRef; + resourceRef: AttachmentResourceRef; }; const AttachmentUploader: FC = ({ diff --git a/frontend/src/app-components/attachment/MultipleAttachmentInput.tsx b/frontend/src/app-components/attachment/MultipleAttachmentInput.tsx index 11a3e069..fb4accc7 100644 --- a/frontend/src/app-components/attachment/MultipleAttachmentInput.tsx +++ b/frontend/src/app-components/attachment/MultipleAttachmentInput.tsx @@ -12,7 +12,7 @@ import { forwardRef, useState } from "react"; import { useHasPermission } from "@/hooks/useHasPermission"; import { EntityType } from "@/services/types"; -import { IAttachment, TAttachmentResourceRef } from "@/types/attachment.types"; +import { AttachmentResourceRef, IAttachment } from "@/types/attachment.types"; import { PermissionAction } from "@/types/permission.types"; import AttachmentThumbnail from "./AttachmentThumbnail"; @@ -28,7 +28,7 @@ type MultipleAttachmentInputProps = { onChange?: (ids: string[]) => void; error?: boolean; helperText?: string; - resourceRef: TAttachmentResourceRef; + resourceRef: AttachmentResourceRef; }; const MultipleAttachmentInput = forwardRef< diff --git a/frontend/src/hooks/crud/useUpload.tsx b/frontend/src/hooks/crud/useUpload.tsx index 5f5a5e44..d7d8dcec 100644 --- a/frontend/src/hooks/crud/useUpload.tsx +++ b/frontend/src/hooks/crud/useUpload.tsx @@ -9,7 +9,7 @@ import { useMutation, useQueryClient } from "react-query"; import { QueryType, TMutationOptions } from "@/services/types"; -import { TAttachmentResourceRef } from "@/types/attachment.types"; +import { AttachmentResourceRef } from "@/types/attachment.types"; import { IBaseSchema, IDynamicProps, TType } from "@/types/base.types"; import { useEntityApiClient } from "../useApiClient"; @@ -27,7 +27,7 @@ export const useUpload = < TMutationOptions< TBasic, Error, - { file: File; resourceRef: TAttachmentResourceRef }, + { file: File; resourceRef: AttachmentResourceRef }, TBasic >, "mutationFn" | "mutationKey" diff --git a/frontend/src/services/api.class.ts b/frontend/src/services/api.class.ts index ddf14d0c..360abf80 100644 --- a/frontend/src/services/api.class.ts +++ b/frontend/src/services/api.class.ts @@ -9,7 +9,7 @@ import { AxiosInstance, AxiosResponse } from "axios"; -import { TAttachmentResourceRef } from "@/types/attachment.types"; +import { AttachmentResourceRef } from "@/types/attachment.types"; import { ILoginAttributes } from "@/types/auth/login.types"; import { IUserPermissions } from "@/types/auth/permission.types"; import { StatsType } from "@/types/bot-stat.types"; @@ -302,7 +302,7 @@ export class EntityApiClient extends ApiClient { return data; } - async upload(file: File, resourceRef?: TAttachmentResourceRef) { + async upload(file: File, resourceRef?: AttachmentResourceRef) { const { _csrf } = await this.getCsrf(); const formData = new FormData(); diff --git a/frontend/src/types/attachment.types.ts b/frontend/src/types/attachment.types.ts index d70ba7b8..22a6c7ff 100644 --- a/frontend/src/types/attachment.types.ts +++ b/frontend/src/types/attachment.types.ts @@ -22,8 +22,6 @@ export enum AttachmentCreatedByRef { Subscriber = "Subscriber", } -export type TAttachmentCreatedByRef = `${AttachmentCreatedByRef}`; - /** * Defines the various resource references in which an attachment can exist. * These references influence how the attachment is uploaded, stored, and accessed: @@ -37,7 +35,10 @@ export enum AttachmentResourceRef { MessageAttachment = "Message", // Files sent or received via messages, uploaded programmatically, accessible to users with inbox permissions.; } -export type TAttachmentResourceRef = `${AttachmentResourceRef}`; +export enum AttachmentAccess { + Public = "public", + Private = "private", +} export interface IAttachmentAttributes { name: string; @@ -46,8 +47,9 @@ export interface IAttachmentAttributes { location: string; url: string; channel?: Record; - resourceRef: TAttachmentResourceRef; - createdByRef: TAttachmentCreatedByRef; + resourceRef: AttachmentResourceRef; + access: AttachmentAccess; + createdByRef: AttachmentCreatedByRef; createdBy: string | null; }