From 93cff6e283089a9fea978b2b0839da4c0bcab490 Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Tue, 10 Jan 2017 21:50:19 -0500 Subject: [PATCH] added parameter for excluded --- src/Api/Controllers/SettingsController.cs | 4 ++-- src/Api/Models/Response/DomainsResponseModel.cs | 13 ++++++++----- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/Api/Controllers/SettingsController.cs b/src/Api/Controllers/SettingsController.cs index bc360864db..4baa383eff 100644 --- a/src/Api/Controllers/SettingsController.cs +++ b/src/Api/Controllers/SettingsController.cs @@ -24,9 +24,9 @@ namespace Bit.Api.Controllers } [HttpGet("domains")] - public Task GetDomains() + public Task GetDomains(bool excluded = true) { - var response = new DomainsResponseModel(_currentContext.User); + var response = new DomainsResponseModel(_currentContext.User, excluded); return Task.FromResult(response); } diff --git a/src/Api/Models/Response/DomainsResponseModel.cs b/src/Api/Models/Response/DomainsResponseModel.cs index edc9b20a38..aaadee5098 100644 --- a/src/Api/Models/Response/DomainsResponseModel.cs +++ b/src/Api/Models/Response/DomainsResponseModel.cs @@ -9,7 +9,7 @@ namespace Bit.Api.Models { public class DomainsResponseModel : ResponseModel { - public DomainsResponseModel(User user) + public DomainsResponseModel(User user, bool excluded = true) : base("domains") { if(user == null) @@ -23,9 +23,11 @@ namespace Bit.Api.Models var excludedGlobalEquivalentDomains = user.ExcludedGlobalEquivalentDomains != null ? JsonConvert.DeserializeObject>(user.ExcludedGlobalEquivalentDomains) : null; var globalDomains = new List(); - foreach(var domain in Core.Utilities.EquivalentDomains.Global) + var domainsToInclude = excluded ? Core.Utilities.EquivalentDomains.Global : + Core.Utilities.EquivalentDomains.Global.Where(d => !excludedGlobalEquivalentDomains.Contains(d.Key)); + foreach(var domain in domainsToInclude) { - globalDomains.Add(new GlobalDomains(domain.Key, domain.Value, excludedGlobalEquivalentDomains)); + globalDomains.Add(new GlobalDomains(domain.Key, domain.Value, excludedGlobalEquivalentDomains, excluded)); } GlobalEquivalentDomains = !globalDomains.Any() ? null : globalDomains; } @@ -39,11 +41,12 @@ namespace Bit.Api.Models public GlobalDomains( GlobalEquivalentDomainsType globalDomain, IEnumerable domains, - IEnumerable excludedDomains) + IEnumerable excludedDomains, + bool excluded) { Type = globalDomain; Domains = domains; - Excluded = excludedDomains?.Contains(globalDomain) ?? false; + Excluded = excluded && (excludedDomains?.Contains(globalDomain) ?? false); } public GlobalEquivalentDomainsType Type { get; set; }