Skip to content

Commit

Permalink
[PM-13839][PM-13840] Admin Console Collections (#4922)
Browse files Browse the repository at this point in the history
* add collectionIds to the response of `{id}/admin`

- They're now needed in the admin console when add/editing a cipher.
- Prior to this there was no way to edit collection when editing a cipher. Assigning collections was a separate workflow

* return cipher from collections endpoint
  • Loading branch information
nick-livefront authored and cyprain-okeke committed Nov 12, 2024
1 parent be2b755 commit 5ac5596
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/Api/Vault/Controllers/CiphersController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,10 @@ public async Task<CipherMiniResponseModel> GetAdmin(string id)
throw new NotFoundException();
}

return new CipherMiniResponseModel(cipher, _globalSettings, cipher.OrganizationUseTotp);
var collectionCiphers = await _collectionCipherRepository.GetManyByOrganizationIdAsync(cipher.OrganizationId.Value);
var collectionCiphersGroupDict = collectionCiphers.GroupBy(c => c.CipherId).ToDictionary(s => s.Key);

return new CipherMiniDetailsResponseModel(cipher, _globalSettings, collectionCiphersGroupDict, cipher.OrganizationUseTotp);
}

[HttpGet("{id}/full-details")]
Expand Down Expand Up @@ -600,10 +603,10 @@ await _cipherService.SaveCollectionsAsync(cipher,

[HttpPut("{id}/collections-admin")]
[HttpPost("{id}/collections-admin")]
public async Task PutCollectionsAdmin(string id, [FromBody] CipherCollectionsRequestModel model)
public async Task<CipherMiniDetailsResponseModel> PutCollectionsAdmin(string id, [FromBody] CipherCollectionsRequestModel model)
{
var userId = _userService.GetProperUserId(User).Value;
var cipher = await _cipherRepository.GetByIdAsync(new Guid(id));
var cipher = await _cipherRepository.GetOrganizationDetailsByIdAsync(new Guid(id));

if (cipher == null || !cipher.OrganizationId.HasValue ||
!await CanEditCipherAsAdminAsync(cipher.OrganizationId.Value, new[] { cipher.Id }))
Expand All @@ -621,6 +624,11 @@ public async Task PutCollectionsAdmin(string id, [FromBody] CipherCollectionsReq
}

await _cipherService.SaveCollectionsAsync(cipher, collectionIds, userId, true);

var collectionCiphers = await _collectionCipherRepository.GetManyByOrganizationIdAsync(cipher.OrganizationId.Value);
var collectionCiphersGroupDict = collectionCiphers.GroupBy(c => c.CipherId).ToDictionary(s => s.Key);

return new CipherMiniDetailsResponseModel(cipher, _globalSettings, collectionCiphersGroupDict, cipher.OrganizationUseTotp);
}

[HttpPost("bulk-collections")]
Expand Down

0 comments on commit 5ac5596

Please sign in to comment.