1
0
mirror of https://github.com/bitwarden/server.git synced 2025-04-06 13:38:13 -05:00

only get collection info when in an org

This commit is contained in:
Kyle Spearrin 2017-11-24 09:28:38 -05:00
parent a956b826cd
commit 0502ba2451
3 changed files with 21 additions and 9 deletions

View File

@ -90,7 +90,7 @@ namespace Bit.Api.Controllers
}
[HttpGet("")]
public async Task<ListResponseModel<CipherResponseModel>> Get([FromQuery]Core.Enums.CipherType? type = null)
public async Task<ListResponseModel<CipherDetailsResponseModel>> Get([FromQuery]Core.Enums.CipherType? type = null)
{
var userId = _userService.GetProperUserId(User).Value;
@ -104,8 +104,16 @@ namespace Bit.Api.Controllers
ciphers = await _cipherRepository.GetManyByUserIdAsync(userId);
}
var responses = ciphers.Select(c => new CipherResponseModel(c, _globalSettings)).ToList();
return new ListResponseModel<CipherResponseModel>(responses);
Dictionary<Guid, IGrouping<Guid, CollectionCipher>> collectionCiphersGroupDict = null;
if(_currentContext.Organizations.Any())
{
var collectionCiphers = await _collectionCipherRepository.GetManyByUserIdAsync(userId);
collectionCiphersGroupDict = collectionCiphers.GroupBy(c => c.CipherId).ToDictionary(s => s.Key);
}
var responses = ciphers.Select(c => new CipherDetailsResponseModel(c, _globalSettings,
collectionCiphersGroupDict)).ToList();
return new ListResponseModel<CipherDetailsResponseModel>(responses);
}
[HttpPost("")]
@ -179,14 +187,19 @@ namespace Bit.Api.Controllers
return response;
}
[Obsolete]
[HttpGet("details")]
public async Task<ListResponseModel<CipherDetailsResponseModel>> GetCollections()
{
var userId = _userService.GetProperUserId(User).Value;
var ciphers = await _cipherRepository.GetManyByUserIdHasCollectionsAsync(userId);
var collectionCiphers = await _collectionCipherRepository.GetManyByUserIdAsync(userId);
var collectionCiphersGroupDict = collectionCiphers.GroupBy(c => c.CipherId).ToDictionary(s => s.Key);
Dictionary<Guid, IGrouping<Guid, CollectionCipher>> collectionCiphersGroupDict = null;
if(_currentContext.Organizations.Any())
{
var collectionCiphers = await _collectionCipherRepository.GetManyByUserIdAsync(userId);
collectionCiphersGroupDict = collectionCiphers.GroupBy(c => c.CipherId).ToDictionary(s => s.Key);
}
var responses = ciphers.Select(c => new CipherDetailsResponseModel(c, _globalSettings, collectionCiphersGroupDict));
return new ListResponseModel<CipherDetailsResponseModel>(responses);

View File

@ -58,9 +58,8 @@ namespace Bit.Api.Controllers
var folders = await _folderRepository.GetManyByUserIdAsync(user.Id);
var ciphers = await _cipherRepository.GetManyByUserIdAsync(user.Id);
IEnumerable<Collection> collections = new List<Collection>();
IDictionary<Guid, IGrouping<Guid, CollectionCipher>> collectionCiphersGroupDict =
new Dictionary<Guid, IGrouping<Guid, CollectionCipher>>();
IEnumerable<Collection> collections = null;
IDictionary<Guid, IGrouping<Guid, CollectionCipher>> collectionCiphersGroupDict = null;
if(organizationUserDetails.Any(o => o.Enabled))
{
collections = await _collectionRepository.GetManyByUserIdAsync(user.Id, false);

View File

@ -22,7 +22,7 @@ namespace Bit.Core.Models.Api
Profile = new ProfileResponseModel(user, organizationUserDetails);
Folders = folders.Select(f => new FolderResponseModel(f));
Ciphers = ciphers.Select(c => new CipherDetailsResponseModel(c, globalSettings, collectionCiphersDict));
Collections = collections.Select(c => new CollectionResponseModel(c));
Collections = collections?.Select(c => new CollectionResponseModel(c)) ?? new List<CollectionResponseModel>();
Domains = new DomainsResponseModel(user, false);
}