From 1fb5f0602931a8a0552b0183c51df3cffed18fae Mon Sep 17 00:00:00 2001 From: Billy Stalnaker Date: Mon, 24 Mar 2025 16:30:56 -0400 Subject: [PATCH] wip; need to fix a test; and write more Signed-off-by: Billy Stalnaker --- .changeset/new-beers-sell.md | 8 +++++ .../migrations/20250317_addTopic.js | 4 +-- .../DatabaseNotificationsStore.test.ts | 1 + .../src/service/router.test.ts | 6 ++-- plugins/notifications-common/report.api.md | 31 ++++++++++++------- plugins/notifications/report.api.md | 1 + 6 files changed, 36 insertions(+), 15 deletions(-) create mode 100644 .changeset/new-beers-sell.md diff --git a/.changeset/new-beers-sell.md b/.changeset/new-beers-sell.md new file mode 100644 index 0000000000..fd7407007d --- /dev/null +++ b/.changeset/new-beers-sell.md @@ -0,0 +1,8 @@ +--- +'@backstage/plugin-scaffolder-backend-module-notifications': patch +'@backstage/plugin-notifications-backend': patch +'@backstage/plugin-notifications-common': patch +'@backstage/plugin-notifications': patch +--- + +Adds ability for user to turn on/off notifications for specific topics within an origin. diff --git a/plugins/notifications-backend/migrations/20250317_addTopic.js b/plugins/notifications-backend/migrations/20250317_addTopic.js index 7a7deed3d7..980e67f9dc 100644 --- a/plugins/notifications-backend/migrations/20250317_addTopic.js +++ b/plugins/notifications-backend/migrations/20250317_addTopic.js @@ -19,7 +19,7 @@ exports.up = async function up(knex) { }); await knex.schema.table('user_settings', table => { - table.dropUnique('user_settings_unique_idx'); + table.dropUnique([], 'user_settings_unique_idx'); }); await knex.schema.alterTable('user_settings', table => { @@ -31,7 +31,7 @@ exports.up = async function up(knex) { exports.down = async function down(knex) { await knex.schema.table('user_settings', table => { - table.dropUnique('user_settings_unique_idx'); + table.dropUnique([], 'user_settings_unique_idx'); }); await knex.schema.alterTable('user_settings', table => { diff --git a/plugins/notifications-backend/src/database/DatabaseNotificationsStore.test.ts b/plugins/notifications-backend/src/database/DatabaseNotificationsStore.test.ts index d0551cb777..81420211cb 100644 --- a/plugins/notifications-backend/src/database/DatabaseNotificationsStore.test.ts +++ b/plugins/notifications-backend/src/database/DatabaseNotificationsStore.test.ts @@ -159,6 +159,7 @@ const notificationSettings: NotificationSettings = { { id: 'plugin-test', enabled: true, + topics: [], }, { id: 'abcd-origin', diff --git a/plugins/notifications-backend/src/service/router.test.ts b/plugins/notifications-backend/src/service/router.test.ts index 46ee00c554..39844e8245 100644 --- a/plugins/notifications-backend/src/service/router.test.ts +++ b/plugins/notifications-backend/src/service/router.test.ts @@ -307,7 +307,7 @@ describe.each(databases.eachSupportedId())('createRouter (%s)', databaseId => { expect(notifications).toHaveLength(1); }); - it('should not send to user entity if disabled in settings', async () => { + it('should not send to user entity if origin is disabled in settings', async () => { const client = await database.getClient(); await client('user_settings').insert({ user: 'user:default/mock', @@ -502,7 +502,9 @@ describe.each(databases.eachSupportedId())('createRouter (%s)', databaseId => { channels: [ { id: 'Web', - origins: [{ enabled: false, id: 'external:test-service' }], + origins: [ + { enabled: false, id: 'external:test-service', topics: [] }, + ], }, ], }); diff --git a/plugins/notifications-common/report.api.md b/plugins/notifications-common/report.api.md index 0aeb49f71f..93889b206b 100644 --- a/plugins/notifications-common/report.api.md +++ b/plugins/notifications-common/report.api.md @@ -5,6 +5,12 @@ ```ts import { Config } from '@backstage/config'; +// @public (undocumented) +export type ChannelSetting = { + id: string; + origins: OriginSetting[]; +}; + // @public (undocumented) export const getProcessorFiltersFromConfig: ( config: Config, @@ -63,17 +69,7 @@ export type NotificationReadSignal = { // @public (undocumented) export type NotificationSettings = { - channels: { - id: string; - origins: { - id: string; - enabled: boolean; - topics?: { - id: string; - enabled: boolean; - }[]; - }[]; - }[]; + channels: ChannelSetting[]; }; // @public @@ -90,4 +86,17 @@ export type NotificationStatus = { unread: number; read: number; }; + +// @public (undocumented) +export type OriginSetting = { + id: string; + enabled: boolean; + topics?: TopicSetting[]; +}; + +// @public (undocumented) +export type TopicSetting = { + id: string; + enabled: boolean; +}; ``` diff --git a/plugins/notifications/report.api.md b/plugins/notifications/report.api.md index aacee54329..4d64c26c0f 100644 --- a/plugins/notifications/report.api.md +++ b/plugins/notifications/report.api.md @@ -208,6 +208,7 @@ export function useNotificationsApi( // @public (undocumented) export const UserNotificationSettingsCard: (props: { originNames?: Record; + topicNames?: Record; }) => React_2.JSX.Element; // (No @packageDocumentation comment for this package)