From de997a2246303c95e6c1ed6b86eae67c20785f63 Mon Sep 17 00:00:00 2001 From: Oscar Hinton Date: Wed, 20 Apr 2022 21:05:21 +0200 Subject: [PATCH] Avoid sending "user need confirmation" emails when there are no org admins (#1960) --- .../Services/Implementations/OrganizationService.cs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/Core/Services/Implementations/OrganizationService.cs b/src/Core/Services/Implementations/OrganizationService.cs index a21a9cee3b..b72c604a26 100644 --- a/src/Core/Services/Implementations/OrganizationService.cs +++ b/src/Core/Services/Implementations/OrganizationService.cs @@ -1405,10 +1405,15 @@ namespace Bit.Core.Services await _organizationUserRepository.ReplaceAsync(orgUser); - await _mailService.SendOrganizationAcceptedEmailAsync( - (await _organizationRepository.GetByIdAsync(orgUser.OrganizationId)), - user.Email, - (await _organizationUserRepository.GetManyByMinimumRoleAsync(orgUser.OrganizationId, OrganizationUserType.Admin)).Select(a => a.Email).Distinct()); + var admins = await _organizationUserRepository.GetManyByMinimumRoleAsync(orgUser.OrganizationId, OrganizationUserType.Admin); + var adminEmails = admins.Select(a => a.Email).Distinct().ToList(); + + if (adminEmails.Count > 0) + { + var organization = await _organizationRepository.GetByIdAsync(orgUser.OrganizationId); + await _mailService.SendOrganizationAcceptedEmailAsync(organization, user.Email, adminEmails); + } + return orgUser; }