mirror of
https://github.com/bitwarden/server.git
synced 2025-05-23 04:21:05 -05:00
sometimes delete org on user delete
This commit is contained in:
parent
9b80043098
commit
002b642e50
@ -31,6 +31,7 @@ namespace Bit.Core.Services
|
|||||||
private readonly IUserRepository _userRepository;
|
private readonly IUserRepository _userRepository;
|
||||||
private readonly ICipherRepository _cipherRepository;
|
private readonly ICipherRepository _cipherRepository;
|
||||||
private readonly IOrganizationUserRepository _organizationUserRepository;
|
private readonly IOrganizationUserRepository _organizationUserRepository;
|
||||||
|
private readonly IOrganizationRepository _organizationRepository;
|
||||||
private readonly IU2fRepository _u2fRepository;
|
private readonly IU2fRepository _u2fRepository;
|
||||||
private readonly IMailService _mailService;
|
private readonly IMailService _mailService;
|
||||||
private readonly IPushNotificationService _pushService;
|
private readonly IPushNotificationService _pushService;
|
||||||
@ -49,6 +50,7 @@ namespace Bit.Core.Services
|
|||||||
IUserRepository userRepository,
|
IUserRepository userRepository,
|
||||||
ICipherRepository cipherRepository,
|
ICipherRepository cipherRepository,
|
||||||
IOrganizationUserRepository organizationUserRepository,
|
IOrganizationUserRepository organizationUserRepository,
|
||||||
|
IOrganizationRepository organizationRepository,
|
||||||
IU2fRepository u2fRepository,
|
IU2fRepository u2fRepository,
|
||||||
IMailService mailService,
|
IMailService mailService,
|
||||||
IPushNotificationService pushService,
|
IPushNotificationService pushService,
|
||||||
@ -81,6 +83,7 @@ namespace Bit.Core.Services
|
|||||||
_userRepository = userRepository;
|
_userRepository = userRepository;
|
||||||
_cipherRepository = cipherRepository;
|
_cipherRepository = cipherRepository;
|
||||||
_organizationUserRepository = organizationUserRepository;
|
_organizationUserRepository = organizationUserRepository;
|
||||||
|
_organizationRepository = organizationRepository;
|
||||||
_u2fRepository = u2fRepository;
|
_u2fRepository = u2fRepository;
|
||||||
_mailService = mailService;
|
_mailService = mailService;
|
||||||
_pushService = pushService;
|
_pushService = pushService;
|
||||||
@ -173,12 +176,32 @@ namespace Bit.Core.Services
|
|||||||
// Check if user is the only owner of any organizations.
|
// Check if user is the only owner of any organizations.
|
||||||
var onlyOwnerCount = await _organizationUserRepository.GetCountByOnlyOwnerAsync(user.Id);
|
var onlyOwnerCount = await _organizationUserRepository.GetCountByOnlyOwnerAsync(user.Id);
|
||||||
if(onlyOwnerCount > 0)
|
if(onlyOwnerCount > 0)
|
||||||
|
{
|
||||||
|
var deletedOrg = false;
|
||||||
|
var orgs = await _organizationUserRepository.GetManyDetailsByUserAsync(user.Id,
|
||||||
|
OrganizationUserStatusType.Confirmed);
|
||||||
|
if(orgs.Count == 1)
|
||||||
|
{
|
||||||
|
var org = await _organizationRepository.GetByIdAsync(orgs.First().OrganizationId);
|
||||||
|
if(org != null && (!org.Enabled || string.IsNullOrWhiteSpace(org.GatewaySubscriptionId)))
|
||||||
|
{
|
||||||
|
var orgCount = await _organizationUserRepository.GetCountByOrganizationIdAsync(org.Id);
|
||||||
|
if(orgCount == 1)
|
||||||
|
{
|
||||||
|
await _organizationRepository.DeleteAsync(org);
|
||||||
|
deletedOrg = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!deletedOrg)
|
||||||
{
|
{
|
||||||
return IdentityResult.Failed(new IdentityError
|
return IdentityResult.Failed(new IdentityError
|
||||||
{
|
{
|
||||||
Description = "You must leave or delete any organizations that you are the only owner of first."
|
Description = "You must leave or delete any organizations that you are the only owner of first."
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if(!string.IsNullOrWhiteSpace(user.GatewaySubscriptionId))
|
if(!string.IsNullOrWhiteSpace(user.GatewaySubscriptionId))
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user