From da337189026dcc69fc5c6d06ecefb6ba55345d07 Mon Sep 17 00:00:00 2001 From: Nicholas Cristofaro Date: Wed, 4 Dec 2024 10:49:17 -0300 Subject: [PATCH] is: Filter email receivers by user state --- pkg/identityserver/email.go | 7 ++++++- pkg/identityserver/notification_registry.go | 5 +++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/pkg/identityserver/email.go b/pkg/identityserver/email.go index d19b0b353e..3a6efbe1ff 100644 --- a/pkg/identityserver/email.go +++ b/pkg/identityserver/email.go @@ -109,6 +109,11 @@ func (is *IdentityServer) SendNotificationEmailToUsers(ctx context.Context, noti continue } + // Skips over non approved users. + if receiver.State != ttnpb.State_STATE_APPROVED { + continue + } + wg.Go(func() error { templateData, err := emailNotification.DataBuilder( ctx, @@ -147,7 +152,7 @@ func (is *IdentityServer) SendTemplateEmailToUserIDs( return is.SendTemplateEmailToUsers(ctx, templateName, dataBuilder, receivers...) } -var notificationEmailUserFields = store.FieldMask{"ids", "name", "primary_email_address", "admin"} +var notificationEmailUserFields = store.FieldMask{"ids", "name", "primary_email_address", "admin", "state"} // SendNotificationEmailToUserIDs looks up the users and sends them a notification email. func (is *IdentityServer) SendNotificationEmailToUserIDs(ctx context.Context, notification *ttnpb.Notification, receiverIDs ...*ttnpb.UserIdentifiers) error { diff --git a/pkg/identityserver/notification_registry.go b/pkg/identityserver/notification_registry.go index 83db4aa81f..93227118c0 100644 --- a/pkg/identityserver/notification_registry.go +++ b/pkg/identityserver/notification_registry.go @@ -350,6 +350,11 @@ func (is *IdentityServer) notifyAdminsInternal(ctx context.Context, req *ttnpb.C if receiver.Ids.IDString() == ttnpb.SupportUserID { continue } + + // Skips over non approved administrators. + if receiver.State != ttnpb.State_STATE_APPROVED { + continue + } receiverUserIDs[i] = receiver.Ids }