public async Task <CipherResponseModel> Put(string id, [FromBody] CipherRequestModel model) { var userId = _userService.GetProperUserId(User).Value; var cipher = await _cipherRepository.GetByIdAsync(new Guid(id), userId); if (cipher == null) { throw new NotFoundException(); } var modelOrgId = string.IsNullOrWhiteSpace(model.OrganizationId) ? (Guid?)null : new Guid(model.OrganizationId); if (cipher.OrganizationId != modelOrgId) { throw new BadRequestException("Organization mismatch. Re-sync if you recently shared this item, " + "then try again."); } await _cipherService.SaveDetailsAsync(model.ToCipherDetails(cipher), userId); var response = new CipherResponseModel(cipher, _globalSettings); return(response); }
public async Task <CipherResponseModel> Put(Guid id, [FromBody] CipherRequestModel model) { var userId = _userService.GetProperUserId(User).Value; var cipher = await _cipherRepository.GetByIdAsync(id, userId); if (cipher == null) { throw new NotFoundException(); } var collectionIds = (await _collectionCipherRepository.GetManyByUserIdCipherIdAsync(userId, id)).Select(c => c.CollectionId).ToList(); var modelOrgId = string.IsNullOrWhiteSpace(model.OrganizationId) ? (Guid?)null : new Guid(model.OrganizationId); if (cipher.OrganizationId != modelOrgId) { throw new BadRequestException("Organization mismatch. Re-sync if you recently moved this item, " + "then try again."); } await _cipherService.SaveDetailsAsync(model.ToCipherDetails(cipher), userId, model.LastKnownRevisionDate, collectionIds); var response = new CipherResponseModel(cipher, _globalSettings); return(response); }
public async Task <CipherResponseModel> Post([FromBody] CipherRequestModel model) { var userId = _userService.GetProperUserId(User).Value; var cipher = model.ToCipherDetails(userId); await _cipherService.SaveDetailsAsync(cipher, userId); var response = new CipherResponseModel(cipher, _globalSettings); return(response); }
public async Task <CipherResponseModel> PostCreate([FromBody] CipherCreateRequestModel model) { var userId = _userService.GetProperUserId(User).Value; var cipher = model.Cipher.ToCipherDetails(userId); if (cipher.OrganizationId.HasValue && !_currentContext.OrganizationUser(cipher.OrganizationId.Value)) { throw new NotFoundException(); } await _cipherService.SaveDetailsAsync(cipher, userId, model.CollectionIds, cipher.OrganizationId.HasValue); var response = new CipherResponseModel(cipher, _globalSettings); return(response); }
public async Task <CipherResponseModel> PutShare(string id, [FromBody] CipherShareRequestModel model) { var userId = _userService.GetProperUserId(User).Value; var cipherId = new Guid(id); var cipher = await _cipherRepository.GetByIdAsync(cipherId); if (cipher == null || cipher.UserId != userId || !_currentContext.OrganizationUser(new Guid(model.Cipher.OrganizationId))) { throw new NotFoundException(); } var original = CoreHelpers.CloneObject(cipher); await _cipherService.ShareAsync(original, model.Cipher.ToCipher(cipher), new Guid(model.Cipher.OrganizationId), model.CollectionIds.Select(c => new Guid(c)), userId); var sharedCipher = await _cipherRepository.GetByIdAsync(cipherId, userId); var response = new CipherResponseModel(sharedCipher, _globalSettings); return(response); }