Skip to content

Commit

Permalink
feat: handle deduplication in getFilter method for LDAPFilter
Browse files Browse the repository at this point in the history
  • Loading branch information
urangel committed Nov 17, 2023
1 parent 2cde9e5 commit 37438c1
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions src/CommonLib/LDAPQueries/LDAPFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -245,16 +245,23 @@ public LDAPFilter AddFilter(string filter, bool enforce)
/// <returns></returns>
public string GetFilter()
{
var temp = string.Join("", _filterParts.ToArray());
if (_filterParts.Count == 1)
temp = _filterParts[0];
else if (_filterParts.Count > 1)
temp = $"(|{temp})";

var mandatory = string.Join("", _mandatory.ToArray());
temp = _mandatory.Count > 0 ? $"(&{temp}{mandatory})" : temp;
var filterPartList = _filterParts.ToArray().Distinct();
var mandatoryList = _mandatory.ToArray().Distinct();

return temp;
var filterPartsExceptMandatory = filterPartList.Except(mandatoryList).ToList();

var filterPartsDistinct = string.Join("", filterPartsExceptMandatory);
var mandatoryDistinct = string.Join("", mandatoryList);

if (filterPartsExceptMandatory.Count == 1)
filterPartsDistinct = filterPartsExceptMandatory[0];
else if (filterPartsExceptMandatory.Count > 1)
filterPartsDistinct = $"(|{filterPartsDistinct})";

filterPartsDistinct = _mandatory.Count > 0 ? $"(&{filterPartsDistinct}{mandatoryDistinct})" : filterPartsDistinct;

return filterPartsDistinct;
}

public IEnumerable<string> GetFilterList()
Expand Down

0 comments on commit 37438c1

Please sign in to comment.