From a9b0748d073f44443ffeb6d83935276bc01b779b Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Wed, 19 Apr 2017 16:00:47 -0400 Subject: [PATCH] cipher delete for admin --- src/Api/Controllers/CiphersController.cs | 15 +++++++++++++++ src/Core/Services/ICipherService.cs | 2 +- .../Services/Implementations/CipherService.cs | 4 ++-- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/Api/Controllers/CiphersController.cs b/src/Api/Controllers/CiphersController.cs index dcc715bd2..7fb274ebc 100644 --- a/src/Api/Controllers/CiphersController.cs +++ b/src/Api/Controllers/CiphersController.cs @@ -207,5 +207,20 @@ namespace Bit.Api.Controllers await _cipherService.DeleteAsync(cipher, userId); } + + [HttpDelete("{id}/admin")] + [HttpPost("{id}/delete-admin")] + public async Task DeleteAdmin(string id) + { + var userId = _userService.GetProperUserId(User).Value; + var cipher = await _cipherRepository.GetByIdAsync(new Guid(id)); + if(cipher == null || !cipher.OrganizationId.HasValue || + !_currentContext.OrganizationAdmin(cipher.OrganizationId.Value)) + { + throw new NotFoundException(); + } + + await _cipherService.DeleteAsync(cipher, userId, true); + } } } diff --git a/src/Core/Services/ICipherService.cs b/src/Core/Services/ICipherService.cs index 8f87ef9dc..22b36a463 100644 --- a/src/Core/Services/ICipherService.cs +++ b/src/Core/Services/ICipherService.cs @@ -9,7 +9,7 @@ namespace Bit.Core.Services public interface ICipherService { Task SaveAsync(CipherDetails cipher, Guid savingUserId); - Task DeleteAsync(CipherDetails cipher, Guid deletingUserId); + Task DeleteAsync(Cipher cipher, Guid deletingUserId, bool orgAdmin = false); Task SaveFolderAsync(Folder folder); Task DeleteFolderAsync(Folder folder); Task ShareAsync(Cipher cipher, Guid organizationId, IEnumerable subvaultIds, Guid userId); diff --git a/src/Core/Services/Implementations/CipherService.cs b/src/Core/Services/Implementations/CipherService.cs index 2c8c34018..e803f51d1 100644 --- a/src/Core/Services/Implementations/CipherService.cs +++ b/src/Core/Services/Implementations/CipherService.cs @@ -65,9 +65,9 @@ namespace Bit.Core.Services } } - public async Task DeleteAsync(CipherDetails cipher, Guid deletingUserId) + public async Task DeleteAsync(Cipher cipher, Guid deletingUserId, bool orgAdmin = false) { - if(!(await UserCanEditAsync(cipher, deletingUserId))) + if(!orgAdmin && !(await UserCanEditAsync(cipher, deletingUserId))) { throw new BadRequestException("Not an admin."); }