Exemplo n.º 1
0
        public async Task <CipherMiniResponseModel> PutAdmin(string id, [FromBody] CipherRequestModel model)
        {
            var userId = _userService.GetProperUserId(User).Value;
            var cipher = await _cipherRepository.GetDetailsByIdAsync(new Guid(id));

            if (cipher == null || !cipher.OrganizationId.HasValue ||
                !_currentContext.OrganizationAdmin(cipher.OrganizationId.Value))
            {
                throw new NotFoundException();
            }

            // object cannot be a descendant of CipherDetails, so let's clone it.
            var cipherClone = CoreHelpers.CloneObject(model.ToCipher(cipher));
            await _cipherService.SaveAsync(cipherClone, userId, true);

            var response = new CipherMiniResponseModel(cipherClone, _globalSettings, cipher.OrganizationUseTotp);

            return(response);
        }
Exemplo n.º 2
0
        public async Task <CipherMiniResponseModel> PutAdmin(Guid id, [FromBody] CipherRequestModel model)
        {
            var userId = _userService.GetProperUserId(User).Value;
            var cipher = await _cipherRepository.GetOrganizationDetailsByIdAsync(id);

            if (cipher == null || !cipher.OrganizationId.HasValue ||
                !await _currentContext.EditAnyCollection(cipher.OrganizationId.Value))
            {
                throw new NotFoundException();
            }

            var collectionIds = (await _collectionCipherRepository.GetManyByUserIdCipherIdAsync(userId, id)).Select(c => c.CollectionId).ToList();
            // object cannot be a descendant of CipherDetails, so let's clone it.
            var cipherClone = model.ToCipher(cipher).Clone();
            await _cipherService.SaveAsync(cipherClone, userId, model.LastKnownRevisionDate, collectionIds, true, false);

            var response = new CipherMiniResponseModel(cipherClone, _globalSettings, cipher.OrganizationUseTotp);

            return(response);
        }