Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
        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);
        }
Exemplo n.º 4
0
        public async Task <CipherResponseModel> Post([FromBody] CipherRequestModel model)
        {
            var userId = _userService.GetProperUserId(User).Value;
            var cipher = model.ToCipherDetails(userId);

            if (cipher.OrganizationId.HasValue && !_currentContext.OrganizationUser(cipher.OrganizationId.Value))
            {
                throw new NotFoundException();
            }

            await _cipherService.SaveDetailsAsync(cipher, userId, null, cipher.OrganizationId.HasValue);

            var response = new CipherResponseModel(cipher, _globalSettings);

            return(response);
        }