1
0
mirror of https://github.com/bitwarden/server.git synced 2025-01-04 19:07:50 +01:00

cipher delete for admin

This commit is contained in:
Kyle Spearrin 2017-04-19 16:00:47 -04:00
parent 552b117821
commit a9b0748d07
3 changed files with 18 additions and 3 deletions

View File

@ -207,5 +207,20 @@ namespace Bit.Api.Controllers
await _cipherService.DeleteAsync(cipher, userId); 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);
}
} }
} }

View File

@ -9,7 +9,7 @@ namespace Bit.Core.Services
public interface ICipherService public interface ICipherService
{ {
Task SaveAsync(CipherDetails cipher, Guid savingUserId); 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 SaveFolderAsync(Folder folder);
Task DeleteFolderAsync(Folder folder); Task DeleteFolderAsync(Folder folder);
Task ShareAsync(Cipher cipher, Guid organizationId, IEnumerable<Guid> subvaultIds, Guid userId); Task ShareAsync(Cipher cipher, Guid organizationId, IEnumerable<Guid> subvaultIds, Guid userId);

View File

@ -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."); throw new BadRequestException("Not an admin.");
} }