Allows for a opt-in strategy for notifications rather than opt-out.

Signed-off-by: Henrik Edegård <henrik.edegard@fortnox.se>
This commit is contained in:
Henrik Edegård
2025-10-01 09:10:45 +00:00
parent 7a26c0947e
commit 87e597c406
8 changed files with 476 additions and 13 deletions
@@ -9,6 +9,7 @@ import { JsonValue } from '@backstage/types';
// @public (undocumented)
export type ChannelSetting = {
id: string;
enabled?: boolean;
origins: OriginSetting[];
};
@@ -154,6 +154,12 @@ export type OriginSetting = {
*/
export type ChannelSetting = {
id: string;
/**
* Optional flag to enable/disable the channel by default.
* If not set, defaults to true for backwards compatibility.
* When set to false, the channel uses an opt-in strategy.
*/
enabled?: boolean;
origins: OriginSetting[];
};
+13 -7
View File
@@ -29,14 +29,20 @@ export const isNotificationsEnabledFor = (
const origin = channel.origins.find(o => o.id === originId);
if (!origin) {
return true;
// If no origin is found, use channel's enabled flag (defaults to true if not set)
return channel.enabled ?? true;
}
if (topicId === null) {
// If topic is specified, check topic-level setting
if (topicId !== null) {
const topic = origin.topics?.find(t => t.id === topicId);
if (topic) {
return topic.enabled;
}
// No explicit topic setting, check origin
return origin.enabled;
}
const topic = origin.topics?.find(t => t.id === topicId);
if (!topic) {
return origin.enabled;
}
return topic.enabled;
// No topic specified, check origin-level setting
return origin.enabled;
};