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); } 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); } }
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); // push await _pushService.PushSyncCipherCreateAsync(cipher); } else { cipher.RevisionDate = DateTime.UtcNow; await _cipherRepository.ReplaceAsync(cipher); // push await _pushService.PushSyncCipherUpdateAsync(cipher); } }
public async Task SaveAsync(CipherDetails cipher, Guid savingUserId) { if (!(await UserCanEditAsync(cipher, savingUserId))) { throw new BadRequestException("Not an admin."); } cipher.UserId = savingUserId; if (cipher.Id == default(Guid)) { await _cipherRepository.CreateAsync(cipher); // push //await _pushService.PushSyncCipherCreateAsync(cipher); } else { cipher.RevisionDate = DateTime.UtcNow; await _cipherRepository.ReplaceAsync(cipher); // push //await _pushService.PushSyncCipherUpdateAsync(cipher); } }