From 5cd51fa0176fbdc9a386123d7747e8d820d51625 Mon Sep 17 00:00:00 2001 From: gdlcf88 Date: Mon, 20 Mar 2023 01:51:26 +0800 Subject: [PATCH] The user's email to be sent should be confirmed --- .../FakeExternalUserLookupServiceProvider.cs | 6 +++-- .../Mailing/MailingNotificationTests.cs | 22 +++++++++++++++++++ .../IdentityUserEmailAddressProvider.cs | 9 ++++++-- 3 files changed, 33 insertions(+), 4 deletions(-) diff --git a/providers/Mailing/EasyAbp.NotificationService.Provider.Mailing.Tests/EasyAbp/NotificationService/Provider/Mailing/FakeExternalUserLookupServiceProvider.cs b/providers/Mailing/EasyAbp.NotificationService.Provider.Mailing.Tests/EasyAbp/NotificationService/Provider/Mailing/FakeExternalUserLookupServiceProvider.cs index 5888c68..bcb146c 100644 --- a/providers/Mailing/EasyAbp.NotificationService.Provider.Mailing.Tests/EasyAbp/NotificationService/Provider/Mailing/FakeExternalUserLookupServiceProvider.cs +++ b/providers/Mailing/EasyAbp.NotificationService.Provider.Mailing.Tests/EasyAbp/NotificationService/Provider/Mailing/FakeExternalUserLookupServiceProvider.cs @@ -16,7 +16,8 @@ public class FakeExternalUserLookupServiceProvider : IExternalUserLookupServiceP return new UserData( NotificationServiceProviderMailingTestConsts.FakeUser1Id, "fake1", - "user1@easyabp.io"); + "user1@easyabp.io", + emailConfirmed: true); } if (id == NotificationServiceProviderMailingTestConsts.FakeUser2Id) @@ -24,7 +25,8 @@ public class FakeExternalUserLookupServiceProvider : IExternalUserLookupServiceP return new UserData( NotificationServiceProviderMailingTestConsts.FakeUser2Id, "fake2", - "user2@easyabp.io"); + "user2@easyabp.io", + emailConfirmed: false); } return null; diff --git a/providers/Mailing/EasyAbp.NotificationService.Provider.Mailing.Tests/EasyAbp/NotificationService/Provider/Mailing/MailingNotificationTests.cs b/providers/Mailing/EasyAbp.NotificationService.Provider.Mailing.Tests/EasyAbp/NotificationService/Provider/Mailing/MailingNotificationTests.cs index a50fae8..a75a384 100644 --- a/providers/Mailing/EasyAbp.NotificationService.Provider.Mailing.Tests/EasyAbp/NotificationService/Provider/Mailing/MailingNotificationTests.cs +++ b/providers/Mailing/EasyAbp.NotificationService.Provider.Mailing.Tests/EasyAbp/NotificationService/Provider/Mailing/MailingNotificationTests.cs @@ -93,6 +93,28 @@ await EmailNotificationSendingJob.ExecuteAsync( notification.FailureReason.ShouldBeNull(); } + [Fact] + public async Task Should_Set_Notification_Result_To_Failure_If_Email_Is_Not_Confirmed() + { + var userIds = new List + { + NotificationServiceProviderMailingTestConsts.FakeUser2Id + }; + + await CreateEmailNotificationAsync(userIds, Subject, Body); + + var notification = (await NotificationRepository.GetListAsync()).First(); + + await EmailNotificationSendingJob.ExecuteAsync( + new EmailNotificationSendingJobArgs(notification.TenantId, notification.Id)); + + notification = await NotificationRepository.GetAsync(notification.Id); + + notification.Success.ShouldBe(false); + notification.CompletionTime.ShouldNotBeNull(); + notification.FailureReason.ShouldBe(NotificationConsts.FailureReasons.ReceiverInfoNotFound); + } + [Fact] public async Task Should_Set_Notification_Result_To_Failure_If_User_Not_Found() { diff --git a/providers/Mailing/EasyAbp.NotificationService.Provider.Mailing/EasyAbp/NotificationService/Provider/Mailing/IdentityUserEmailAddressProvider.cs b/providers/Mailing/EasyAbp.NotificationService.Provider.Mailing/EasyAbp/NotificationService/Provider/Mailing/IdentityUserEmailAddressProvider.cs index 7994f36..3a92fef 100644 --- a/providers/Mailing/EasyAbp.NotificationService.Provider.Mailing/EasyAbp/NotificationService/Provider/Mailing/IdentityUserEmailAddressProvider.cs +++ b/providers/Mailing/EasyAbp.NotificationService.Provider.Mailing/EasyAbp/NotificationService/Provider/Mailing/IdentityUserEmailAddressProvider.cs @@ -15,12 +15,17 @@ public IdentityUserEmailAddressProvider( { _userLookupServiceProvider = userLookupServiceProvider; } - + public virtual async Task GetAsync(Guid userId) { var userData = await _userLookupServiceProvider.FindByIdAsync(userId); - return userData?.Email; + if (userData is null || !userData.EmailConfirmed || userData.Email.IsNullOrWhiteSpace()) + { + return null; + } + + return userData.Email; } } } \ No newline at end of file