From 15fb76445bae9cb1241a5ad1bd84ae8f2a05c448 Mon Sep 17 00:00:00 2001 From: Hellgren Heikki Date: Tue, 28 Oct 2025 10:01:38 +0200 Subject: [PATCH] fix(notifications): show default settings before first notification this fixes default notification configuration not showing in the notification settings before user has received first notification from the specific origin/topic Signed-off-by: Hellgren Heikki --- .changeset/fast-tools-mate.md | 10 +++++ .../src/service/router.test.ts | 40 +++++++++++++++++++ .../src/service/router.ts | 21 ++++++++++ 3 files changed, 71 insertions(+) create mode 100644 .changeset/fast-tools-mate.md diff --git a/.changeset/fast-tools-mate.md b/.changeset/fast-tools-mate.md new file mode 100644 index 0000000000..2e212ce1b3 --- /dev/null +++ b/.changeset/fast-tools-mate.md @@ -0,0 +1,10 @@ +--- +'@backstage/plugin-notifications-backend': patch +--- + +Show default settings for notifications even before receiving first notification. + +Previously, it was not possible for the users to see or modify their notification settings until they had received at +least one notification from specific origin or topic. +This update ensures that default settings are displayed from the outset, +allowing users to customize their preferences immediately. diff --git a/plugins/notifications-backend/src/service/router.test.ts b/plugins/notifications-backend/src/service/router.test.ts index f42a7b4513..3f71377151 100644 --- a/plugins/notifications-backend/src/service/router.test.ts +++ b/plugins/notifications-backend/src/service/router.test.ts @@ -68,6 +68,16 @@ describe.each(databases.eachSupportedId())('createRouter (%s)', databaseId => { id: 'external:test-service2', enabled: false, }, + { + id: 'external:test-service3', + enabled: true, + topics: [ + { + id: 'test-topic3', + enabled: false, + }, + ], + }, ], }, ], @@ -829,6 +839,16 @@ describe.each(databases.eachSupportedId())('createRouter (%s)', databaseId => { id: 'external:test-service2', topics: [{ enabled: false, id: 'test-topic2' }], }, + { + enabled: true, + id: 'external:test-service3', + topics: [ + { + enabled: false, + id: 'test-topic3', + }, + ], + }, ]), }, ], @@ -863,6 +883,16 @@ describe.each(databases.eachSupportedId())('createRouter (%s)', databaseId => { id: 'external:test-service2', topics: [{ enabled: false, id: 'test-topic2' }], }, + { + enabled: true, + id: 'external:test-service3', + topics: [ + { + enabled: false, + id: 'test-topic3', + }, + ], + }, ]), }, ], @@ -887,6 +917,16 @@ describe.each(databases.eachSupportedId())('createRouter (%s)', databaseId => { id: 'external:test-service2', topics: [{ enabled: false, id: 'test-topic2' }], }, + { + enabled: true, + id: 'external:test-service3', + topics: [ + { + enabled: false, + id: 'test-topic3', + }, + ], + }, ]), }, ], diff --git a/plugins/notifications-backend/src/service/router.ts b/plugins/notifications-backend/src/service/router.ts index 027d6a1732..77f2685ebf 100644 --- a/plugins/notifications-backend/src/service/router.ts +++ b/plugins/notifications-backend/src/service/router.ts @@ -207,6 +207,27 @@ export async function createRouter( const settings = await store.getNotificationSettings({ user }); const channels = getNotificationChannels(); + // Merge existing channels/origins/topics with configured settings + for (const channel of defaultNotificationSettings?.channels ?? []) { + if (!channels.includes(channel.id)) { + channels.push(channel.id); + } + + for (const origin of channel.origins) { + if (!origins.includes(origin.id)) { + origins.push(origin.id); + } + + for (const topic of origin.topics ?? []) { + if ( + !topics.some(t => t.origin === origin.id && t.topic === topic.id) + ) { + topics.push({ origin: origin.id, topic: topic.id }); + } + } + } + } + return { channels: channels.map(channelId => getChannelSettings(channelId, settings, origins, topics),