feat: add user specific notification settings
The settings can be customized for each origin and each processor individually. The default Web indicates notifications shown in the Backstage UI. By default, if there are no settings saved in the database, all notifications are enabled for all processors. The origins will populate by time for each user as they receive the first notification from that origin. Processors are shown as their own columns. Later, if it makes sense, allow users to also disable/enable notifications based on notification topic. Signed-off-by: Heikki Hellgren <heikki.hellgren@op.fi>
This commit is contained in:
@@ -10,6 +10,13 @@ export const getProcessorFiltersFromConfig: (
|
||||
config: Config,
|
||||
) => NotificationProcessorFilters;
|
||||
|
||||
// @public (undocumented)
|
||||
export const isNotificationsEnabledFor: (
|
||||
settings: NotificationSettings,
|
||||
channelId: string,
|
||||
originId: string,
|
||||
) => boolean;
|
||||
|
||||
// @public (undocumented)
|
||||
export type NewNotificationSignal = {
|
||||
action: 'new_notification';
|
||||
@@ -53,6 +60,17 @@ export type NotificationReadSignal = {
|
||||
notification_ids: string[];
|
||||
};
|
||||
|
||||
// @public (undocumented)
|
||||
export type NotificationSettings = {
|
||||
channels: {
|
||||
id: string;
|
||||
origins: {
|
||||
id: string;
|
||||
enabled: boolean;
|
||||
}[];
|
||||
}[];
|
||||
};
|
||||
|
||||
// @public
|
||||
export const notificationSeverities: NotificationSeverity[];
|
||||
|
||||
|
||||
@@ -23,3 +23,4 @@
|
||||
export * from './types';
|
||||
export * from './constants';
|
||||
export * from './filters';
|
||||
export * from './utils';
|
||||
|
||||
@@ -125,3 +125,16 @@ export type NotificationProcessorFilters = {
|
||||
maxSeverity?: NotificationSeverity;
|
||||
excludedTopics?: string[];
|
||||
};
|
||||
|
||||
/**
|
||||
* @public
|
||||
*/
|
||||
export type NotificationSettings = {
|
||||
channels: {
|
||||
id: string;
|
||||
origins: {
|
||||
id: string;
|
||||
enabled: boolean;
|
||||
}[];
|
||||
}[];
|
||||
};
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright 2024 The Backstage Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import { NotificationSettings } from './types';
|
||||
|
||||
/** @public */
|
||||
export const isNotificationsEnabledFor = (
|
||||
settings: NotificationSettings,
|
||||
channelId: string,
|
||||
originId: string,
|
||||
) => {
|
||||
const channel = settings.channels.find(c => c.id === channelId);
|
||||
if (!channel) {
|
||||
return true;
|
||||
}
|
||||
|
||||
const origin = channel.origins.find(o => o.id === originId);
|
||||
if (!origin) {
|
||||
return true;
|
||||
}
|
||||
return origin.enabled;
|
||||
};
|
||||
Reference in New Issue
Block a user