Esempio n. 1
0
        private async Task <Collection> GetCollectionAsync(Guid id, Guid orgId)
        {
            Collection collection = default;

            if (await _currentContext.ViewAllCollections(orgId))
            {
                collection = await _collectionRepository.GetByIdAsync(id);
            }
            else if (await _currentContext.ViewAssignedCollections(orgId))
            {
                collection = await _collectionRepository.GetByIdAsync(id, _currentContext.UserId.Value);
            }

            if (collection == null || collection.OrganizationId != orgId)
            {
                throw new NotFoundException();
            }

            return(collection);
        }
Esempio n. 2
0
        public async Task<ListResponseModel<GroupResponseModel>> Get(string orgId)
        {
            var orgIdGuid = new Guid(orgId);
            var canAccess = await _currentContext.ManageGroups(orgIdGuid) ||
                await _currentContext.ViewAssignedCollections(orgIdGuid) ||
                await _currentContext.ViewAllCollections(orgIdGuid) ||
                await _currentContext.ManageUsers(orgIdGuid);

            if (!canAccess)
            {
                throw new NotFoundException();
            }

            var groups = await _groupRepository.GetManyByOrganizationIdAsync(orgIdGuid);
            var responses = groups.Select(g => new GroupResponseModel(g));
            return new ListResponseModel<GroupResponseModel>(responses);
        }
        public async Task <ListResponseModel <OrganizationUserUserDetailsResponseModel> > Get(string orgId)
        {
            var orgGuidId = new Guid(orgId);

            if (!await _currentContext.ViewAssignedCollections(orgGuidId) &&
                !await _currentContext.ManageGroups(orgGuidId) &&
                !await _currentContext.ManageUsers(orgGuidId))
            {
                throw new NotFoundException();
            }

            var organizationUsers = await _organizationUserRepository.GetManyDetailsByOrganizationAsync(orgGuidId);

            var responseTasks = organizationUsers.Select(async o => new OrganizationUserUserDetailsResponseModel(o,
                                                                                                                 await _userService.TwoFactorIsEnabledAsync(o)));
            var responses = await Task.WhenAll(responseTasks);

            return(new ListResponseModel <OrganizationUserUserDetailsResponseModel>(responses));
        }