mirror of
https://github.com/OneUptime/oneuptime
synced 2024-11-23 07:42:10 +00:00
458 lines
14 KiB
TypeScript
458 lines
14 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/Model/EnableWorkflow';
|
|
import IconProp from 'Common/Types/Icon/IconProp';
|
|
import EnableDocumentation from 'Common/Types/Model/EnableDocumentation';
|
|
|
|
@EnableDocumentation()
|
|
@TenantColumn('projectId')
|
|
@TableAccessControl({
|
|
create: [
|
|
Permission.ProjectOwner,
|
|
Permission.ProjectAdmin,
|
|
Permission.ProjectMember,
|
|
Permission.CanCreateProjectMonitorStatus,
|
|
],
|
|
read: [
|
|
Permission.ProjectOwner,
|
|
Permission.ProjectAdmin,
|
|
Permission.ProjectMember,
|
|
Permission.CanReadProjectMonitorStatus,
|
|
],
|
|
delete: [
|
|
Permission.ProjectOwner,
|
|
Permission.ProjectAdmin,
|
|
Permission.ProjectMember,
|
|
Permission.CanDeleteProjectMonitorStatus,
|
|
],
|
|
update: [
|
|
Permission.ProjectOwner,
|
|
Permission.ProjectAdmin,
|
|
Permission.ProjectMember,
|
|
Permission.CanEditProjectMonitorStatus,
|
|
],
|
|
})
|
|
@EnableWorkflow({
|
|
create: true,
|
|
delete: true,
|
|
update: true,
|
|
read: true,
|
|
})
|
|
@CrudApiEndpoint(new Route('/monitor-status'))
|
|
@SlugifyColumn('name', 'slug')
|
|
@TableMetadata({
|
|
tableName: 'MonitorStatus',
|
|
singularName: 'Monitor Status',
|
|
pluralName: 'Monitor Statuses',
|
|
icon: IconProp.AltGlobe,
|
|
tableDescription:
|
|
'Manage monitor status in your project. Monitor Status are Operational, Degraded and Offline for example. Add custom status like Monitoring or more.',
|
|
})
|
|
@Entity({
|
|
name: 'MonitorStatus',
|
|
})
|
|
export default class MonitorStatus extends BaseModel {
|
|
@ColumnAccessControl({
|
|
create: [
|
|
Permission.ProjectOwner,
|
|
Permission.ProjectAdmin,
|
|
Permission.ProjectMember,
|
|
Permission.CanCreateProjectMonitorStatus,
|
|
],
|
|
read: [
|
|
Permission.ProjectOwner,
|
|
Permission.ProjectAdmin,
|
|
Permission.ProjectMember,
|
|
Permission.CanReadProjectMonitorStatus,
|
|
],
|
|
update: [],
|
|
})
|
|
@TableColumn({
|
|
manyToOneRelationColumn: 'projectId',
|
|
type: TableColumnType.Entity,
|
|
modelType: Project,
|
|
title: "Project",
|
|
description: "Relation to Project Resource"
|
|
})
|
|
@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.CanCreateProjectMonitorStatus,
|
|
],
|
|
read: [
|
|
Permission.ProjectOwner,
|
|
Permission.ProjectAdmin,
|
|
Permission.ProjectMember,
|
|
Permission.CanReadProjectMonitorStatus,
|
|
],
|
|
update: [],
|
|
})
|
|
@Index()
|
|
@TableColumn({
|
|
type: TableColumnType.ObjectID,
|
|
required: true,
|
|
canReadOnPopulate: true,
|
|
title: "Project ID",
|
|
description: "ID of your OneUptime Project"
|
|
})
|
|
@Column({
|
|
type: ColumnType.ObjectID,
|
|
nullable: false,
|
|
transformer: ObjectID.getDatabaseTransformer(),
|
|
})
|
|
public projectId?: ObjectID = undefined;
|
|
|
|
@ColumnAccessControl({
|
|
create: [
|
|
Permission.ProjectOwner,
|
|
Permission.ProjectAdmin,
|
|
Permission.ProjectMember,
|
|
Permission.CanCreateProjectMonitorStatus,
|
|
],
|
|
read: [
|
|
Permission.ProjectOwner,
|
|
Permission.ProjectAdmin,
|
|
Permission.ProjectMember,
|
|
Permission.CanReadProjectMonitorStatus,
|
|
],
|
|
update: [
|
|
Permission.ProjectOwner,
|
|
Permission.ProjectAdmin,
|
|
Permission.ProjectMember,
|
|
Permission.CanEditProjectMonitorStatus,
|
|
],
|
|
})
|
|
@TableColumn({
|
|
required: true,
|
|
type: TableColumnType.ShortText,
|
|
canReadOnPopulate: true,
|
|
})
|
|
@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.CanReadProjectMonitorStatus,
|
|
],
|
|
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.CanCreateProjectMonitorStatus,
|
|
],
|
|
read: [
|
|
Permission.ProjectOwner,
|
|
Permission.ProjectAdmin,
|
|
Permission.ProjectMember,
|
|
Permission.CanReadProjectMonitorStatus,
|
|
],
|
|
update: [
|
|
Permission.ProjectOwner,
|
|
Permission.ProjectAdmin,
|
|
Permission.ProjectMember,
|
|
Permission.CanEditProjectMonitorStatus,
|
|
],
|
|
})
|
|
@TableColumn({ required: false, type: TableColumnType.LongText, title: "Description", description: "Any friendly description of this object" })
|
|
@Column({
|
|
nullable: true,
|
|
type: ColumnType.LongText,
|
|
length: ColumnLength.LongText,
|
|
})
|
|
public description?: string = undefined;
|
|
|
|
@ColumnAccessControl({
|
|
create: [
|
|
Permission.ProjectOwner,
|
|
Permission.ProjectAdmin,
|
|
Permission.ProjectMember,
|
|
Permission.CanCreateProjectMonitorStatus,
|
|
],
|
|
read: [
|
|
Permission.ProjectOwner,
|
|
Permission.ProjectAdmin,
|
|
Permission.ProjectMember,
|
|
Permission.CanReadProjectMonitorStatus,
|
|
],
|
|
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.CanCreateProjectMonitorStatus,
|
|
],
|
|
read: [
|
|
Permission.ProjectOwner,
|
|
Permission.ProjectAdmin,
|
|
Permission.ProjectMember,
|
|
Permission.CanReadProjectMonitorStatus,
|
|
],
|
|
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.CanReadProjectMonitorStatus,
|
|
],
|
|
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.CanReadProjectMonitorStatus,
|
|
],
|
|
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.CanCreateProjectMonitorStatus,
|
|
],
|
|
read: [
|
|
Permission.ProjectOwner,
|
|
Permission.ProjectAdmin,
|
|
Permission.ProjectMember,
|
|
Permission.CanReadProjectMonitorStatus,
|
|
],
|
|
update: [
|
|
Permission.ProjectOwner,
|
|
Permission.ProjectAdmin,
|
|
Permission.ProjectMember,
|
|
Permission.CanEditProjectMonitorStatus,
|
|
],
|
|
})
|
|
@TableColumn({
|
|
title: 'Color',
|
|
required: true,
|
|
unique: false,
|
|
type: TableColumnType.Color,
|
|
canReadOnPopulate: true,
|
|
})
|
|
@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.CanCreateProjectMonitorStatus,
|
|
],
|
|
read: [
|
|
Permission.ProjectOwner,
|
|
Permission.ProjectAdmin,
|
|
Permission.ProjectMember,
|
|
Permission.CanReadProjectMonitorStatus,
|
|
],
|
|
update: [
|
|
Permission.ProjectOwner,
|
|
Permission.ProjectAdmin,
|
|
Permission.ProjectMember,
|
|
Permission.CanEditProjectMonitorStatus,
|
|
],
|
|
})
|
|
@TableColumn({
|
|
isDefaultValueColumn: true,
|
|
type: TableColumnType.Boolean,
|
|
canReadOnPopulate: true,
|
|
})
|
|
@Column({
|
|
type: ColumnType.Boolean,
|
|
default: false,
|
|
})
|
|
public isOperationalState?: boolean = undefined;
|
|
|
|
@ColumnAccessControl({
|
|
create: [
|
|
Permission.ProjectOwner,
|
|
Permission.ProjectAdmin,
|
|
Permission.ProjectMember,
|
|
Permission.CanCreateProjectMonitorStatus,
|
|
],
|
|
read: [
|
|
Permission.ProjectOwner,
|
|
Permission.ProjectAdmin,
|
|
Permission.ProjectMember,
|
|
Permission.CanReadProjectMonitorStatus,
|
|
],
|
|
update: [
|
|
Permission.ProjectOwner,
|
|
Permission.ProjectAdmin,
|
|
Permission.ProjectMember,
|
|
Permission.CanEditProjectMonitorStatus,
|
|
],
|
|
})
|
|
@TableColumn({
|
|
isDefaultValueColumn: true,
|
|
type: TableColumnType.Boolean,
|
|
canReadOnPopulate: true,
|
|
})
|
|
@Column({
|
|
type: ColumnType.Boolean,
|
|
default: false,
|
|
})
|
|
public isOfflineState?: boolean = undefined;
|
|
|
|
@ColumnAccessControl({
|
|
create: [
|
|
Permission.ProjectOwner,
|
|
Permission.ProjectAdmin,
|
|
Permission.ProjectMember,
|
|
Permission.CanCreateProjectMonitorStatus,
|
|
],
|
|
read: [
|
|
Permission.ProjectOwner,
|
|
Permission.ProjectAdmin,
|
|
Permission.ProjectMember,
|
|
Permission.CanReadProjectMonitorStatus,
|
|
],
|
|
update: [
|
|
Permission.ProjectOwner,
|
|
Permission.ProjectAdmin,
|
|
Permission.ProjectMember,
|
|
Permission.CanEditProjectMonitorStatus,
|
|
],
|
|
})
|
|
@TableColumn({
|
|
isDefaultValueColumn: false,
|
|
type: TableColumnType.Number,
|
|
canReadOnPopulate: true,
|
|
})
|
|
@Column({
|
|
type: ColumnType.Number,
|
|
})
|
|
public priority?: number = undefined;
|
|
}
|