Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 34 additions & 21 deletions Common/Server/Utils/Monitor/MonitorStepsProjectValidator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,29 +151,42 @@ export default class MonitorStepsProjectValidator {
return;
}

const projectScopedReferences: Array<ProjectScopedReference> = [];

for (const reference of introduced) {
const service: DatabaseService<DatabaseBaseModel> | undefined =
SERVICE_BY_MODEL[reference.model];

if (!service) {
continue;
}

projectScopedReferences.push({
/*
* The path — `criteria "Monitor is offline" incident severity` —
* rather than the bare model name, so the message points at the
* field to fix. monitorSteps can hold a dozen of these.
*/
modelName: `${reference.model} (${reference.path})`,
id: reference.id,
service: service,
/*
* Only ids the monitor actually reads at run time are required to
* exist — see MonitorStepsReference.isOperative. The rest are still
* checked for belonging to this project.
*/
mustExist: reference.isOperative,
});
}

if (projectScopedReferences.length === 0) {
return;
}

await ProjectScopedReferenceValidator.validateReferencesBelongToProject({
projectId: data.projectId,
subject: "monitor's criteria",
references: introduced.map(
(reference: MonitorStepsReference): ProjectScopedReference => {
return {
/*
* The path — `criteria "Monitor is offline" incident severity` —
* rather than the bare model name, so the message points at the
* field to fix. monitorSteps can hold a dozen of these.
*/
modelName: `${reference.model} (${reference.path})`,
id: reference.id,
service: SERVICE_BY_MODEL[reference.model],
/*
* Only ids the monitor actually reads at run time are required to
* exist — see MonitorStepsReference.isOperative. The rest are still
* checked for belonging to this project.
*/
mustExist: reference.isOperative,
};
},
),
references: projectScopedReferences,
});
}
}
}
Loading