oneuptime/Model/Models/IncidentState.ts
Kevin Jagodic ac7b04e8ad Change delete permission to Free plan in model files
Updated the 'delete' permissions for Team, IncidentState, TeamPermission, ScheduledMaintenanceState, Label, and MonitorStatus model files from 'PlanSelect.Growth' to 'PlanSelect.Free'. This change allows users with a 'Free' plan to have the ability to delete these specific resources.
2023-11-18 14:45:36 +01:00

529 lines
15 KiB
TypeScript

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 SlugifyColumn from 'Common/Types/Database/SlugifyColumn';
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 ColumnLength from 'Common/Types/Database/ColumnLength';
import Color from 'Common/Types/Color';
import TableAccessControl from 'Common/Types/Database/AccessControl/TableAccessControl';
import Permission from 'Common/Types/Permission';
import ColumnAccessControl from 'Common/Types/Database/AccessControl/ColumnAccessControl';
import UniqueColumnBy from 'Common/Types/Database/UniqueColumnBy';
import TenantColumn from 'Common/Types/Database/TenantColumn';
import TableMetadata from 'Common/Types/Database/TableMetadata';
import EnableWorkflow from 'Common/Types/Database/EnableWorkflow';
import IconProp from 'Common/Types/Icon/IconProp';
import EnableDocumentation from 'Common/Types/Database/EnableDocumentation';
import TableBillingAccessControl from 'Common/Types/Database/AccessControl/TableBillingAccessControl';
import { PlanSelect } from 'Common/Types/Billing/SubscriptionPlan';
@TableBillingAccessControl({
create: PlanSelect.Growth,
read: PlanSelect.Free,
update: PlanSelect.Growth,
delete: PlanSelect.Free,
})
@EnableDocumentation()
@TenantColumn('projectId')
@TableAccessControl({
create: [
Permission.ProjectOwner,
Permission.ProjectAdmin,
Permission.ProjectMember,
Permission.CanCreateIncidentState,
],
read: [
Permission.ProjectOwner,
Permission.ProjectAdmin,
Permission.ProjectMember,
Permission.CanReadIncidentState,
],
delete: [
Permission.ProjectOwner,
Permission.ProjectAdmin,
Permission.ProjectMember,
Permission.CanDeleteIncidentState,
],
update: [
Permission.ProjectOwner,
Permission.ProjectAdmin,
Permission.ProjectMember,
Permission.CanEditIncidentState,
],
})
@EnableWorkflow({
create: true,
delete: true,
update: true,
read: true,
})
@CrudApiEndpoint(new Route('/incident-state'))
@SlugifyColumn('name', 'slug')
@TableMetadata({
tableName: 'IncidentState',
singularName: 'Incident State',
pluralName: 'Incident States',
icon: IconProp.ArrowCircleRight,
tableDescription:
'Manage incident states for your project (Created, Acknowledged for example). Add / edit or remove states.',
})
@Entity({
name: 'IncidentState',
})
export default class IncidentState extends BaseModel {
@ColumnAccessControl({
create: [
Permission.ProjectOwner,
Permission.ProjectAdmin,
Permission.ProjectMember,
Permission.CanCreateIncidentState,
],
read: [
Permission.ProjectOwner,
Permission.ProjectAdmin,
Permission.ProjectMember,
Permission.CanReadIncidentState,
],
update: [],
})
@TableColumn({
manyToOneRelationColumn: 'projectId',
type: TableColumnType.Entity,
modelType: Project,
title: 'Project',
description:
'Relation to Project Resource in which this object belongs',
})
@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.ProjectAdmin,
Permission.ProjectMember,
Permission.CanCreateIncidentState,
],
read: [
Permission.ProjectOwner,
Permission.ProjectAdmin,
Permission.ProjectMember,
Permission.CanReadIncidentState,
],
update: [],
})
@Index()
@TableColumn({
type: TableColumnType.ObjectID,
required: true,
canReadOnRelationQuery: true,
title: 'Project ID',
description:
'ID of your OneUptime Project in which this object belongs',
})
@Column({
type: ColumnType.ObjectID,
nullable: false,
transformer: ObjectID.getDatabaseTransformer(),
})
public projectId?: ObjectID = undefined;
@ColumnAccessControl({
create: [
Permission.ProjectOwner,
Permission.ProjectAdmin,
Permission.ProjectMember,
Permission.CanCreateIncidentState,
],
read: [
Permission.ProjectOwner,
Permission.ProjectAdmin,
Permission.ProjectMember,
Permission.CanReadIncidentState,
],
update: [
Permission.ProjectOwner,
Permission.ProjectAdmin,
Permission.ProjectMember,
Permission.CanEditIncidentState,
],
})
@TableColumn({
required: true,
type: TableColumnType.ShortText,
canReadOnRelationQuery: true,
title: 'Name',
description: 'Any friendly name of this object',
})
@Column({
nullable: false,
type: ColumnType.ShortText,
length: ColumnLength.ShortText,
})
@UniqueColumnBy('projectId')
public name?: string = undefined;
@ColumnAccessControl({
create: [],
read: [
Permission.ProjectOwner,
Permission.ProjectAdmin,
Permission.ProjectMember,
Permission.CanReadIncidentState,
],
update: [],
})
@TableColumn({
required: true,
unique: true,
type: TableColumnType.Slug,
title: 'Slug',
description: 'Friendly globally unique name for your object',
})
@Column({
nullable: false,
type: ColumnType.Slug,
length: ColumnLength.Slug,
})
public slug?: string = undefined;
@ColumnAccessControl({
create: [
Permission.ProjectOwner,
Permission.ProjectAdmin,
Permission.ProjectMember,
Permission.CanCreateIncidentState,
],
read: [
Permission.ProjectOwner,
Permission.ProjectAdmin,
Permission.ProjectMember,
Permission.CanReadIncidentState,
],
update: [
Permission.ProjectOwner,
Permission.ProjectAdmin,
Permission.ProjectMember,
Permission.CanEditIncidentState,
],
})
@TableColumn({
required: false,
type: TableColumnType.LongText,
title: 'Description',
description: 'Friendly description that will help you remember',
})
@Column({
nullable: true,
type: ColumnType.LongText,
length: ColumnLength.LongText,
})
public description?: string = undefined;
@ColumnAccessControl({
create: [
Permission.ProjectOwner,
Permission.ProjectAdmin,
Permission.ProjectMember,
Permission.CanCreateIncidentState,
],
read: [
Permission.ProjectOwner,
Permission.ProjectAdmin,
Permission.ProjectMember,
Permission.CanReadIncidentState,
],
update: [],
})
@TableColumn({
manyToOneRelationColumn: 'createdByUserId',
type: TableColumnType.Entity,
modelType: User,
title: 'Created by User',
description:
'Relation to User who created this object (if this object was created by a User)',
})
@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.ProjectAdmin,
Permission.ProjectMember,
Permission.CanCreateIncidentState,
],
read: [
Permission.ProjectOwner,
Permission.ProjectAdmin,
Permission.ProjectMember,
Permission.CanReadIncidentState,
],
update: [],
})
@TableColumn({
type: TableColumnType.ObjectID,
title: 'Created by User ID',
description:
'User ID who created this object (if this object was created by a User)',
})
@Column({
type: ColumnType.ObjectID,
nullable: true,
transformer: ObjectID.getDatabaseTransformer(),
})
public createdByUserId?: ObjectID = undefined;
@ColumnAccessControl({
create: [],
read: [
Permission.ProjectOwner,
Permission.ProjectAdmin,
Permission.ProjectMember,
Permission.CanReadIncidentState,
],
update: [],
})
@TableColumn({
manyToOneRelationColumn: 'deletedByUserId',
type: TableColumnType.Entity,
title: 'Deleted by User',
description:
'Relation to User who deleted this object (if this object was deleted by a User)',
})
@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.ProjectOwner,
Permission.ProjectAdmin,
Permission.ProjectMember,
Permission.CanReadIncidentState,
],
update: [],
})
@TableColumn({
type: TableColumnType.ObjectID,
title: 'Deleted by User ID',
description:
'User ID who deleted this object (if this object was deleted by a User)',
})
@Column({
type: ColumnType.ObjectID,
nullable: true,
transformer: ObjectID.getDatabaseTransformer(),
})
public deletedByUserId?: ObjectID = undefined;
@ColumnAccessControl({
create: [
Permission.ProjectOwner,
Permission.ProjectAdmin,
Permission.ProjectMember,
Permission.CanCreateIncidentState,
],
read: [
Permission.ProjectOwner,
Permission.ProjectAdmin,
Permission.ProjectMember,
Permission.CanReadIncidentState,
],
update: [
Permission.ProjectOwner,
Permission.ProjectAdmin,
Permission.ProjectMember,
Permission.CanEditIncidentState,
],
})
@TableColumn({
title: 'Color',
required: true,
unique: false,
type: TableColumnType.Color,
canReadOnRelationQuery: true,
description: 'Color of this resource in Hex (#32a852 for example)',
})
@Column({
type: ColumnType.Color,
length: ColumnLength.Color,
unique: false,
nullable: false,
transformer: Color.getDatabaseTransformer(),
})
public color?: Color = undefined;
@ColumnAccessControl({
create: [
Permission.ProjectOwner,
Permission.ProjectAdmin,
Permission.ProjectMember,
Permission.CanCreateIncidentState,
],
read: [
Permission.ProjectOwner,
Permission.ProjectAdmin,
Permission.ProjectMember,
Permission.CanReadIncidentState,
],
update: [
Permission.ProjectOwner,
Permission.ProjectAdmin,
Permission.ProjectMember,
Permission.CanEditIncidentState,
],
})
@TableColumn({
isDefaultValueColumn: false,
type: TableColumnType.Boolean,
canReadOnRelationQuery: true,
title: 'Is Created State',
description: 'Is it the created state of the incident?',
})
@Column({
type: ColumnType.Boolean,
default: false,
})
public isCreatedState?: boolean = undefined;
@ColumnAccessControl({
create: [
Permission.ProjectOwner,
Permission.ProjectAdmin,
Permission.ProjectMember,
Permission.CanCreateIncidentState,
],
read: [
Permission.ProjectOwner,
Permission.ProjectAdmin,
Permission.ProjectMember,
Permission.CanReadIncidentState,
],
update: [
Permission.ProjectOwner,
Permission.ProjectAdmin,
Permission.ProjectMember,
Permission.CanEditIncidentState,
],
})
@TableColumn({
isDefaultValueColumn: false,
type: TableColumnType.Boolean,
canReadOnRelationQuery: true,
title: 'Is Acknowledged State',
description: 'Is it the acknowledged state of the incident?',
})
@Column({
type: ColumnType.Boolean,
default: false,
})
public isAcknowledgedState?: boolean = undefined;
@ColumnAccessControl({
create: [
Permission.ProjectOwner,
Permission.ProjectAdmin,
Permission.ProjectMember,
Permission.CanCreateIncidentState,
],
read: [
Permission.ProjectOwner,
Permission.ProjectAdmin,
Permission.ProjectMember,
Permission.CanReadIncidentState,
],
update: [
Permission.ProjectOwner,
Permission.ProjectAdmin,
Permission.ProjectMember,
Permission.CanEditIncidentState,
],
})
@TableColumn({
isDefaultValueColumn: false,
type: TableColumnType.Boolean,
canReadOnRelationQuery: true,
title: 'Is Resolved State',
description: 'Is it the resolved state of the incident?',
})
@Column({
type: ColumnType.Boolean,
default: false,
})
public isResolvedState?: boolean = undefined;
@UniqueColumnBy('projectId')
@ColumnAccessControl({
create: [
Permission.ProjectOwner,
Permission.ProjectAdmin,
Permission.ProjectMember,
Permission.CanCreateIncidentState,
],
read: [
Permission.ProjectOwner,
Permission.ProjectAdmin,
Permission.ProjectMember,
Permission.CanReadIncidentState,
],
update: [
Permission.ProjectOwner,
Permission.ProjectAdmin,
Permission.ProjectMember,
Permission.CanEditIncidentState,
],
})
@TableColumn({
isDefaultValueColumn: false,
type: TableColumnType.SmallNumber,
canReadOnRelationQuery: true,
title: 'Order',
description: 'Order / Priority of this resource',
})
@Column({
type: ColumnType.SmallNumber,
})
public order?: number = undefined;
}