mirror of
https://github.com/bitwarden/server.git
synced 2025-07-01 08:02:49 -05:00
[Soft Delete] - API updates for soft delete + retrieval
This commit is contained in:
@ -94,8 +94,12 @@ namespace Bit.Api.Controllers
|
||||
Dictionary<Guid, IGrouping<Guid, CollectionCipher>> collectionCiphersGroupDict = null;
|
||||
if (hasOrgs)
|
||||
{
|
||||
var keyMatches = ciphers.Select(c => c.Id); // Soft deletes not filtered in tweener "Get" methods
|
||||
var collectionCiphers = await _collectionCipherRepository.GetManyByUserIdAsync(userId);
|
||||
collectionCiphersGroupDict = collectionCiphers.GroupBy(c => c.CipherId).ToDictionary(s => s.Key);
|
||||
collectionCiphersGroupDict = collectionCiphers
|
||||
.Where(c => keyMatches.Contains(c.CipherId))
|
||||
.GroupBy(c => c.CipherId)
|
||||
.ToDictionary(s => s.Key);
|
||||
}
|
||||
|
||||
var responses = ciphers.Select(c => new CipherDetailsResponseModel(c, _globalSettings,
|
||||
@ -206,9 +210,13 @@ namespace Bit.Api.Controllers
|
||||
}
|
||||
|
||||
var ciphers = await _cipherRepository.GetManyByOrganizationIdAsync(orgIdGuid);
|
||||
var cipherMatchKeys = ciphers.Select(c => c.Id);
|
||||
|
||||
var collectionCiphers = await _collectionCipherRepository.GetManyByOrganizationIdAsync(orgIdGuid);
|
||||
var collectionCiphersGroupDict = collectionCiphers.GroupBy(c => c.CipherId).ToDictionary(s => s.Key);
|
||||
var collectionCiphersGroupDict = collectionCiphers
|
||||
.Where(c => cipherMatchKeys.Contains(c.CipherId))
|
||||
.GroupBy(c => c.CipherId)
|
||||
.ToDictionary(s => s.Key);
|
||||
|
||||
var responses = ciphers.Select(c => new CipherMiniDetailsResponseModel(c, _globalSettings,
|
||||
collectionCiphersGroupDict));
|
||||
@ -360,6 +368,83 @@ namespace Bit.Api.Controllers
|
||||
await _cipherService.DeleteManyAsync(model.Ids.Select(i => new Guid(i)), userId);
|
||||
}
|
||||
|
||||
[HttpPut("{id}/delete")]
|
||||
public async Task PutDelete(string id)
|
||||
{
|
||||
var userId = _userService.GetProperUserId(User).Value;
|
||||
var cipher = await _cipherRepository.GetByIdAsync(new Guid(id), userId);
|
||||
if (cipher == null)
|
||||
{
|
||||
throw new NotFoundException();
|
||||
}
|
||||
await _cipherService.SoftDeleteAsync(cipher, userId);
|
||||
}
|
||||
|
||||
[HttpPut("{id}/delete-admin")]
|
||||
public async Task PutDeleteAdmin(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.SoftDeleteAsync(cipher, userId, true);
|
||||
}
|
||||
|
||||
[HttpPut("delete")]
|
||||
public async Task PutDeleteMany([FromBody]CipherBulkRestoreRequestModel model)
|
||||
{
|
||||
if (!_globalSettings.SelfHosted && model.Ids.Count() > 500)
|
||||
{
|
||||
throw new BadRequestException("You can only restore up to 500 items at a time.");
|
||||
}
|
||||
|
||||
var userId = _userService.GetProperUserId(User).Value;
|
||||
await _cipherService.SoftDeleteManyAsync(model.Ids.Select(i => new Guid(i)), userId);
|
||||
}
|
||||
|
||||
[HttpPut("{id}/restore")]
|
||||
public async Task PutRestore(string id)
|
||||
{
|
||||
var userId = _userService.GetProperUserId(User).Value;
|
||||
var cipher = await _cipherRepository.GetByIdAsync(new Guid(id), userId);
|
||||
if (cipher == null)
|
||||
{
|
||||
throw new NotFoundException();
|
||||
}
|
||||
|
||||
await _cipherService.RestoreAsync(cipher, userId);
|
||||
}
|
||||
|
||||
[HttpPut("{id}/restore-admin")]
|
||||
public async Task PutRestoreAdmin(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.RestoreAsync(cipher, userId, true);
|
||||
}
|
||||
|
||||
[HttpPut("restore")]
|
||||
public async Task PutRestoreMany([FromBody]CipherBulkRestoreRequestModel model)
|
||||
{
|
||||
if (!_globalSettings.SelfHosted && model.Ids.Count() > 500)
|
||||
{
|
||||
throw new BadRequestException("You can only restore up to 500 items at a time.");
|
||||
}
|
||||
|
||||
var userId = _userService.GetProperUserId(User).Value;
|
||||
await _cipherService.RestoreManyAsync(model.Ids.Select(i => new Guid(i)), userId);
|
||||
}
|
||||
|
||||
[HttpPut("move")]
|
||||
[HttpPost("move")]
|
||||
public async Task MoveMany([FromBody]CipherBulkMoveRequestModel model)
|
||||
|
Reference in New Issue
Block a user