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 <heikki.hellgren@op.fi>
This commit is contained in:
Hellgren Heikki
2025-10-28 10:01:38 +02:00
parent b78fc4541b
commit 15fb76445b
3 changed files with 71 additions and 0 deletions
+10
View File
@@ -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.
@@ -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',
},
],
},
]),
},
],
@@ -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),