From 3f1550096c1df9c4a0b1f8b6d8cbf832def6ed97 Mon Sep 17 00:00:00 2001 From: Simon Larsen Date: Sun, 9 Jul 2023 15:11:01 +0100 Subject: [PATCH] fix sso docs --- .vscode/launch.json | 14 +++ ApiReference/Service/Model.ts | 2 + Common/Types/Permission.ts | 8 ++ .../Services/UserNotificationLogService.ts | 96 ++++++++++++++++++- Model/Models/StatusPageSso.ts | 7 -- Workers/Index.ts | 4 +- .../HardDelete/HardDeleteItemsInDatabase.ts | 7 ++ 7 files changed, 127 insertions(+), 11 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index 6a87a90bab..65e8d2aa8c 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -41,6 +41,20 @@ "restart": true, "autoAttachChildProcesses": true }, + { + "address": "127.0.0.1", + "localRoot": "${workspaceFolder}/ApiReference", + "name": "API Reference: Debug with Docker", + "port": 9178, + "remoteRoot": "/usr/src/app", + "request": "attach", + "skipFiles": [ + "/**" + ], + "type": "node", + "restart": true, + "autoAttachChildProcesses": true + }, { "address": "127.0.0.1", "localRoot": "${workspaceFolder}/LinkShortner", diff --git a/ApiReference/Service/Model.ts b/ApiReference/Service/Model.ts index d44cf541b8..30127d5332 100644 --- a/ApiReference/Service/Model.ts +++ b/ApiReference/Service/Model.ts @@ -47,6 +47,8 @@ export default class ServiceHandler { page = 'model'; + debugger; + const tableColumns: any = getTableColumns(currentResource.model); for (const key in tableColumns) { diff --git a/Common/Types/Permission.ts b/Common/Types/Permission.ts index adaf473086..c9f4f92d85 100644 --- a/Common/Types/Permission.ts +++ b/Common/Types/Permission.ts @@ -500,6 +500,14 @@ export class PermissionHelper { isAssignableToTenant: true, isAccessControlPermission: false, }, + { + permission: Permission.ProjectUser, + title: 'Project User', + description: + 'User of this project.', + isAssignableToTenant: true, + isAccessControlPermission: false, + }, { permission: Permission.CurrentUser, title: 'Logged in User', diff --git a/CommonServer/Services/UserNotificationLogService.ts b/CommonServer/Services/UserNotificationLogService.ts index 6d11436aee..543fb88e1b 100644 --- a/CommonServer/Services/UserNotificationLogService.ts +++ b/CommonServer/Services/UserNotificationLogService.ts @@ -1,6 +1,6 @@ import PostgresDatabase from '../Infrastructure/PostgresDatabase'; import Model from 'Model/Models/UserNotificationLog'; -import DatabaseService, { OnCreate } from './DatabaseService'; +import DatabaseService, { OnCreate, OnUpdate } from './DatabaseService'; import UserNotificationRule from 'Model/Models/UserNotificationRule'; import UserNotificationRuleService from './UserNotificationRuleService'; import { LIMIT_PER_PROJECT } from 'Common/Types/Database/LimitMax'; @@ -9,9 +9,12 @@ import UserNotificationEventType from 'Common/Types/UserNotification/UserNotific import BadDataException from 'Common/Types/Exception/BadDataException'; import CreateBy from '../Types/Database/CreateBy'; import UserNotificationExecutionStatus from 'Common/Types/UserNotification/UserNotificationExecutionStatus'; -import IncidentSeverity from 'Model/Models/IncidentSeverity'; import IncidentService from './IncidentService'; import Incident from 'Model/Models/Incident'; +import PositiveNumber from 'Common/Types/PositiveNumber'; +import ObjectID from 'Common/Types/ObjectID'; +import OnCallDutyPolicyExecutionLogTimelineService from './OnCallDutyPolicyExecutionLogTimelineService'; +import OnCallDutyExecutionLogTimelineStatus from 'Common/Types/OnCallDutyPolicy/OnCalDutyExecutionLogTimelineStatus'; export class Service extends DatabaseService { public constructor(postgresDatabase?: PostgresDatabase) { @@ -29,6 +32,62 @@ export class Service extends DatabaseService { }; } + protected override async onUpdateSuccess(onUpdate: OnUpdate, _updatedItemIds: ObjectID[]): Promise> { + if (onUpdate.updateBy.data.status) { + //update the correspomnding oncallTimeline. + const items = await this.findBy({ + query: onUpdate.updateBy.query, + select: { + onCallDutyPolicyExecutionLogTimelineId: true, + }, + skip: 0, + limit: LIMIT_PER_PROJECT, + props: { + isRoot: true, + }, + }); + + let status: OnCallDutyExecutionLogTimelineStatus | undefined = undefined; + + switch (onUpdate.updateBy.data.status) { + case UserNotificationExecutionStatus.Completed: + status = OnCallDutyExecutionLogTimelineStatus.NotificationSent; + break; + case UserNotificationExecutionStatus.Error: + status = OnCallDutyExecutionLogTimelineStatus.Error; + break; + case UserNotificationExecutionStatus.Running: + status = OnCallDutyExecutionLogTimelineStatus.Running; + break; + case UserNotificationExecutionStatus.Scheduled: + status = OnCallDutyExecutionLogTimelineStatus.Started; + break; + case UserNotificationExecutionStatus.Started: + status = OnCallDutyExecutionLogTimelineStatus.Started; + break; + default: + throw new BadDataException('Invalid status'); + } + + + for (const item of items) { + await OnCallDutyPolicyExecutionLogTimelineService.updateOneById({ + id: item.onCallDutyPolicyExecutionLogTimelineId!, + data: { + status: status!, + statusMessage: onUpdate.updateBy.data.statusMessage!, + }, + props: { + isRoot: true, + }, + }); + } + + } + + return onUpdate; + } + protected override async onCreateSuccess( _onCreate: OnCreate, createdItem: Model @@ -60,6 +119,39 @@ export class Service extends DatabaseService { }); + // Check if there are any rules . + const ruleCount: PositiveNumber = await UserNotificationRuleService.countBy({ + query: { + userId: createdItem.userId!, + projectId: createdItem.projectId!, + ruleType: notificationRuleType, + incidentSeverityId: incident?.incidentSeverityId!, + }, + skip: 0, + limit: LIMIT_PER_PROJECT, + props: { + isRoot: true, + }, + }); + + if (ruleCount.toNumber() === 0) { + // update this item to be processed. + await this.updateOneById({ + id: createdItem.id!, + data: { + status: UserNotificationExecutionStatus.Error, // now the worker will pick this up and complete this or mark this as failed. + statusMessage: 'No notification rules found.' + }, + props: { + isRoot: true, + }, + }); + + + return createdItem; + } + + // find immediate notification rule and alert the user. const immediateNotificationRule: Array = diff --git a/Model/Models/StatusPageSso.ts b/Model/Models/StatusPageSso.ts index 40cfc43f6e..e053307280 100644 --- a/Model/Models/StatusPageSso.ts +++ b/Model/Models/StatusPageSso.ts @@ -45,7 +45,6 @@ import EnableDocumentation from 'Common/Types/Model/EnableDocumentation'; Permission.ProjectUser, Permission.Public, Permission.ProjectAdmin, - Permission.ProjectUser, Permission.CanReadStatusPageSSO, ], delete: [ @@ -82,8 +81,6 @@ export default class StatusPageSSO extends BaseModel { Permission.ProjectAdmin, Permission.ProjectUser, Permission.Public, - Permission.ProjectUser, - Permission.Public, Permission.CanReadStatusPageSSO, ], update: [], @@ -122,8 +119,6 @@ export default class StatusPageSSO extends BaseModel { Permission.ProjectUser, Permission.Public, Permission.CanReadStatusPageSSO, - Permission.ProjectUser, - Permission.Public, ], update: [], }) @@ -222,8 +217,6 @@ export default class StatusPageSSO extends BaseModel { Permission.ProjectUser, Permission.Public, Permission.CanReadStatusPageSSO, - Permission.ProjectUser, - Permission.Public, ], update: [ Permission.ProjectOwner, diff --git a/Workers/Index.ts b/Workers/Index.ts index 88587f8b86..3d4ab5b0bb 100644 --- a/Workers/Index.ts +++ b/Workers/Index.ts @@ -62,10 +62,10 @@ import './Jobs/StatusPageOwners/SendAnnouncementCreatedEmail'; import RunDatabaseMigrations from './Utils/DataMigration'; // On Call Duty Policy Executions. -import './Jobs/OnCallDutyPolicyExecution/ExecuteOnCallDutyPolicy'; +import './Jobs/OnCallDutyPolicyExecutionLog/ExecutePendingExecutions'; // User Notifications Log -import './Jobs/UserNotificationsLog/UpdateUserNotificationsLog'; +import './Jobs/UserNotificationLog/ExecutePendingExecutions'; const APP_NAME: string = 'workers'; diff --git a/Workers/Jobs/HardDelete/HardDeleteItemsInDatabase.ts b/Workers/Jobs/HardDelete/HardDeleteItemsInDatabase.ts index 96c2b09abe..b0145d78e9 100644 --- a/Workers/Jobs/HardDelete/HardDeleteItemsInDatabase.ts +++ b/Workers/Jobs/HardDelete/HardDeleteItemsInDatabase.ts @@ -7,6 +7,7 @@ import OneUptimeDate from 'Common/Types/Date'; import QueryHelper from 'CommonServer/Types/Database/QueryHelper'; import LIMIT_MAX from 'Common/Types/Database/LimitMax'; import logger from 'CommonServer/Utils/Logger'; +import { Service as BillingInvoiceServiceType } from 'CommonServer/Services/BillingInvoiceService'; RunCron( 'HardDelete:HardDeleteItemsInDatabase', @@ -14,6 +15,12 @@ RunCron( async () => { for (const service of Services) { if (service instanceof DatabaseService) { + + if (service instanceof BillingInvoiceServiceType) { + // skip invoice service because invoices should not be deleted. + continue; + } + try { // Retain data for 30 days for accidental deletion, and then hard delete. await service.hardDeleteBy({