diff --git a/Common/Types/Database/ColumnType.ts b/Common/Types/Database/ColumnType.ts index 525f9333f3..9a18889702 100644 --- a/Common/Types/Database/ColumnType.ts +++ b/Common/Types/Database/ColumnType.ts @@ -24,6 +24,7 @@ enum ColumnType { SmallNumber = 'smallint', Number = 'integer', BigNumber = 'bigint', + Markdown = 'text', } export default ColumnType; diff --git a/Common/Types/Permission.ts b/Common/Types/Permission.ts index 95a7d6f0e1..4e0c5c2dff 100644 --- a/Common/Types/Permission.ts +++ b/Common/Types/Permission.ts @@ -92,10 +92,10 @@ enum Permission { CanDeleteIncidentInternalNote = 'CanDeleteIncidentInternalNote', CanReadIncidentInternalNote = 'CanReadIncidentInternalNote', - CanCreateIncidentStatusPageNote = 'CanCreateIncidentStatusPageNote', - CanEditIncidentStatusPageNote = 'CanEditIncidentStatusPageNote', - CanDeleteIncidentStatusPageNote = 'CanDeleteIncidentStatusPageNote', - CanReadIncidentStatusPageNote = 'CanReadIncidentStatusPageNote', + CanCreateIncidentPublicNote = 'CanCreateIncidentPublicNote', + CanEditIncidentPublicNote = 'CanEditIncidentPublicNote', + CanDeleteIncidentPublicNote = 'CanDeleteIncidentPublicNote', + CanReadIncidentPublicNote = 'CanReadIncidentPublicNote', CanCreateProjectMonitor = 'CanCreateProjectMonitor', CanEditProjectMonitor = 'CanEditProjectMonitor', @@ -561,28 +561,28 @@ export class PermissionHelper { { - permission: Permission.CanCreateIncidentStatusPageNote, + permission: Permission.CanCreateIncidentPublicNote, title: 'Can Create Incident Status Page Note', description: 'A user assigned this permission can create Incident Status Page Note this project.', isAssignableToProject: true, }, { - permission: Permission.CanDeleteIncidentStatusPageNote, + permission: Permission.CanDeleteIncidentPublicNote, title: 'Can Delete Incident Status Page Note', description: 'A user assigned this permission can delete Incident Status Page Note of this project.', isAssignableToProject: true, }, { - permission: Permission.CanEditIncidentStatusPageNote, + permission: Permission.CanEditIncidentPublicNote, title: 'Can Edit Incident Status Page Note', description: 'A user assigned this permission can edit Incident Status Page Note of this project.', isAssignableToProject: true, }, { - permission: Permission.CanReadIncidentStatusPageNote, + permission: Permission.CanReadIncidentPublicNote, title: 'Can Read Incident Status Page Note', description: 'A user assigned this permission can read Incident Status Page Note of this project.', diff --git a/Model/Models/IncidentInternalNote.ts b/Model/Models/IncidentInternalNote.ts new file mode 100644 index 0000000000..d420aa752c --- /dev/null +++ b/Model/Models/IncidentInternalNote.ts @@ -0,0 +1,227 @@ +import { Column, Entity, Index, JoinColumn, ManyToOne } from 'typeorm'; +import BaseModel from 'Common/Models/BaseModel'; +import User from './User'; +import Project from './Project'; +import CrudApiEndpoint from 'Common/Types/Database/CrudApiEndpoint'; +import Route from 'Common/Types/API/Route'; +import TableColumnType from 'Common/Types/Database/TableColumnType'; +import TableColumn from 'Common/Types/Database/TableColumn'; +import ColumnType from 'Common/Types/Database/ColumnType'; +import ObjectID from 'Common/Types/ObjectID'; +import TableAccessControl from 'Common/Types/Database/AccessControl/TableAccessControl'; +import Permission from 'Common/Types/Permission'; +import ColumnAccessControl from 'Common/Types/Database/AccessControl/ColumnAccessControl'; +import TenantColumn from 'Common/Types/Database/TenantColumn'; +import SingularPluralName from 'Common/Types/Database/SingularPluralName'; +import Incident from './Incident'; + +@TenantColumn('projectId') +@TableAccessControl({ + create: [Permission.ProjectOwner, Permission.CanCreateIncidentInternalNote], + read: [ + Permission.ProjectOwner, + Permission.CanReadIncidentInternalNote, + Permission.ProjectMember, + ], + delete: [Permission.ProjectOwner, Permission.CanDeleteIncidentInternalNote], + update: [Permission.ProjectOwner, Permission.CanEditIncidentInternalNote], +}) +@CrudApiEndpoint(new Route('/incident-internal-note')) +@Entity({ + name: 'IncidentInternalNote', +}) +@SingularPluralName('Internal Note', 'Internal Notes') +export default class IncidentInternalNote extends BaseModel { + @ColumnAccessControl({ + create: [Permission.ProjectOwner, Permission.CanCreateIncidentInternalNote], + read: [ + Permission.ProjectOwner, + Permission.CanReadIncidentInternalNote, + Permission.ProjectMember, + ], + update: [], + }) + @TableColumn({ + manyToOneRelationColumn: 'projectId', + type: TableColumnType.Entity, + modelType: Project, + }) + @ManyToOne( + (_type: string) => { + return Project; + }, + { + eager: false, + nullable: true, + onDelete: 'CASCADE', + orphanedRowAction: 'nullify', + } + ) + @JoinColumn({ name: 'projectId' }) + public project?: Project = undefined; + + @ColumnAccessControl({ + create: [Permission.ProjectOwner, Permission.CanCreateIncidentInternalNote], + read: [ + Permission.ProjectOwner, + Permission.CanReadIncidentInternalNote, + Permission.ProjectMember, + ], + update: [], + }) + @Index() + @TableColumn({ type: TableColumnType.ObjectID, required: true }) + @Column({ + type: ColumnType.ObjectID, + nullable: false, + transformer: ObjectID.getDatabaseTransformer(), + }) + public projectId?: ObjectID = undefined; + + @ColumnAccessControl({ + create: [Permission.ProjectOwner, Permission.CanCreateIncidentInternalNote], + read: [ + Permission.ProjectOwner, + Permission.CanReadIncidentInternalNote, + Permission.ProjectMember, + ], + update: [], + }) + @TableColumn({ + manyToOneRelationColumn: 'incidentId', + type: TableColumnType.Entity, + modelType: Incident, + }) + @ManyToOne( + (_type: string) => { + return Incident; + }, + { + eager: false, + nullable: true, + onDelete: 'CASCADE', + orphanedRowAction: 'nullify', + } + ) + @JoinColumn({ name: 'incidentId' }) + public incident?: Incident = undefined; + + @ColumnAccessControl({ + create: [Permission.ProjectOwner, Permission.CanCreateIncidentInternalNote], + read: [ + Permission.ProjectOwner, + Permission.CanReadIncidentInternalNote, + Permission.ProjectMember, + ], + update: [], + }) + @Index() + @TableColumn({ type: TableColumnType.ObjectID, required: true }) + @Column({ + type: ColumnType.ObjectID, + nullable: false, + transformer: ObjectID.getDatabaseTransformer(), + }) + public incidentId?: ObjectID = undefined; + + @ColumnAccessControl({ + create: [Permission.ProjectOwner, Permission.CanCreateIncidentInternalNote], + read: [ + Permission.ProjectOwner, + Permission.CanReadIncidentInternalNote, + Permission.ProjectMember, + ], + update: [], + }) + @TableColumn({ + manyToOneRelationColumn: 'createdByUserId', + type: TableColumnType.Entity, + modelType: Project, + }) + @ManyToOne( + (_type: string) => { + return User; + }, + { + eager: false, + nullable: true, + onDelete: 'CASCADE', + orphanedRowAction: 'nullify', + } + ) + @JoinColumn({ name: 'createdByUserId' }) + public createdByUser?: User = undefined; + + @ColumnAccessControl({ + create: [Permission.ProjectOwner, Permission.CanCreateIncidentInternalNote], + read: [ + Permission.ProjectOwner, + Permission.CanReadIncidentInternalNote, + Permission.ProjectMember, + ], + update: [], + }) + @TableColumn({ type: TableColumnType.ObjectID }) + @Column({ + type: ColumnType.ObjectID, + nullable: true, + transformer: ObjectID.getDatabaseTransformer(), + }) + public createdByUserId?: ObjectID = undefined; + + @ColumnAccessControl({ + create: [], + read: [], + update: [], + }) + @TableColumn({ + manyToOneRelationColumn: 'deletedByUserId', + type: TableColumnType.ObjectID, + }) + @ManyToOne( + (_type: string) => { + return User; + }, + { + cascade: false, + eager: false, + nullable: true, + onDelete: 'CASCADE', + orphanedRowAction: 'nullify', + } + ) + @JoinColumn({ name: 'deletedByUserId' }) + public deletedByUser?: User = undefined; + + @ColumnAccessControl({ + create: [], + read: [Permission.ProjectMember], + update: [], + }) + @TableColumn({ type: TableColumnType.ObjectID }) + @Column({ + type: ColumnType.ObjectID, + nullable: true, + transformer: ObjectID.getDatabaseTransformer(), + }) + public deletedByUserId?: ObjectID = undefined; + + + @ColumnAccessControl({ + create: [Permission.ProjectOwner, Permission.CanCreateIncidentInternalNote], + read: [ + Permission.ProjectOwner, + Permission.CanReadIncidentInternalNote, + Permission.ProjectMember, + ], + update: [ Permission.ProjectOwner, Permission.CanEditIncidentInternalNote,], + }) + @TableColumn({ type: TableColumnType.ShortText }) + @Column({ + type: ColumnType.Markdown, + nullable: false, + unique: false, + }) + public note?: string = undefined; + +} diff --git a/Model/Models/IncidentPublicNote.ts b/Model/Models/IncidentPublicNote.ts new file mode 100644 index 0000000000..a024a86dbb --- /dev/null +++ b/Model/Models/IncidentPublicNote.ts @@ -0,0 +1,227 @@ +import { Column, Entity, Index, JoinColumn, ManyToOne } from 'typeorm'; +import BaseModel from 'Common/Models/BaseModel'; +import User from './User'; +import Project from './Project'; +import CrudApiEndpoint from 'Common/Types/Database/CrudApiEndpoint'; +import Route from 'Common/Types/API/Route'; +import TableColumnType from 'Common/Types/Database/TableColumnType'; +import TableColumn from 'Common/Types/Database/TableColumn'; +import ColumnType from 'Common/Types/Database/ColumnType'; +import ObjectID from 'Common/Types/ObjectID'; +import TableAccessControl from 'Common/Types/Database/AccessControl/TableAccessControl'; +import Permission from 'Common/Types/Permission'; +import ColumnAccessControl from 'Common/Types/Database/AccessControl/ColumnAccessControl'; +import TenantColumn from 'Common/Types/Database/TenantColumn'; +import SingularPluralName from 'Common/Types/Database/SingularPluralName'; +import Incident from './Incident'; + +@TenantColumn('projectId') +@TableAccessControl({ + create: [Permission.ProjectOwner, Permission.CanCreateIncidentPublicNote], + read: [ + Permission.ProjectOwner, + Permission.CanReadIncidentPublicNote, + Permission.ProjectMember, + ], + delete: [Permission.ProjectOwner, Permission.CanDeleteIncidentPublicNote], + update: [Permission.ProjectOwner, Permission.CanEditIncidentPublicNote], +}) +@CrudApiEndpoint(new Route('/incident-public-note')) +@Entity({ + name: 'IncidentPublicNote', +}) +@SingularPluralName('Public Note', 'Public Notes') +export default class IncidentPublicNote extends BaseModel { + @ColumnAccessControl({ + create: [Permission.ProjectOwner, Permission.CanCreateIncidentPublicNote], + read: [ + Permission.ProjectOwner, + Permission.CanReadIncidentPublicNote, + Permission.ProjectMember, + ], + update: [], + }) + @TableColumn({ + manyToOneRelationColumn: 'projectId', + type: TableColumnType.Entity, + modelType: Project, + }) + @ManyToOne( + (_type: string) => { + return Project; + }, + { + eager: false, + nullable: true, + onDelete: 'CASCADE', + orphanedRowAction: 'nullify', + } + ) + @JoinColumn({ name: 'projectId' }) + public project?: Project = undefined; + + @ColumnAccessControl({ + create: [Permission.ProjectOwner, Permission.CanCreateIncidentPublicNote], + read: [ + Permission.ProjectOwner, + Permission.CanReadIncidentPublicNote, + Permission.ProjectMember, + ], + update: [], + }) + @Index() + @TableColumn({ type: TableColumnType.ObjectID, required: true }) + @Column({ + type: ColumnType.ObjectID, + nullable: false, + transformer: ObjectID.getDatabaseTransformer(), + }) + public projectId?: ObjectID = undefined; + + @ColumnAccessControl({ + create: [Permission.ProjectOwner, Permission.CanCreateIncidentPublicNote], + read: [ + Permission.ProjectOwner, + Permission.CanReadIncidentPublicNote, + Permission.ProjectMember, + ], + update: [], + }) + @TableColumn({ + manyToOneRelationColumn: 'incidentId', + type: TableColumnType.Entity, + modelType: Incident, + }) + @ManyToOne( + (_type: string) => { + return Incident; + }, + { + eager: false, + nullable: true, + onDelete: 'CASCADE', + orphanedRowAction: 'nullify', + } + ) + @JoinColumn({ name: 'incidentId' }) + public incident?: Incident = undefined; + + @ColumnAccessControl({ + create: [Permission.ProjectOwner, Permission.CanCreateIncidentPublicNote], + read: [ + Permission.ProjectOwner, + Permission.CanReadIncidentPublicNote, + Permission.ProjectMember, + ], + update: [], + }) + @Index() + @TableColumn({ type: TableColumnType.ObjectID, required: true }) + @Column({ + type: ColumnType.ObjectID, + nullable: false, + transformer: ObjectID.getDatabaseTransformer(), + }) + public incidentId?: ObjectID = undefined; + + @ColumnAccessControl({ + create: [Permission.ProjectOwner, Permission.CanCreateIncidentPublicNote], + read: [ + Permission.ProjectOwner, + Permission.CanReadIncidentPublicNote, + Permission.ProjectMember, + ], + update: [], + }) + @TableColumn({ + manyToOneRelationColumn: 'createdByUserId', + type: TableColumnType.Entity, + modelType: Project, + }) + @ManyToOne( + (_type: string) => { + return User; + }, + { + eager: false, + nullable: true, + onDelete: 'CASCADE', + orphanedRowAction: 'nullify', + } + ) + @JoinColumn({ name: 'createdByUserId' }) + public createdByUser?: User = undefined; + + @ColumnAccessControl({ + create: [Permission.ProjectOwner, Permission.CanCreateIncidentPublicNote], + read: [ + Permission.ProjectOwner, + Permission.CanReadIncidentPublicNote, + Permission.ProjectMember, + ], + update: [], + }) + @TableColumn({ type: TableColumnType.ObjectID }) + @Column({ + type: ColumnType.ObjectID, + nullable: true, + transformer: ObjectID.getDatabaseTransformer(), + }) + public createdByUserId?: ObjectID = undefined; + + @ColumnAccessControl({ + create: [], + read: [], + update: [], + }) + @TableColumn({ + manyToOneRelationColumn: 'deletedByUserId', + type: TableColumnType.ObjectID, + }) + @ManyToOne( + (_type: string) => { + return User; + }, + { + cascade: false, + eager: false, + nullable: true, + onDelete: 'CASCADE', + orphanedRowAction: 'nullify', + } + ) + @JoinColumn({ name: 'deletedByUserId' }) + public deletedByUser?: User = undefined; + + @ColumnAccessControl({ + create: [], + read: [Permission.ProjectMember], + update: [], + }) + @TableColumn({ type: TableColumnType.ObjectID }) + @Column({ + type: ColumnType.ObjectID, + nullable: true, + transformer: ObjectID.getDatabaseTransformer(), + }) + public deletedByUserId?: ObjectID = undefined; + + + @ColumnAccessControl({ + create: [Permission.ProjectOwner, Permission.CanCreateIncidentPublicNote], + read: [ + Permission.ProjectOwner, + Permission.CanReadIncidentPublicNote, + Permission.ProjectMember, + ], + update: [ Permission.ProjectOwner, Permission.CanEditIncidentPublicNote,], + }) + @TableColumn({ type: TableColumnType.ShortText }) + @Column({ + type: ColumnType.Markdown, + nullable: false, + unique: false, + }) + public note?: string = undefined; + +}