1
0
mirror of https://github.com/bitwarden/server.git synced 2025-07-01 16:12:49 -05:00

Resolve error when deleting an account connected to a provider (#1580)

This commit is contained in:
Oscar Hinton
2021-09-15 20:34:06 +02:00
committed by GitHub
parent 00332e72e4
commit c22e48c1b4
11 changed files with 264 additions and 9 deletions

View File

@ -52,7 +52,7 @@ namespace Bit.Core.Services
private readonly ICurrentContext _currentContext;
private readonly GlobalSettings _globalSettings;
private readonly IOrganizationService _organizationService;
private readonly ISendRepository _sendRepository;
private readonly IProviderUserRepository _providerUserRepository;
public UserService(
IUserRepository userRepository,
@ -81,7 +81,7 @@ namespace Bit.Core.Services
ICurrentContext currentContext,
GlobalSettings globalSettings,
IOrganizationService organizationService,
ISendRepository sendRepository)
IProviderUserRepository providerUserRepository)
: base(
store,
optionsAccessor,
@ -115,7 +115,7 @@ namespace Bit.Core.Services
_currentContext = currentContext;
_globalSettings = globalSettings;
_organizationService = organizationService;
_sendRepository = sendRepository;
_providerUserRepository = providerUserRepository;
}
public Guid? GetProperUserId(ClaimsPrincipal principal)
@ -216,11 +216,20 @@ namespace Bit.Core.Services
{
return IdentityResult.Failed(new IdentityError
{
Description = "You must leave or delete any organizations that you are the only owner of first."
Description = "Cannot delete this user because it is the sole owner of at least one organization. Please delete these organizations or upgrade another user.",
});
}
}
var onlyOwnerProviderCount = await _providerUserRepository.GetCountByOnlyOwnerAsync(user.Id);
if (onlyOwnerProviderCount > 0)
{
return IdentityResult.Failed(new IdentityError
{
Description = "Cannot delete this user because it is the sole owner of at least one provider. Please delete these providers or upgrade another user.",
});
}
if (!string.IsNullOrWhiteSpace(user.GatewaySubscriptionId))
{
try