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

add sends to sync response (#1002)

This commit is contained in:
Kyle Spearrin 2020-11-18 13:55:50 -05:00 committed by GitHub
parent faf909479e
commit 58eb0510ca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 3 deletions

View File

@ -26,6 +26,7 @@ namespace Bit.Api.Controllers
private readonly ICollectionCipherRepository _collectionCipherRepository; private readonly ICollectionCipherRepository _collectionCipherRepository;
private readonly IOrganizationUserRepository _organizationUserRepository; private readonly IOrganizationUserRepository _organizationUserRepository;
private readonly IPolicyRepository _policyRepository; private readonly IPolicyRepository _policyRepository;
private readonly ISendRepository _sendRepository;
private readonly GlobalSettings _globalSettings; private readonly GlobalSettings _globalSettings;
public SyncController( public SyncController(
@ -36,6 +37,7 @@ namespace Bit.Api.Controllers
ICollectionCipherRepository collectionCipherRepository, ICollectionCipherRepository collectionCipherRepository,
IOrganizationUserRepository organizationUserRepository, IOrganizationUserRepository organizationUserRepository,
IPolicyRepository policyRepository, IPolicyRepository policyRepository,
ISendRepository sendRepository,
GlobalSettings globalSettings) GlobalSettings globalSettings)
{ {
_userService = userService; _userService = userService;
@ -45,11 +47,12 @@ namespace Bit.Api.Controllers
_collectionCipherRepository = collectionCipherRepository; _collectionCipherRepository = collectionCipherRepository;
_organizationUserRepository = organizationUserRepository; _organizationUserRepository = organizationUserRepository;
_policyRepository = policyRepository; _policyRepository = policyRepository;
_sendRepository = sendRepository;
_globalSettings = globalSettings; _globalSettings = globalSettings;
} }
[HttpGet("")] [HttpGet("")]
public async Task<SyncResponseModel> Get([FromQuery]bool excludeDomains = false) public async Task<SyncResponseModel> Get([FromQuery] bool excludeDomains = false)
{ {
var user = await _userService.GetUserByPrincipalAsync(User); var user = await _userService.GetUserByPrincipalAsync(User);
if (user == null) if (user == null)
@ -62,6 +65,7 @@ namespace Bit.Api.Controllers
var hasEnabledOrgs = organizationUserDetails.Any(o => o.Enabled); var hasEnabledOrgs = organizationUserDetails.Any(o => o.Enabled);
var folders = await _folderRepository.GetManyByUserIdAsync(user.Id); var folders = await _folderRepository.GetManyByUserIdAsync(user.Id);
var ciphers = await _cipherRepository.GetManyByUserIdAsync(user.Id, hasEnabledOrgs); var ciphers = await _cipherRepository.GetManyByUserIdAsync(user.Id, hasEnabledOrgs);
var sends = await _sendRepository.GetManyByUserIdAsync(user.Id);
IEnumerable<CollectionDetails> collections = null; IEnumerable<CollectionDetails> collections = null;
IDictionary<Guid, IGrouping<Guid, CollectionCipher>> collectionCiphersGroupDict = null; IDictionary<Guid, IGrouping<Guid, CollectionCipher>> collectionCiphersGroupDict = null;
@ -76,7 +80,7 @@ namespace Bit.Api.Controllers
var userTwoFactorEnabled = await _userService.TwoFactorIsEnabledAsync(user); var userTwoFactorEnabled = await _userService.TwoFactorIsEnabledAsync(user);
var response = new SyncResponseModel(_globalSettings, user, userTwoFactorEnabled, organizationUserDetails, var response = new SyncResponseModel(_globalSettings, user, userTwoFactorEnabled, organizationUserDetails,
folders, collections, ciphers, collectionCiphersGroupDict, excludeDomains, policies); folders, collections, ciphers, collectionCiphersGroupDict, excludeDomains, policies, sends);
return response; return response;
} }
} }

View File

@ -19,7 +19,8 @@ namespace Bit.Core.Models.Api
IEnumerable<CipherDetails> ciphers, IEnumerable<CipherDetails> ciphers,
IDictionary<Guid, IGrouping<Guid, CollectionCipher>> collectionCiphersDict, IDictionary<Guid, IGrouping<Guid, CollectionCipher>> collectionCiphersDict,
bool excludeDomains, bool excludeDomains,
IEnumerable<Policy> policies) IEnumerable<Policy> policies,
IEnumerable<Send> sends)
: base("sync") : base("sync")
{ {
Profile = new ProfileResponseModel(user, organizationUserDetails, userTwoFactorEnabled); Profile = new ProfileResponseModel(user, organizationUserDetails, userTwoFactorEnabled);
@ -29,6 +30,7 @@ namespace Bit.Core.Models.Api
c => new CollectionDetailsResponseModel(c)) ?? new List<CollectionDetailsResponseModel>(); c => new CollectionDetailsResponseModel(c)) ?? new List<CollectionDetailsResponseModel>();
Domains = excludeDomains ? null : new DomainsResponseModel(user, false); Domains = excludeDomains ? null : new DomainsResponseModel(user, false);
Policies = policies?.Select(p => new PolicyResponseModel(p)) ?? new List<PolicyResponseModel>(); Policies = policies?.Select(p => new PolicyResponseModel(p)) ?? new List<PolicyResponseModel>();
Sends = sends.Select(s => new SendResponseModel(s, globalSettings));
} }
public ProfileResponseModel Profile { get; set; } public ProfileResponseModel Profile { get; set; }
@ -37,5 +39,6 @@ namespace Bit.Core.Models.Api
public IEnumerable<CipherDetailsResponseModel> Ciphers { get; set; } public IEnumerable<CipherDetailsResponseModel> Ciphers { get; set; }
public DomainsResponseModel Domains { get; set; } public DomainsResponseModel Domains { get; set; }
public IEnumerable<PolicyResponseModel> Policies { get; set; } public IEnumerable<PolicyResponseModel> Policies { get; set; }
public IEnumerable<SendResponseModel> Sends { get; set; }
} }
} }