Exemplo n.º 1
0
        public async Task MoveSubvaultAsync(Cipher cipher, IEnumerable <Guid> subvaultIds, Guid userId)
        {
            if (cipher.Id == default(Guid))
            {
                throw new BadRequestException(nameof(cipher.Id));
            }

            if (!cipher.OrganizationId.HasValue)
            {
                throw new BadRequestException(nameof(cipher.OrganizationId));
            }

            var subvaultUserDetails = await _subvaultUserRepository.GetPermissionsByUserIdAsync(userId, subvaultIds,
                                                                                                cipher.OrganizationId.Value);

            cipher.UserId       = null;
            cipher.RevisionDate = DateTime.UtcNow;
            await _cipherRepository.ReplaceAsync(cipher, subvaultUserDetails.Where(s => s.Admin).Select(s => s.SubvaultId));

            // push
            //await _pushService.PushSyncCipherUpdateAsync(cipher);
        }
Exemplo n.º 2
0
        public async Task MoveSubvaultAsync(Cipher cipher, Guid organizationId, IEnumerable <Guid> subvaultIds, Guid movingUserId)
        {
            if (cipher.Id == default(Guid))
            {
                throw new BadRequestException(nameof(cipher.Id));
            }

            if (organizationId == default(Guid))
            {
                throw new BadRequestException(nameof(organizationId));
            }

            if (!cipher.UserId.HasValue || cipher.UserId.Value != movingUserId)
            {
                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(movingUserId, subvaultIds,
                                                                                                organizationId);

            var adminSubvaults = subvaultUserDetails.Where(s => s.Admin).Select(s => s.SubvaultId);

            if (!adminSubvaults.Any())
            {
                throw new BadRequestException("No subvaults.");
            }

            cipher.UserId         = null;
            cipher.OrganizationId = organizationId;
            cipher.RevisionDate   = DateTime.UtcNow;
            await _cipherRepository.ReplaceAsync(cipher, adminSubvaults);

            // push
            //await _pushService.PushSyncCipherUpdateAsync(cipher);
        }