Esempio n. 1
0
        public async Task SaveAsync(Cipher cipher, Guid savingUserId, DateTime?lastKnownRevisionDate,
                                    IEnumerable <Guid> collectionIds = null, bool skipPermissionCheck = false, bool limitCollectionScope = true)
        {
            if (!skipPermissionCheck && !(await UserCanEditAsync(cipher, savingUserId)))
            {
                throw new BadRequestException("You do not have permissions to edit this.");
            }

            if (cipher.Id == default(Guid))
            {
                if (cipher.OrganizationId.HasValue && collectionIds != null)
                {
                    if (limitCollectionScope)
                    {
                        // Set user ID to limit scope of collection ids in the create sproc
                        cipher.UserId = savingUserId;
                    }
                    await _cipherRepository.CreateAsync(cipher, collectionIds);

                    await _referenceEventService.RaiseEventAsync(
                        new ReferenceEvent(ReferenceEventType.CipherCreated, await _organizationRepository.GetByIdAsync(cipher.OrganizationId.Value)));
                }
                else
                {
                    await _cipherRepository.CreateAsync(cipher);
                }
                await _eventService.LogCipherEventAsync(cipher, Enums.EventType.Cipher_Created);

                // push
                await _pushService.PushSyncCipherCreateAsync(cipher, null);
            }
            else
            {
                if (collectionIds != null)
                {
                    throw new ArgumentException("Cannot create cipher with collection ids at the same time.");
                }
                ValidateCipherLastKnownRevisionDateAsync(cipher, lastKnownRevisionDate);
                cipher.RevisionDate = DateTime.UtcNow;
                await _cipherRepository.ReplaceAsync(cipher);

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

                // push
                await _pushService.PushSyncCipherUpdateAsync(cipher, null);
            }
        }
Esempio n. 2
0
        public async Task SaveAsync(Cipher cipher, Guid savingUserId, bool orgAdmin = false)
        {
            if (!orgAdmin && !(await UserCanEditAsync(cipher, savingUserId)))
            {
                throw new BadRequestException("You do not have permissions to edit this.");
            }

            if (cipher.Id == default(Guid))
            {
                await _cipherRepository.CreateAsync(cipher);

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

                // push
                await _pushService.PushSyncCipherCreateAsync(cipher, null);
            }
            else
            {
                cipher.RevisionDate = DateTime.UtcNow;
                await _cipherRepository.ReplaceAsync(cipher);

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

                // push
                await _pushService.PushSyncCipherUpdateAsync(cipher, null);
            }
        }
Esempio n. 3
0
        public async Task SaveAsync(Cipher cipher, Guid savingUserId, IEnumerable <Guid> collectionIds = null,
                                    bool skipPermissionCheck = false)
        {
            if (!skipPermissionCheck && !(await UserCanEditAsync(cipher, savingUserId)))
            {
                throw new BadRequestException("You do not have permissions to edit this.");
            }

            if (cipher.Id == default(Guid))
            {
                if (cipher.OrganizationId.HasValue && collectionIds != null)
                {
                    await _cipherRepository.CreateAsync(cipher, collectionIds);
                }
                else
                {
                    await _cipherRepository.CreateAsync(cipher);
                }
                await _eventService.LogCipherEventAsync(cipher, Enums.EventType.Cipher_Created);

                // push
                await _pushService.PushSyncCipherCreateAsync(cipher, null);
            }
            else
            {
                if (collectionIds != null)
                {
                    throw new ArgumentException("Cannot create cipher with collection ids at the same time.");
                }
                cipher.RevisionDate = DateTime.UtcNow;
                await _cipherRepository.ReplaceAsync(cipher);

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

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