Beispiel #1
0
        public async Task <ListResponseModel <CipherMiniDetailsResponseModel> > GetOrganizationCollections(
            string organizationId)
        {
            var userId    = _userService.GetProperUserId(User).Value;
            var orgIdGuid = new Guid(organizationId);

            if (!await _currentContext.ViewAllCollections(orgIdGuid) && !await _currentContext.AccessReports(orgIdGuid))
            {
                throw new NotFoundException();
            }

            var ciphers = await _cipherRepository.GetManyByOrganizationIdAsync(orgIdGuid);

            var collectionCiphers = await _collectionCipherRepository.GetManyByOrganizationIdAsync(orgIdGuid);

            var collectionCiphersGroupDict = collectionCiphers.GroupBy(c => c.CipherId).ToDictionary(s => s.Key);

            var responses = ciphers.Select(c => new CipherMiniDetailsResponseModel(c, _globalSettings,
                                                                                   collectionCiphersGroupDict));

            var providerId = await _currentContext.ProviderIdForOrg(orgIdGuid);

            if (providerId.HasValue)
            {
                await _providerService.LogProviderAccessToOrganizationAsync(orgIdGuid);
            }
            return(new ListResponseModel <CipherMiniDetailsResponseModel>(responses));
        }
Beispiel #2
0
        public async Task <ListResponseModel <CipherMiniDetailsResponseModel> > GetOrganizationCollections(
            string organizationId)
        {
            var userId    = _userService.GetProperUserId(User).Value;
            var orgIdGuid = new Guid(organizationId);

            if (!await _currentContext.ViewAllCollections(orgIdGuid) && !await _currentContext.AccessReports(orgIdGuid))
            {
                throw new NotFoundException();
            }

            IEnumerable <Cipher> orgCiphers;

            if (await _currentContext.OrganizationOwner(orgIdGuid))
            {
                // User may be a Provider for the organization, in which case GetManyByUserIdAsync won't return any results
                // But they have access to all organization ciphers, so we can safely get by orgId instead
                orgCiphers = await _cipherRepository.GetManyByOrganizationIdAsync(orgIdGuid);
            }
            else
            {
                var ciphers = await _cipherRepository.GetManyByUserIdAsync(userId, true);

                orgCiphers = ciphers.Where(c => c.OrganizationId == orgIdGuid);
            }

            var orgCipherIds = orgCiphers.Select(c => c.Id);

            var collectionCiphers = await _collectionCipherRepository.GetManyByOrganizationIdAsync(orgIdGuid);

            var collectionCiphersGroupDict = collectionCiphers
                                             .Where(c => orgCipherIds.Contains(c.CipherId))
                                             .GroupBy(c => c.CipherId).ToDictionary(s => s.Key);


            var responses = orgCiphers.Select(c => new CipherMiniDetailsResponseModel(c, _globalSettings,
                                                                                      collectionCiphersGroupDict));

            var providerId = await _currentContext.ProviderIdForOrg(orgIdGuid);

            if (providerId.HasValue)
            {
                await _providerService.LogProviderAccessToOrganizationAsync(orgIdGuid);
            }
            return(new ListResponseModel <CipherMiniDetailsResponseModel>(responses));
        }
Beispiel #3
0
        public async Task <ListResponseModel <CipherMiniDetailsResponseModel> > GetOrganizationCollections(string organizationId)
        {
            var userId    = _userService.GetProperUserId(User).Value;
            var orgIdGuid = new Guid(organizationId);

            if (!_currentContext.OrganizationAdmin(orgIdGuid))
            {
                throw new NotFoundException();
            }

            var ciphers = await _cipherRepository.GetManyByOrganizationIdAsync(orgIdGuid);

            var collectionCiphers = await _collectionCipherRepository.GetManyByOrganizationIdAsync(orgIdGuid);

            var collectionCiphersGroupDict = collectionCiphers.GroupBy(c => c.CipherId).ToDictionary(s => s.Key);

            var responses = ciphers.Select(c => new CipherMiniDetailsResponseModel(c, collectionCiphersGroupDict));

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