mirror of
https://github.com/bitwarden/server.git
synced 2025-05-22 12:04:27 -05:00
delete organization
This commit is contained in:
parent
53a25b908a
commit
96979079ba
@ -8,6 +8,8 @@ using Bit.Core.Models.Api;
|
|||||||
using Bit.Core.Exceptions;
|
using Bit.Core.Exceptions;
|
||||||
using Bit.Core.Services;
|
using Bit.Core.Services;
|
||||||
using Bit.Core;
|
using Bit.Core;
|
||||||
|
using Microsoft.AspNetCore.Identity;
|
||||||
|
using Bit.Core.Models.Table;
|
||||||
|
|
||||||
namespace Bit.Api.Controllers
|
namespace Bit.Api.Controllers
|
||||||
{
|
{
|
||||||
@ -20,19 +22,22 @@ namespace Bit.Api.Controllers
|
|||||||
private readonly IOrganizationService _organizationService;
|
private readonly IOrganizationService _organizationService;
|
||||||
private readonly IUserService _userService;
|
private readonly IUserService _userService;
|
||||||
private readonly CurrentContext _currentContext;
|
private readonly CurrentContext _currentContext;
|
||||||
|
private readonly UserManager<User> _userManager;
|
||||||
|
|
||||||
public OrganizationsController(
|
public OrganizationsController(
|
||||||
IOrganizationRepository organizationRepository,
|
IOrganizationRepository organizationRepository,
|
||||||
IOrganizationUserRepository organizationUserRepository,
|
IOrganizationUserRepository organizationUserRepository,
|
||||||
IOrganizationService organizationService,
|
IOrganizationService organizationService,
|
||||||
IUserService userService,
|
IUserService userService,
|
||||||
CurrentContext currentContext)
|
CurrentContext currentContext,
|
||||||
|
UserManager<User> userManager)
|
||||||
{
|
{
|
||||||
_organizationRepository = organizationRepository;
|
_organizationRepository = organizationRepository;
|
||||||
_organizationUserRepository = organizationUserRepository;
|
_organizationUserRepository = organizationUserRepository;
|
||||||
_organizationService = organizationService;
|
_organizationService = organizationService;
|
||||||
_userService = userService;
|
_userService = userService;
|
||||||
_currentContext = currentContext;
|
_currentContext = currentContext;
|
||||||
|
_userManager = userManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet("{id}")]
|
[HttpGet("{id}")]
|
||||||
@ -185,7 +190,7 @@ namespace Bit.Api.Controllers
|
|||||||
|
|
||||||
[HttpDelete("{id}")]
|
[HttpDelete("{id}")]
|
||||||
[HttpPost("{id}/delete")]
|
[HttpPost("{id}/delete")]
|
||||||
public async Task Delete(string id)
|
public async Task Delete(string id, [FromBody]OrganizationDeleteRequestModel model)
|
||||||
{
|
{
|
||||||
var orgIdGuid = new Guid(id);
|
var orgIdGuid = new Guid(id);
|
||||||
if(!_currentContext.OrganizationOwner(orgIdGuid))
|
if(!_currentContext.OrganizationOwner(orgIdGuid))
|
||||||
@ -199,7 +204,16 @@ namespace Bit.Api.Controllers
|
|||||||
throw new NotFoundException();
|
throw new NotFoundException();
|
||||||
}
|
}
|
||||||
|
|
||||||
await _organizationRepository.DeleteAsync(organization);
|
var user = await _userService.GetUserByPrincipalAsync(User);
|
||||||
|
if(!await _userManager.CheckPasswordAsync(user, model.MasterPasswordHash))
|
||||||
|
{
|
||||||
|
ModelState.AddModelError("MasterPasswordHash", "Invalid password.");
|
||||||
|
await Task.Delay(2000);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
await _organizationService.DeleteAsync(organization);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,10 @@
|
|||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
|
||||||
|
namespace Bit.Core.Models.Api
|
||||||
|
{
|
||||||
|
public class OrganizationDeleteRequestModel
|
||||||
|
{
|
||||||
|
[Required]
|
||||||
|
public string MasterPasswordHash { get; set; }
|
||||||
|
}
|
||||||
|
}
|
@ -16,6 +16,7 @@ namespace Bit.Core.Services
|
|||||||
Task UpgradePlanAsync(Guid organizationId, PlanType plan, int additionalSeats);
|
Task UpgradePlanAsync(Guid organizationId, PlanType plan, int additionalSeats);
|
||||||
Task AdjustSeatsAsync(Guid organizationId, int seatAdjustment);
|
Task AdjustSeatsAsync(Guid organizationId, int seatAdjustment);
|
||||||
Task<Tuple<Organization, OrganizationUser>> SignUpAsync(OrganizationSignup organizationSignup);
|
Task<Tuple<Organization, OrganizationUser>> SignUpAsync(OrganizationSignup organizationSignup);
|
||||||
|
Task DeleteAsync(Organization organization);
|
||||||
Task UpdateAsync(Organization organization, bool updateBilling = false);
|
Task UpdateAsync(Organization organization, bool updateBilling = false);
|
||||||
Task<OrganizationUser> InviteUserAsync(Guid organizationId, Guid invitingUserId, string email,
|
Task<OrganizationUser> InviteUserAsync(Guid organizationId, Guid invitingUserId, string email,
|
||||||
Enums.OrganizationUserType type, IEnumerable<SubvaultUser> subvaults);
|
Enums.OrganizationUserType type, IEnumerable<SubvaultUser> subvaults);
|
||||||
|
@ -570,6 +570,21 @@ namespace Bit.Core.Services
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task DeleteAsync(Organization organization)
|
||||||
|
{
|
||||||
|
if(!string.IsNullOrWhiteSpace(organization.StripeSubscriptionId))
|
||||||
|
{
|
||||||
|
var subscriptionService = new StripeSubscriptionService();
|
||||||
|
var canceledSub = await subscriptionService.CancelAsync(organization.StripeSubscriptionId, false);
|
||||||
|
if(!canceledSub.CanceledAt.HasValue)
|
||||||
|
{
|
||||||
|
throw new BadRequestException("Unable to cancel subscription.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
await _organizationRepository.DeleteAsync(organization);
|
||||||
|
}
|
||||||
|
|
||||||
public async Task UpdateAsync(Organization organization, bool updateBilling = false)
|
public async Task UpdateAsync(Organization organization, bool updateBilling = false)
|
||||||
{
|
{
|
||||||
if(organization.Id == default(Guid))
|
if(organization.Id == default(Guid))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user