Пример #1
0
        public async Task SaveCollectionsAsync(Cipher cipher, IEnumerable <Guid> collectionIds, Guid savingUserId, bool orgAdmin)
        {
            if (cipher.Id == default(Guid))
            {
                throw new BadRequestException(nameof(cipher.Id));
            }

            if (!cipher.OrganizationId.HasValue)
            {
                throw new BadRequestException("Cipher must belong to an organization.");
            }

            // The sprocs will validate that all collections belong to this org/user and that they have proper write permissions.
            if (orgAdmin)
            {
                await _collectionCipherRepository.UpdateCollectionsForAdminAsync(cipher.Id, cipher.OrganizationId.Value,
                                                                                 collectionIds);
            }
            else
            {
                await _collectionCipherRepository.UpdateCollectionsAsync(cipher.Id, savingUserId, collectionIds);
            }

            // push
            await _pushService.PushSyncCipherUpdateAsync(cipher);
        }
Пример #2
0
        public async Task SaveCollectionsAsync(Cipher cipher, IEnumerable <Guid> collectionIds, Guid savingUserId,
                                               bool orgAdmin)
        {
            if (cipher.Id == default(Guid))
            {
                throw new BadRequestException(nameof(cipher.Id));
            }

            if (!cipher.OrganizationId.HasValue)
            {
                throw new BadRequestException("Cipher must belong to an organization.");
            }

            cipher.RevisionDate = DateTime.UtcNow;

            // The sprocs will validate that all collections belong to this org/user and that they have
            // proper write permissions.
            if (orgAdmin)
            {
                await _collectionCipherRepository.UpdateCollectionsForAdminAsync(cipher.Id,
                                                                                 cipher.OrganizationId.Value, collectionIds);
            }
            else
            {
                if (!(await UserCanEditAsync(cipher, savingUserId)))
                {
                    throw new BadRequestException("You do not have permissions to edit this.");
                }
                await _collectionCipherRepository.UpdateCollectionsAsync(cipher.Id, savingUserId, collectionIds);
            }

            await _eventService.LogCipherEventAsync(cipher, Enums.EventType.Cipher_UpdatedCollections);

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