1
0
mirror of https://github.com/bitwarden/server synced 2025-12-15 07:43:54 +00:00

[PM-20554] fix admin endpoint for deleting unassigned items (#6061)

* fix admin endpoint for deleting unassigned items

* whitespace cleanup

* fix tests

* switch type cast to constructor for CipherDetails

* fix tests
This commit is contained in:
Brandon Treston
2025-07-14 15:50:10 -04:00
committed by GitHub
parent d914ab8a98
commit 676f39cef8
2 changed files with 107 additions and 89 deletions

View File

@@ -926,14 +926,14 @@ public class CiphersController : Controller
public async Task PutDeleteAdmin(Guid id)
{
var userId = _userService.GetProperUserId(User).Value;
var cipher = await GetByIdAsync(id, userId);
var cipher = await GetByIdAsyncAdmin(id);
if (cipher == null || !cipher.OrganizationId.HasValue ||
!await CanDeleteOrRestoreCipherAsAdminAsync(cipher.OrganizationId.Value, new[] { cipher.Id }))
{
throw new NotFoundException();
}
await _cipherService.SoftDeleteAsync(cipher, userId, true);
await _cipherService.SoftDeleteAsync(new CipherDetails(cipher), userId, true);
}
[HttpPut("delete")]
@@ -995,14 +995,14 @@ public class CiphersController : Controller
public async Task<CipherMiniResponseModel> PutRestoreAdmin(Guid id)
{
var userId = _userService.GetProperUserId(User).Value;
var cipher = await GetByIdAsync(id, userId);
var cipher = await GetByIdAsyncAdmin(id);
if (cipher == null || !cipher.OrganizationId.HasValue ||
!await CanDeleteOrRestoreCipherAsAdminAsync(cipher.OrganizationId.Value, new[] { cipher.Id }))
{
throw new NotFoundException();
}
await _cipherService.RestoreAsync(cipher, userId, true);
await _cipherService.RestoreAsync(new CipherDetails(cipher), userId, true);
return new CipherMiniResponseModel(cipher, _globalSettings, cipher.OrganizationUseTotp);
}
@@ -1412,6 +1412,11 @@ public class CiphersController : Controller
}
}
private async Task<CipherOrganizationDetails> GetByIdAsyncAdmin(Guid cipherId)
{
return await _cipherRepository.GetOrganizationDetailsByIdAsync(cipherId);
}
private async Task<CipherDetails> GetByIdAsync(Guid cipherId, Guid userId)
{
return await _cipherRepository.GetByIdAsync(cipherId, userId);