Skip to content

Commit d9917e3

Browse files
committed
Add deprecated group to reason options to allow old reasons to be slowly moved away from
1 parent 8ee19c1 commit d9917e3

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

src/components/progress-report/variance-explanation/reason-options.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { Field, ObjectType } from '@nestjs/graphql';
2+
import { stripIndent } from 'common-tags';
23
import { LazyGetter as Once } from 'lazy-get-decorator';
34
import { DataObject, JsonSet } from '~/common';
45

@@ -14,6 +15,16 @@ export class ProgressReportVarianceExplanationReasonOptions extends DataObject {
1415
return new JsonSet([...this.behind, ...this.onTime, ...this.ahead]);
1516
}
1617

18+
@Field(() => [String], {
19+
description: stripIndent`
20+
A list of deprecated options.
21+
If an option is deprecated, it is not available for selection/saving.
22+
This allows rendering old options while enforcing a soft migration
23+
to new values.
24+
`,
25+
})
26+
readonly deprecated: ReadonlySet<string> = new JsonSet([]);
27+
1728
@Field(() => [String])
1829
readonly behind: ReadonlySet<string> = new JsonSet([
1930
'Delayed activities; activities did not occur; slow start of project',

src/components/progress-report/variance-explanation/variance-explanation.service.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
import { Injectable } from '@nestjs/common';
2-
import { mapFromList, NotFoundException, Session } from '~/common';
2+
import {
3+
InputException,
4+
mapFromList,
5+
NotFoundException,
6+
Session,
7+
} from '~/common';
38
import { ResourceLoader } from '~/core';
49
import { Privileges } from '../../authorization';
510
import { ProgressReport } from '../dto';
11+
import { ProgressReportVarianceExplanationReasonOptions as ReasonOptions } from './reason-options';
612
import {
713
ProgressReportVarianceExplanation as VarianceExplanation,
814
ProgressReportVarianceExplanationInput as VarianceExplanationInput,
@@ -50,6 +56,18 @@ export class ProgressReportVarianceExplanationService {
5056
return report;
5157
}
5258

59+
// Don't allow changing to a deprecated reason.
60+
// Here to be nice and allow updating the comments even if the current
61+
// reason is deprecated.
62+
if (
63+
changes.reasons?.some((r) => ReasonOptions.instance.deprecated.has(r))
64+
) {
65+
throw new InputException(
66+
'Reason is deprecated and cannot be used',
67+
'reasons',
68+
);
69+
}
70+
5371
this.privilegesFor(session, report).verifyChanges(changes);
5472

5573
await this.repo.update(report.id, changes, session);

0 commit comments

Comments
 (0)