mirror of
https://github.com/bitwarden/server.git
synced 2025-07-01 16:12:49 -05:00
admin subvault updates for cipher
This commit is contained in:
@ -132,27 +132,17 @@ namespace Bit.Core.Services
|
||||
throw new NotFoundException();
|
||||
}
|
||||
|
||||
// We do not need to check if the user belongs to this organization since this call will return no subvaults
|
||||
// and therefore be caught by the .Any() check below.
|
||||
var subvaultUserDetails = await _subvaultUserRepository.GetPermissionsByUserIdAsync(sharingUserId, subvaultIds,
|
||||
organizationId);
|
||||
|
||||
var writeableSubvaults = subvaultUserDetails.Where(s => !s.ReadOnly).Select(s => s.SubvaultId);
|
||||
if(!writeableSubvaults.Any())
|
||||
{
|
||||
throw new BadRequestException("No subvaults.");
|
||||
}
|
||||
|
||||
cipher.UserId = null;
|
||||
// Sproc will not save this UserId on the cipher. It is used limit scope of the subvaultIds.
|
||||
cipher.UserId = sharingUserId;
|
||||
cipher.OrganizationId = organizationId;
|
||||
cipher.RevisionDate = DateTime.UtcNow;
|
||||
await _cipherRepository.ReplaceAsync(cipher, writeableSubvaults);
|
||||
await _cipherRepository.ReplaceAsync(cipher, subvaultIds);
|
||||
|
||||
// push
|
||||
//await _pushService.PushSyncCipherUpdateAsync(cipher);
|
||||
}
|
||||
|
||||
public async Task SaveSubvaultsAsync(Cipher cipher, IEnumerable<Guid> subvaultIds, Guid savingUserId)
|
||||
public async Task SaveSubvaultsAsync(Cipher cipher, IEnumerable<Guid> subvaultIds, Guid savingUserId, bool orgAdmin)
|
||||
{
|
||||
if(cipher.Id == default(Guid))
|
||||
{
|
||||
@ -164,18 +154,16 @@ namespace Bit.Core.Services
|
||||
throw new BadRequestException("Cipher must belong to an organization.");
|
||||
}
|
||||
|
||||
// We do not need to check if the user belongs to this organization since this call will return no subvaults
|
||||
// and therefore be caught by the .Any() check below.
|
||||
var subvaultUserDetails = await _subvaultUserRepository.GetPermissionsByUserIdAsync(savingUserId, subvaultIds,
|
||||
cipher.OrganizationId.Value);
|
||||
|
||||
var writeableSubvaults = subvaultUserDetails.Where(s => !s.ReadOnly).Select(s => s.SubvaultId);
|
||||
if(!writeableSubvaults.Any())
|
||||
// The sprocs will validate that all subvaults belong to this org/user and that they have proper write permissions.
|
||||
if(orgAdmin)
|
||||
{
|
||||
throw new BadRequestException("No subvaults.");
|
||||
await _subvaultCipherRepository.UpdateSubvaultsForAdminAsync(cipher.Id, cipher.OrganizationId.Value,
|
||||
subvaultIds);
|
||||
}
|
||||
else
|
||||
{
|
||||
await _subvaultCipherRepository.UpdateSubvaultsAsync(cipher.Id, savingUserId, subvaultIds);
|
||||
}
|
||||
|
||||
await _subvaultCipherRepository.UpdateSubvaultsAsync(cipher.Id, savingUserId, writeableSubvaults);
|
||||
|
||||
// push
|
||||
//await _pushService.PushSyncCipherUpdateAsync(cipher);
|
||||
|
Reference in New Issue
Block a user