Skip to content

Commit 04fd4c2

Browse files
committed
Re-introduce config/env flag for project transition email notifications
This time it is just the default preferences, users can override.
1 parent 3c50d4e commit 04fd4c2

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

src/components/project/workflow/notifications/project-transition-notification.strategy.tsx

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,45 @@
1+
import { Injectable } from '@nestjs/common';
12
import { node, type Query, relation } from 'cypher-query-builder';
23
import { type AbstractClass } from 'type-fest';
34
import { EnhancedResource } from '~/common';
5+
import { ConfigService } from '~/core/config';
46
import { EmailMessage } from '~/core/email';
57
import { e } from '~/core/gel';
68
import { createRelationships, exp } from '~/core/neo4j/query';
7-
import { INotificationStrategy, type InputOf } from '../../../notifications';
9+
import {
10+
type ChannelAvailabilities,
11+
INotificationStrategy,
12+
type InputOf,
13+
} from '../../../notifications';
814
import { ProjectStepChangedNotification } from '../emails/project-step-changed-notification.email';
915
import { type ProjectTransitionNotification } from './project-transition-notification.dto';
10-
import type { ProjectTransitionViaMembershipNotification } from './project-transition-via-membership-notification.dto';
16+
import { type ProjectTransitionViaMembershipNotification } from './project-transition-via-membership-notification.dto';
1117

1218
/**
1319
* Shared input type for all ProjectTransition notification strategies.
1420
* Both concrete DTOs have the same extra fields (workflowEvent + previousStep).
1521
*/
1622
export type ProjectTransitionInput = InputOf<ProjectTransitionNotification>;
1723

24+
@Injectable()
1825
export abstract class ProjectTransitionNotificationStrategy<
1926
T extends ProjectTransitionViaMembershipNotification,
2027
> extends INotificationStrategy<T, ProjectTransitionInput> {
2128
protected abstract readonly dtoClass: AbstractClass<T>;
2229

30+
constructor(protected config: ConfigService) {
31+
super();
32+
}
33+
34+
override channelAvailabilities(): ChannelAvailabilities {
35+
return {
36+
...super.channelAvailabilities(),
37+
Email: this.config.email.notifyProjectStepChanges
38+
? 'DefaultOn'
39+
: 'DefaultOff',
40+
};
41+
}
42+
2343
saveForNeo4j({ previousStep, workflowEvent }: ProjectTransitionInput) {
2444
return (query: Query) =>
2545
query

src/core/config/config.service.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,10 @@ export const makeConfig = (env: EnvironmentService) =>
131131
notifyDistributionLists: env
132132
.boolean('NOTIFY_DISTRIBUTION_LIST')
133133
.optional(false),
134+
/**
135+
* Whether email notifications should be default on or off
136+
* for project workflow event notifications.
137+
*/
134138
notifyProjectStepChanges: env
135139
.boolean('NOTIFY_PROJECT_STEP_CHANGES')
136140
.optional(true),

0 commit comments

Comments
 (0)