Example #1
0
        public async Task <CollectionResponseModel> Post(Guid orgId, [FromBody] CollectionRequestModel model)
        {
            var collection = model.ToCollection(orgId);

            if (!await CanCreateCollection(orgId, collection.Id) &&
                !await CanEditCollectionAsync(orgId, collection.Id))
            {
                throw new NotFoundException();
            }

            var assignUserToCollection = !(await _currentContext.EditAnyCollection(orgId)) &&
                                         await _currentContext.EditAssignedCollections(orgId);

            await _collectionService.SaveAsync(collection, model.Groups?.Select(g => g.ToSelectionReadOnly()),
                                               assignUserToCollection?_currentContext.UserId : null);

            return(new CollectionResponseModel(collection));
        }
Example #2
0
        private async Task <bool> CanEditCollectionAsync(Guid orgId, Guid collectionId)
        {
            if (collectionId == default)
            {
                return(false);
            }

            if (await _currentContext.EditAnyCollection(orgId))
            {
                return(true);
            }

            if (await _currentContext.EditAssignedCollections(orgId))
            {
                return(null != _collectionRepository.GetByIdAsync(collectionId, _currentContext.UserId.Value));
            }

            return(false);
        }
Example #3
0
        public async Task <CipherMiniResponseModel> PostAdmin([FromBody] CipherCreateRequestModel model)
        {
            var cipher = model.Cipher.ToOrganizationCipher();

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

            var userId = _userService.GetProperUserId(User).Value;
            await _cipherService.SaveAsync(cipher, userId, model.Cipher.LastKnownRevisionDate, model.CollectionIds, true, false);

            var response = new CipherMiniResponseModel(cipher, _globalSettings, false);

            return(response);
        }