Esempio n. 1
0
        public async Task <CollectionGroupDetailsResponseModel> GetDetails(string orgId, string id)
        {
            var orgIdGuid = new Guid(orgId);

            if (!ManageAnyCollections(orgIdGuid) && !_currentContext.ManageUsers(orgIdGuid))
            {
                throw new NotFoundException();
            }

            var idGuid = new Guid(id);

            if (_currentContext.ManageAllCollections(orgIdGuid))
            {
                var collectionDetails = await _collectionRepository.GetByIdWithGroupsAsync(idGuid);

                if (collectionDetails?.Item1 == null || collectionDetails.Item1.OrganizationId != orgIdGuid)
                {
                    throw new NotFoundException();
                }
                return(new CollectionGroupDetailsResponseModel(collectionDetails.Item1, collectionDetails.Item2));
            }
            else
            {
                var collectionDetails = await _collectionRepository.GetByIdWithGroupsAsync(idGuid,
                                                                                           _currentContext.UserId.Value);

                if (collectionDetails?.Item1 == null || collectionDetails.Item1.OrganizationId != orgIdGuid)
                {
                    throw new NotFoundException();
                }
                return(new CollectionGroupDetailsResponseModel(collectionDetails.Item1, collectionDetails.Item2));
            }
        }
Esempio n. 2
0
        public async Task <ListResponseModel <GroupResponseModel> > Get(string orgId)
        {
            var orgIdGuid = new Guid(orgId);
            var canAccess = _currentContext.ManageGroups(orgIdGuid) ||
                            _currentContext.ManageAssignedCollections(orgIdGuid) ||
                            _currentContext.ManageAllCollections(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));
        }
Esempio n. 3
0
        public async Task <CipherMiniResponseModel> GetAdmin(string id)
        {
            var cipher = await _cipherRepository.GetOrganizationDetailsByIdAsync(new Guid(id));

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

            return(new CipherMiniResponseModel(cipher, _globalSettings, cipher.OrganizationUseTotp));
        }