Beispiel #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));
        }
Beispiel #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);
        }