Avoid false check for broadcast emails
Signed-off-by: Marek Libra <marek.libra@gmail.com>
This commit is contained in:
@@ -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.
|
||||
+10
-3
@@ -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);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user