Avoid false check for broadcast emails

Signed-off-by: Marek Libra <marek.libra@gmail.com>
This commit is contained in:
Marek Libra
2024-08-14 14:13:18 +02:00
parent 9ad63932cf
commit d55b8e317d
3 changed files with 17 additions and 4 deletions
+6
View File
@@ -0,0 +1,6 @@
---
'@backstage/plugin-notifications-backend-module-email': patch
'@backstage/plugin-notifications-backend': patch
---
Avoid sending broadcast emails as a fallback in case the entity-typed notification user can not be resolved.
@@ -207,12 +207,17 @@ export class NotificationsEmailProcessor implements NotificationProcessor {
private async getRecipientEmails(
notification: Notification,
options: NotificationSendOptions,
) {
): Promise<string[]> {
let emails: string[];
if (options.recipients.type === 'broadcast' || notification.user === null) {
if (options.recipients.type === 'broadcast') {
emails = await this.getBroadcastEmails();
} else {
} else if (options.recipients.type === 'entity' && !!notification.user) {
emails = await this.getUserEmail(notification.user);
} else {
this.logger.info(
`Unknown notification type ${options.recipients.type} or missing user.`,
);
return [];
}
if (this.allowlistEmailAddresses) {
@@ -338,6 +343,8 @@ export class NotificationsEmailProcessor implements NotificationProcessor {
return;
}
this.logger.debug(`Sending notification emails to: ${emails.join(',')}`);
if (!this.templateRenderer) {
await this.sendPlainEmail(notification, emails);
return;
@@ -157,5 +157,5 @@ export const getUsersForEntityRef = async (
users.push(...u);
}
return [...new Set(users)];
return [...new Set(users)].filter(Boolean);
};