diff --git a/api/src/attachment/controllers/attachment.controller.spec.ts b/api/src/attachment/controllers/attachment.controller.spec.ts index 0d84d349..2aaf2a0f 100644 --- a/api/src/attachment/controllers/attachment.controller.spec.ts +++ b/api/src/attachment/controllers/attachment.controller.spec.ts @@ -137,16 +137,16 @@ describe('AttachmentController', () => { name: attachmentFile.originalname, location: expect.stringMatching(new RegExp(`^/${name}`)), context: 'block_attachment', - ownerType: 'User', - owner: '9'.repeat(24), + createdByRef: 'User', + createdBy: '9'.repeat(24), }); expect(result).toEqualPayload( [ { ...attachment, context: 'block_attachment', - ownerType: 'User', - owner: '9'.repeat(24), + createdByRef: 'User', + createdBy: '9'.repeat(24), }, ], [...IGNORED_TEST_FIELDS, 'location', 'url'], diff --git a/api/src/attachment/controllers/attachment.controller.ts b/api/src/attachment/controllers/attachment.controller.ts index c93dd014..ef118204 100644 --- a/api/src/attachment/controllers/attachment.controller.ts +++ b/api/src/attachment/controllers/attachment.controller.ts @@ -150,8 +150,8 @@ export class AttachmentController extends BaseController { size: file.size, type: file.mimetype, context, - owner: userId, - ownerType: 'User', + createdBy: userId, + createdByRef: 'User', }); attachments.push(attachment); } diff --git a/api/src/attachment/dto/attachment.dto.ts b/api/src/attachment/dto/attachment.dto.ts index f698b135..6c3c982f 100644 --- a/api/src/attachment/dto/attachment.dto.ts +++ b/api/src/attachment/dto/attachment.dto.ts @@ -25,9 +25,9 @@ import { IsObjectId } from '@/utils/validation-rules/is-object-id'; import { AttachmentContext, - AttachmentOwnerType, + AttachmentCreatedByRef, TAttachmentContext, - TAttachmentOwnerType, + TAttachmentCreatedByRef, } from '../types'; export class AttachmentMetadataDto { @@ -81,12 +81,12 @@ export class AttachmentMetadataDto { */ @ApiPropertyOptional({ description: 'Attachment Owner Type', - enum: Object.values(AttachmentOwnerType), + enum: Object.values(AttachmentCreatedByRef), }) @IsString() @IsNotEmpty() - @IsIn(Object.values(AttachmentOwnerType)) - ownerType: TAttachmentOwnerType; + @IsIn(Object.values(AttachmentCreatedByRef)) + createdByRef: TAttachmentCreatedByRef; /** * Attachment Owner : Subscriber or User ID @@ -98,7 +98,7 @@ export class AttachmentMetadataDto { @IsString() @IsNotEmpty() @IsObjectId({ message: 'Owner must be a valid ObjectId' }) - owner: string; + createdBy: string; } export class AttachmentCreateDto extends AttachmentMetadataDto { diff --git a/api/src/attachment/mocks/attachment.mock.ts b/api/src/attachment/mocks/attachment.mock.ts index d0dbfef7..112201a8 100644 --- a/api/src/attachment/mocks/attachment.mock.ts +++ b/api/src/attachment/mocks/attachment.mock.ts @@ -20,8 +20,8 @@ export const attachment: Attachment = { id: '65940d115178607da65c82b6', createdAt: new Date(), updatedAt: new Date(), - owner: '1', - ownerType: 'User', + createdBy: '1', + createdByRef: 'User', }; export const attachmentFile: Express.Multer.File = { @@ -50,8 +50,8 @@ export const attachments: Attachment[] = [ id: '65940d115178607da65c82b7', createdAt: new Date(), updatedAt: new Date(), - owner: '1', - ownerType: 'User', + createdBy: '1', + createdByRef: 'User', }, { name: 'Screenshot from 2022-03-18 08-58-15-af61e7f71281f9fd3f1ad7ad10107741c.png', @@ -64,7 +64,7 @@ export const attachments: Attachment[] = [ id: '65940d115178607da65c82b8', createdAt: new Date(), updatedAt: new Date(), - owner: '1', - ownerType: 'User', + createdBy: '1', + createdByRef: 'User', }, ]; diff --git a/api/src/attachment/schemas/attachment.schema.ts b/api/src/attachment/schemas/attachment.schema.ts index 8a7a9b4e..10d341c4 100644 --- a/api/src/attachment/schemas/attachment.schema.ts +++ b/api/src/attachment/schemas/attachment.schema.ts @@ -25,9 +25,9 @@ import { import { AttachmentContext, - AttachmentOwnerType, + AttachmentCreatedByRef, TAttachmentContext, - TAttachmentOwnerType, + TAttachmentCreatedByRef, } from '../types'; import { MIME_REGEX } from '../utilities'; @@ -79,20 +79,20 @@ export class AttachmentStub extends BaseSchema { channel?: Partial>; /** - * Object ID of the owner (depending on the owner type) + * Object ID of the createdBy (depending on the createdBy type) */ @Prop({ type: MongooseSchema.Types.ObjectId, - refPath: 'ownerType', + refPath: 'createdByRef', default: null, }) - owner: unknown; + createdBy: unknown; /** - * Type of the owner (depending on the owner type) + * Type of the createdBy (depending on the createdBy type) */ - @Prop({ type: String, enum: Object.values(AttachmentOwnerType) }) - ownerType: TAttachmentOwnerType; + @Prop({ type: String, enum: Object.values(AttachmentCreatedByRef) }) + createdByRef: TAttachmentCreatedByRef; /** * Context of the attachment @@ -142,20 +142,20 @@ export class AttachmentStub extends BaseSchema { @Schema({ timestamps: true }) export class Attachment extends AttachmentStub { - @Transform(({ obj }) => obj.owner?.toString() || null) - owner: string | null; + @Transform(({ obj }) => obj.createdBy?.toString() || null) + createdBy: string | null; } @Schema({ timestamps: true }) export class UserAttachmentFull extends AttachmentStub { @Type(() => User) - owner: User | undefined; + createdBy: User | undefined; } @Schema({ timestamps: true }) export class SubscriberAttachmentFull extends AttachmentStub { @Type(() => Subscriber) - owner: Subscriber | undefined; + createdBy: Subscriber | undefined; } export type AttachmentDocument = THydratedDocument; @@ -182,4 +182,4 @@ export type AttachmentPopulate = keyof TFilterPopulateFields< AttachmentStub >; -export const ATTACHMENT_POPULATE: AttachmentPopulate[] = ['owner']; +export const ATTACHMENT_POPULATE: AttachmentPopulate[] = ['createdBy']; diff --git a/api/src/attachment/types/index.ts b/api/src/attachment/types/index.ts index 9accd75c..b2a136b3 100644 --- a/api/src/attachment/types/index.ts +++ b/api/src/attachment/types/index.ts @@ -9,15 +9,15 @@ import { Readable, Stream } from 'stream'; /** - * Defines the types of owners for an attachment, + * Defines the types of createdBys for an attachment, * indicating whether the file belongs to a User or a Subscriber. */ -export enum AttachmentOwnerType { +export enum AttachmentCreatedByRef { User = 'User', Subscriber = 'Subscriber', } -export type TAttachmentOwnerType = `${AttachmentOwnerType}`; +export type TAttachmentCreatedByRef = `${AttachmentCreatedByRef}`; /** * Defines the various contexts in which an attachment can exist. diff --git a/api/src/channel/lib/Handler.ts b/api/src/channel/lib/Handler.ts index ee0e7ccb..49604f43 100644 --- a/api/src/channel/lib/Handler.ts +++ b/api/src/channel/lib/Handler.ts @@ -259,8 +259,8 @@ export default abstract class ChannelHandler< type, size, context: 'message_attachment', - ownerType: 'Subscriber', - owner: subscriber.id, + createdByRef: 'Subscriber', + createdBy: subscriber.id, }); }), ); diff --git a/api/src/channel/lib/__test__/common.mock.ts b/api/src/channel/lib/__test__/common.mock.ts index dcb27049..34826cbe 100644 --- a/api/src/channel/lib/__test__/common.mock.ts +++ b/api/src/channel/lib/__test__/common.mock.ts @@ -89,8 +89,8 @@ const attachment: Attachment = { }, }, context: 'block_attachment', - ownerType: 'User', - owner: null, + createdByRef: '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 8b8dc5ea..672bccd7 100644 --- a/api/src/chat/services/chat.service.ts +++ b/api/src/chat/services/chat.service.ts @@ -277,8 +277,8 @@ export class ChatService { size, type, context: 'subscriber_avatar', - ownerType: 'Subscriber', - owner: subscriber.id, + createdByRef: 'Subscriber', + createdBy: subscriber.id, }); if (avatar) { diff --git a/api/src/extensions/channels/web/base-web-channel.ts b/api/src/extensions/channels/web/base-web-channel.ts index 44421ebd..8f165677 100644 --- a/api/src/extensions/channels/web/base-web-channel.ts +++ b/api/src/extensions/channels/web/base-web-channel.ts @@ -621,8 +621,8 @@ export default abstract class BaseWebChannelHandler< size: Buffer.byteLength(data.file), type: data.type, context: 'message_attachment', - ownerType: 'Subscriber', - owner: req.session.web.profile?.id, + createdByRef: 'Subscriber', + createdBy: req.session.web.profile?.id, }); } catch (err) { this.logger.error( @@ -687,8 +687,8 @@ export default abstract class BaseWebChannelHandler< size: file.size, type: file.mimetype, context: 'message_attachment', - ownerType: 'Subscriber', - owner: req.session.web.profile?.id, + createdByRef: 'Subscriber', + createdBy: req.session.web.profile?.id, }); } catch (err) { this.logger.error( 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 052e02d7..a92ef24c 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 @@ -15,7 +15,7 @@ import { v4 as uuidv4 } from 'uuid'; import attachmentSchema, { Attachment, } from '@/attachment/schemas/attachment.schema'; -import { AttachmentContext, AttachmentOwnerType } from '@/attachment/types'; +import { AttachmentContext, AttachmentCreatedByRef } from '@/attachment/types'; import blockSchema, { Block } from '@/chat/schemas/block.schema'; import messageSchema, { Message } from '@/chat/schemas/message.schema'; import subscriberSchema, { Subscriber } from '@/chat/schemas/subscriber.schema'; @@ -80,8 +80,8 @@ const populateBlockAttachments = async ({ logger }: MigrationServices) => { { $set: { context: AttachmentContext.BlockAttachment, - ownerType: AttachmentOwnerType.User, - owner: user._id, + createdByRef: AttachmentCreatedByRef.User, + createdBy: user._id, }, }, ); @@ -102,7 +102,7 @@ const populateBlockAttachments = async ({ logger }: MigrationServices) => { }; /** - * Updates setting attachment documents to populate new attributes (context, owner, ownerType) + * Updates setting attachment documents to populate new attributes (context, createdBy, createdByRef) * * @returns Resolves when the migration process is complete. */ @@ -130,8 +130,8 @@ const populateSettingAttachments = async ({ logger }: MigrationServices) => { { $set: { context: AttachmentContext.SettingAttachment, - ownerType: AttachmentOwnerType.User, - owner: user._id, + createdByRef: AttachmentCreatedByRef.User, + createdBy: user._id, }, }, ); @@ -146,7 +146,7 @@ const populateSettingAttachments = async ({ logger }: MigrationServices) => { }; /** - * Updates user attachment documents to populate new attributes (context, owner, ownerType) + * Updates user attachment documents to populate new attributes (context, createdBy, createdByRef) * * @returns Resolves when the migration process is complete. */ @@ -168,8 +168,8 @@ const populateUserAvatars = async ({ logger }: MigrationServices) => { { $set: { context: AttachmentContext.UserAvatar, - ownerType: AttachmentOwnerType.User, - owner: user._id, + createdByRef: AttachmentCreatedByRef.User, + createdBy: user._id, }, }, ); @@ -184,7 +184,7 @@ const populateUserAvatars = async ({ logger }: MigrationServices) => { /** * Updates subscriber documents with their corresponding avatar attachments, - * populate new attributes (context, owner, ownerType) and moves avatar files to a new directory. + * populate new attributes (context, createdBy, createdByRef) and moves avatar files to a new directory. * * @returns Resolves when the migration process is complete. */ @@ -229,8 +229,8 @@ const populateSubscriberAvatars = async ({ logger }: MigrationServices) => { { $set: { context: AttachmentContext.SubscriberAvatar, - ownerType: AttachmentOwnerType.Subscriber, - owner: subscriber._id, + createdByRef: AttachmentCreatedByRef.Subscriber, + createdBy: subscriber._id, }, }, ); @@ -361,8 +361,8 @@ const undoPopulateAttachments = async ({ logger }: MigrationServices) => { { $unset: { context: '', - ownerType: '', - owner: '', + createdByRef: '', + createdBy: '', }, }, ); @@ -640,8 +640,8 @@ const migrateAndPopulateAttachmentMessages = async ({ await attachmentService.updateOne( msg.message.attachment.payload.attachment_id, { - ownerType: msg.sender ? 'Subscriber' : 'User', - owner: msg.sender ? msg.sender : adminUser.id, + createdByRef: msg.sender ? 'Subscriber' : 'User', + createdBy: msg.sender ? msg.sender : adminUser.id, context: 'message_attachment', }, ); @@ -672,8 +672,8 @@ const migrateAndPopulateAttachmentMessages = async ({ size: fileBuffer.length, type: response.headers['content-type'], channel: {}, - owner: msg.sender ? msg.sender : adminUser.id, - ownerType: msg.sender ? 'Subscriber' : 'User', + createdBy: msg.sender ? msg.sender : adminUser.id, + createdByRef: msg.sender ? 'Subscriber' : 'User', context: 'message_attachment', }); diff --git a/api/src/user/controllers/user.controller.ts b/api/src/user/controllers/user.controller.ts index 4cd16405..5c528450 100644 --- a/api/src/user/controllers/user.controller.ts +++ b/api/src/user/controllers/user.controller.ts @@ -295,8 +295,8 @@ export class ReadWriteUserController extends ReadOnlyUserController { size: avatarFile.size, type: avatarFile.mimetype, context: 'user_avatar', - ownerType: 'User', - owner: req.user.id, + createdByRef: 'User', + createdBy: req.user.id, }) : undefined; diff --git a/api/src/user/types/index.type.ts b/api/src/user/types/index.type.ts index 59eec88a..9eee3c2c 100644 --- a/api/src/user/types/index.type.ts +++ b/api/src/user/types/index.type.ts @@ -1,9 +1,9 @@ /* - * Copyright © 2024 Hexastack. All rights reserved. + * Copyright © 2025 Hexastack. All rights reserved. * * Licensed under the GNU Affero General Public License v3.0 (AGPLv3) with the following additional terms: * 1. The name "Hexabot" is a trademark of Hexastack. You may not use this name in derivative works without express written permission. * 2. All derivative works must include clear attribution to the original creator and software, Hexastack and Hexabot, in a prominent location (e.g., in the software's "About" section, documentation, and README file). */ -export type TRelation = 'role' | 'owner'; +export type TRelation = 'role' | 'createdBy'; diff --git a/api/src/utils/test/fixtures/attachment.ts b/api/src/utils/test/fixtures/attachment.ts index e60880bc..2bef61c7 100644 --- a/api/src/utils/test/fixtures/attachment.ts +++ b/api/src/utils/test/fixtures/attachment.ts @@ -23,8 +23,8 @@ export const attachmentFixtures: AttachmentCreateDto[] = [ }, }, context: 'content_attachment', - ownerType: 'User', - owner: null, + createdByRef: 'User', + createdBy: null, }, { name: 'store2.jpg', @@ -37,8 +37,8 @@ export const attachmentFixtures: AttachmentCreateDto[] = [ }, }, context: 'content_attachment', - ownerType: 'User', - owner: null, + createdByRef: 'User', + createdBy: null, }, ]; diff --git a/frontend/src/types/attachment.types.ts b/frontend/src/types/attachment.types.ts index adfdc8aa..aafd5aac 100644 --- a/frontend/src/types/attachment.types.ts +++ b/frontend/src/types/attachment.types.ts @@ -17,12 +17,12 @@ import { IUser } from "./user.types"; * Defines the types of owners for an attachment, * indicating whether the file belongs to a User or a Subscriber. */ -export enum AttachmentOwnerType { +export enum AttachmentCreatedByRef { User = "User", Subscriber = "Subscriber", } -export type TAttachmentOwnerType = `${AttachmentOwnerType}`; +export type TAttachmentCreatedByRef = `${AttachmentCreatedByRef}`; /** * Defines the various contexts in which an attachment can exist. @@ -47,8 +47,8 @@ export interface IAttachmentAttributes { url: string; channel?: Record; context: TAttachmentContext; - ownerType: TAttachmentOwnerType; - owner: string | null; + createdByRef: TAttachmentCreatedByRef; + createdBy: string | null; } export interface IAttachmentStub @@ -56,11 +56,11 @@ export interface IAttachmentStub OmitPopulate {} export interface IAttachment extends IAttachmentStub, IFormat { - owner: string | null; + createdBy: string | null; } export interface ISubscriberAttachmentFull extends IAttachmentStub, IFormat { - owner: (ISubscriber | IUser)[]; + createdBy: (ISubscriber | IUser)[]; } diff --git a/frontend/src/types/base.types.ts b/frontend/src/types/base.types.ts index 77dd4b11..29bb91d6 100644 --- a/frontend/src/types/base.types.ts +++ b/frontend/src/types/base.types.ts @@ -110,7 +110,7 @@ export const POPULATE_BY_TYPE = { [EntityType.MENUTREE]: [], [EntityType.LANGUAGE]: [], [EntityType.TRANSLATION]: [], - [EntityType.ATTACHMENT]: ["owner"], + [EntityType.ATTACHMENT]: ["createdBy"], [EntityType.CUSTOM_BLOCK]: [], [EntityType.CUSTOM_BLOCK_SETTINGS]: [], [EntityType.CHANNEL]: [], diff --git a/frontend/src/types/model.types.ts b/frontend/src/types/model.types.ts index 83145b06..51bccd40 100644 --- a/frontend/src/types/model.types.ts +++ b/frontend/src/types/model.types.ts @@ -1,17 +1,18 @@ /* - * Copyright © 2024 Hexastack. All rights reserved. + * Copyright © 2025 Hexastack. All rights reserved. * * Licensed under the GNU Affero General Public License v3.0 (AGPLv3) with the following additional terms: * 1. The name "Hexabot" is a trademark of Hexastack. You may not use this name in derivative works without express written permission. * 2. All derivative works must include clear attribution to the original creator and software, Hexastack and Hexabot, in a prominent location (e.g., in the software's "About" section, documentation, and README file). */ + import { EntityType, Format } from "@/services/types"; import { IBaseSchema, IFormat, OmitPopulate } from "./base.types"; import { IPermission } from "./permission.types"; -export type TRelation = "role" | "owner"; +export type TRelation = "role" | "createdBy"; export interface IModelAttributes { name: string;