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

added parameter for excluded

This commit is contained in:
Kyle Spearrin 2017-01-10 21:50:19 -05:00
parent ce036c5e16
commit 93cff6e283
2 changed files with 10 additions and 7 deletions

View File

@ -24,9 +24,9 @@ namespace Bit.Api.Controllers
} }
[HttpGet("domains")] [HttpGet("domains")]
public Task<DomainsResponseModel> GetDomains() public Task<DomainsResponseModel> GetDomains(bool excluded = true)
{ {
var response = new DomainsResponseModel(_currentContext.User); var response = new DomainsResponseModel(_currentContext.User, excluded);
return Task.FromResult(response); return Task.FromResult(response);
} }

View File

@ -9,7 +9,7 @@ namespace Bit.Api.Models
{ {
public class DomainsResponseModel : ResponseModel public class DomainsResponseModel : ResponseModel
{ {
public DomainsResponseModel(User user) public DomainsResponseModel(User user, bool excluded = true)
: base("domains") : base("domains")
{ {
if(user == null) if(user == null)
@ -23,9 +23,11 @@ namespace Bit.Api.Models
var excludedGlobalEquivalentDomains = user.ExcludedGlobalEquivalentDomains != null ? var excludedGlobalEquivalentDomains = user.ExcludedGlobalEquivalentDomains != null ?
JsonConvert.DeserializeObject<List<GlobalEquivalentDomainsType>>(user.ExcludedGlobalEquivalentDomains) : null; JsonConvert.DeserializeObject<List<GlobalEquivalentDomainsType>>(user.ExcludedGlobalEquivalentDomains) : null;
var globalDomains = new List<GlobalDomains>(); var globalDomains = new List<GlobalDomains>();
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; GlobalEquivalentDomains = !globalDomains.Any() ? null : globalDomains;
} }
@ -39,11 +41,12 @@ namespace Bit.Api.Models
public GlobalDomains( public GlobalDomains(
GlobalEquivalentDomainsType globalDomain, GlobalEquivalentDomainsType globalDomain,
IEnumerable<string> domains, IEnumerable<string> domains,
IEnumerable<GlobalEquivalentDomainsType> excludedDomains) IEnumerable<GlobalEquivalentDomainsType> excludedDomains,
bool excluded)
{ {
Type = globalDomain; Type = globalDomain;
Domains = domains; Domains = domains;
Excluded = excludedDomains?.Contains(globalDomain) ?? false; Excluded = excluded && (excludedDomains?.Contains(globalDomain) ?? false);
} }
public GlobalEquivalentDomainsType Type { get; set; } public GlobalEquivalentDomainsType Type { get; set; }