diff --git a/NetCasbin/Abstractions/IEnforcer.cs b/NetCasbin/Abstractions/IEnforcer.cs
index ac1d0a61..2b82f9a2 100644
--- a/NetCasbin/Abstractions/IEnforcer.cs
+++ b/NetCasbin/Abstractions/IEnforcer.cs
@@ -34,7 +34,6 @@ public interface IEnforcer
public string ModelPath { get; }
public bool IsFiltered { get; }
-
public IExpressionHandler ExpressionHandler { get; }
///
diff --git a/NetCasbin/Abstractions/IPolicy.cs b/NetCasbin/Abstractions/IPolicy.cs
index 316f12cd..a781b339 100644
--- a/NetCasbin/Abstractions/IPolicy.cs
+++ b/NetCasbin/Abstractions/IPolicy.cs
@@ -56,7 +56,7 @@ public IEnumerable> GetFilteredPolicy(string section, string
public bool RemovePolicies(string section, string policyType, IEnumerable> rules);
- public bool RemoveFilteredPolicy(string section, string policyType, int fieldIndex, params string[] fieldValues);
+ public IEnumerable> RemoveFilteredPolicy(string section, string policyType, int fieldIndex, params string[] fieldValues);
public void ClearPolicy();
}
diff --git a/NetCasbin/Enforcer.cs b/NetCasbin/Enforcer.cs
index 662973ce..8b397711 100644
--- a/NetCasbin/Enforcer.cs
+++ b/NetCasbin/Enforcer.cs
@@ -18,9 +18,6 @@
namespace Casbin
{
- ///
- /// CoreEnforcer defines the core functionality of an enforcer.
- ///
public class Enforcer : IEnforcer
{
public Enforcer()
@@ -72,7 +69,6 @@ public Enforcer(IModel model, IAdapter adapter = null)
public string ModelPath { get; private set; }
public bool IsFiltered => Adapter is IFilteredAdapter {IsFiltered: true};
-
public IExpressionHandler ExpressionHandler { get; private set; }
#region Set options
@@ -379,6 +375,9 @@ public void ClearPolicy()
}
#endregion
+
+ #region Enforce method
+
///
/// Decides whether a "subject" can access a "object" with the operation
/// "action", input parameters are usually: (sub, obj, act).
@@ -812,5 +811,7 @@ private static string RewriteEval(string expressionString, IDictionary
///
- ///
- ///
+ ///
+ ///
///
///
- internal static bool InternalAddPolicy(this IEnforcer enforcer, string sec, string ptype, IEnumerable rule)
+ internal static bool InternalAddPolicy(this IEnforcer enforcer, string section, string policyType, IEnumerable rule)
{
- if (enforcer.Model.HasPolicy(sec, ptype, rule))
+ IEnumerable ruleArray = rule as string[] ?? rule.ToArray();
+ if (enforcer.Model.HasPolicy(section, policyType, ruleArray))
{
return false;
}
@@ -29,7 +30,7 @@ internal static bool InternalAddPolicy(this IEnforcer enforcer, string sec, stri
{
try
{
- enforcer.Adapter.AddPolicy(sec, ptype, rule);
+ enforcer.Adapter.AddPolicy(section, policyType, ruleArray);
}
catch (NotImplementedException)
{
@@ -37,21 +38,14 @@ internal static bool InternalAddPolicy(this IEnforcer enforcer, string sec, stri
}
}
- bool ruleAdded = enforcer.Model.AddPolicy(sec, ptype, rule);
+ bool ruleAdded = enforcer.Model.AddPolicy(section, policyType, ruleArray);
if (ruleAdded is false)
{
return false;
}
- if (sec.Equals(PermConstants.Section.RoleSection))
- {
- enforcer.Model.BuildIncrementalRoleLink(enforcer.RoleManager, PolicyOperation.PolicyAdd,
- sec, ptype, rule);
- enforcer.ExpressionHandler.SetGFunctions();
- }
-
- NotifyPolicyChanged(enforcer);
+ OnPolicyChanged(enforcer, PolicyOperation.PolicyAdd, section, policyType, ruleArray);
return true;
}
@@ -59,13 +53,14 @@ internal static bool InternalAddPolicy(this IEnforcer enforcer, string sec, stri
/// Adds a rule to the current policy.
///
///
- ///
- ///
+ ///
+ ///
///
///
- internal static async Task InternalAddPolicyAsync(this IEnforcer enforcer, string sec, string ptype, IEnumerable rule)
+ internal static async Task InternalAddPolicyAsync(this IEnforcer enforcer, string section, string policyType, IEnumerable rule)
{
- if (enforcer.Model.HasPolicy(sec, ptype, rule))
+ IEnumerable ruleArray = rule as string[] ?? rule.ToArray();
+ if (enforcer.Model.HasPolicy(section, policyType, ruleArray))
{
return false;
}
@@ -74,7 +69,7 @@ internal static async Task InternalAddPolicyAsync(this IEnforcer enforcer,
{
try
{
- await enforcer.Adapter.AddPolicyAsync(sec, ptype, rule);
+ await enforcer.Adapter.AddPolicyAsync(section, policyType, ruleArray);
}
catch (NotImplementedException)
{
@@ -82,21 +77,14 @@ internal static async Task InternalAddPolicyAsync(this IEnforcer enforcer,
}
}
- bool ruleAdded = enforcer.Model.AddPolicy(sec, ptype, rule);
+ bool ruleAdded = enforcer.Model.AddPolicy(section, policyType, ruleArray);
if (ruleAdded is false)
{
return false;
}
- if (sec.Equals(PermConstants.Section.RoleSection))
- {
- enforcer.Model.BuildIncrementalRoleLink(enforcer.RoleManager, PolicyOperation.PolicyAdd,
- sec, ptype, rule);
- enforcer.ExpressionHandler.SetGFunctions();
- }
-
- await NotifyPolicyChangedAsync(enforcer);
+ await OnPolicyAsyncChanged(enforcer, PolicyOperation.PolicyAdd, section, policyType, ruleArray);
return true;
}
@@ -104,15 +92,15 @@ internal static async Task InternalAddPolicyAsync(this IEnforcer enforcer,
/// Adds rules to the current policy.
///
///
- ///
- ///
+ ///
+ ///
///
///
- internal static bool InternalAddPolicies(this IEnforcer enforcer, string sec, string ptype, IEnumerable> rules)
+ internal static bool InternalAddPolicies(this IEnforcer enforcer, string section, string policyType, IEnumerable> rules)
{
var ruleArray = rules as IEnumerable[] ?? rules.ToArray();
- if (enforcer.Model.HasPolicies(sec, ptype, ruleArray))
+ if (enforcer.Model.HasPolicies(section, policyType, ruleArray))
{
return false;
}
@@ -121,7 +109,7 @@ internal static bool InternalAddPolicies(this IEnforcer enforcer, string sec, st
{
try
{
- enforcer.Adapter.AddPolicies(sec, ptype, ruleArray);
+ enforcer.Adapter.AddPolicies(section, policyType, ruleArray);
}
catch (NotImplementedException)
{
@@ -129,21 +117,14 @@ internal static bool InternalAddPolicies(this IEnforcer enforcer, string sec, st
}
}
- bool ruleAdded = enforcer.Model.AddPolicies(sec, ptype, ruleArray);
+ bool ruleAdded = enforcer.Model.AddPolicies(section, policyType, ruleArray);
if (ruleAdded is false)
{
return false;
}
- if (sec.Equals(PermConstants.Section.RoleSection))
- {
- enforcer.Model.BuildIncrementalRoleLinks(enforcer.RoleManager, PolicyOperation.PolicyAdd,
- sec, ptype, ruleArray);
- enforcer.ExpressionHandler.SetGFunctions();
- }
-
- NotifyPolicyChanged(enforcer);
+ OnPoliciesChanged(enforcer, PolicyOperation.PolicyAdd, section, policyType, ruleArray);
return true;
}
@@ -152,15 +133,15 @@ internal static bool InternalAddPolicies(this IEnforcer enforcer, string sec, st
/// Adds rules to the current policy.
///
///
- ///
- ///
+ ///
+ ///
///
///
- internal static async Task InternalAddPoliciesAsync(this IEnforcer enforcer, string sec, string ptype, IEnumerable> rules)
+ internal static async Task InternalAddPoliciesAsync(this IEnforcer enforcer, string section, string policyType, IEnumerable> rules)
{
- var ruleArray = rules as IEnumerable[] ?? rules.ToArray();
+ var rulesArray = rules as IEnumerable[] ?? rules.ToArray();
- if (enforcer.Model.HasPolicies(sec, ptype, ruleArray))
+ if (enforcer.Model.HasPolicies(section, policyType, rulesArray))
{
return false;
}
@@ -169,7 +150,7 @@ internal static async Task InternalAddPoliciesAsync(this IEnforcer enforce
{
try
{
- await enforcer.Adapter.AddPoliciesAsync(sec, ptype, ruleArray);
+ await enforcer.Adapter.AddPoliciesAsync(section, policyType, rulesArray);
}
catch (NotImplementedException)
{
@@ -177,21 +158,14 @@ internal static async Task InternalAddPoliciesAsync(this IEnforcer enforce
}
}
- bool ruleAdded = enforcer.Model.AddPolicies(sec, ptype, ruleArray);
+ bool ruleAdded = enforcer.Model.AddPolicies(section, policyType, rulesArray);
if (ruleAdded is false)
{
return false;
}
- if (sec.Equals(PermConstants.Section.RoleSection))
- {
- enforcer.Model.BuildIncrementalRoleLinks(enforcer.RoleManager, PolicyOperation.PolicyAdd,
- sec, ptype, ruleArray);
- enforcer.ExpressionHandler.SetGFunctions();
- }
-
- await NotifyPolicyChangedAsync(enforcer);
+ await OnPoliciesAsyncChanged(enforcer, PolicyOperation.PolicyAdd, section, policyType, rulesArray);
return true;
}
@@ -199,13 +173,14 @@ internal static async Task InternalAddPoliciesAsync(this IEnforcer enforce
/// Removes a rule from the current policy.
///
///
- ///
- ///
+ ///
+ ///
///
///
- internal static bool InternalRemovePolicy(this IEnforcer enforcer, string sec, string ptype, IEnumerable rule)
+ internal static bool InternalRemovePolicy(this IEnforcer enforcer, string section, string policyType, IEnumerable rule)
{
- if (enforcer.Model.HasPolicy(sec, ptype, rule) is false)
+ IEnumerable ruleArray = rule as string[] ?? rule.ToArray();
+ if (enforcer.Model.HasPolicy(section, policyType, ruleArray) is false)
{
return false;
}
@@ -214,7 +189,7 @@ internal static bool InternalRemovePolicy(this IEnforcer enforcer, string sec, s
{
try
{
- enforcer.Adapter.RemovePolicy(sec, ptype, rule);
+ enforcer.Adapter.RemovePolicy(section, policyType, ruleArray);
}
catch (NotImplementedException)
{
@@ -222,21 +197,14 @@ internal static bool InternalRemovePolicy(this IEnforcer enforcer, string sec, s
}
}
- bool ruleRemoved = enforcer.Model.RemovePolicy(sec, ptype, rule);
+ bool ruleRemoved = enforcer.Model.RemovePolicy(section, policyType, ruleArray);
if (ruleRemoved is false)
{
return false;
}
- if (sec.Equals(PermConstants.Section.RoleSection))
- {
- enforcer.Model.BuildIncrementalRoleLink(enforcer.RoleManager, PolicyOperation.PolicyRemove,
- sec, ptype, rule);
- enforcer.ExpressionHandler.SetGFunctions();
- }
-
- NotifyPolicyChanged(enforcer);
+ OnPoliciesChanged(enforcer, PolicyOperation.PolicyRemove, section, policyType, new [] {ruleArray});
return true;
}
@@ -244,13 +212,14 @@ internal static bool InternalRemovePolicy(this IEnforcer enforcer, string sec, s
/// Removes a rule from the current policy.
///
///
- ///
- ///
+ ///
+ ///
///
///
- internal static async Task InternalRemovePolicyAsync(this IEnforcer enforcer, string sec, string ptype, IEnumerable rule)
+ internal static async Task InternalRemovePolicyAsync(this IEnforcer enforcer, string section, string policyType, IEnumerable rule)
{
- if (enforcer.Model.HasPolicy(sec, ptype, rule) is false)
+ IEnumerable ruleArray = rule as string[] ?? rule.ToArray();
+ if (enforcer.Model.HasPolicy(section, policyType, ruleArray) is false)
{
return false;
}
@@ -259,7 +228,7 @@ internal static async Task InternalRemovePolicyAsync(this IEnforcer enforc
{
try
{
- await enforcer.Adapter.RemovePolicyAsync(sec, ptype, rule);
+ await enforcer.Adapter.RemovePolicyAsync(section, policyType, ruleArray);
}
catch (NotImplementedException)
{
@@ -267,21 +236,14 @@ internal static async Task InternalRemovePolicyAsync(this IEnforcer enforc
}
}
- bool ruleRemoved = enforcer.Model.RemovePolicy(sec, ptype, rule);
+ bool ruleRemoved = enforcer.Model.RemovePolicy(section, policyType, ruleArray);
if (ruleRemoved is false)
{
return false;
}
- if (sec.Equals(PermConstants.Section.RoleSection))
- {
- enforcer.Model.BuildIncrementalRoleLink(enforcer.RoleManager, PolicyOperation.PolicyRemove,
- sec, ptype, rule);
- enforcer.ExpressionHandler.SetGFunctions();
- }
-
- await NotifyPolicyChangedAsync(enforcer);
+ await OnPolicyAsyncChanged(enforcer, PolicyOperation.PolicyRemove, section, policyType, ruleArray);
return true;
}
@@ -289,15 +251,15 @@ internal static async Task InternalRemovePolicyAsync(this IEnforcer enforc
/// Removes rules from the current policy.
///
///
- ///
- ///
+ ///
+ ///
///
///
- internal static bool InternalRemovePolicies(this IEnforcer enforcer, string sec, string ptype, IEnumerable> rules)
+ internal static bool InternalRemovePolicies(this IEnforcer enforcer, string section, string policyType, IEnumerable> rules)
{
- var ruleArray = rules as IEnumerable[] ?? rules.ToArray();
+ var rulesArray = rules as IEnumerable[] ?? rules.ToArray();
- if (enforcer.Model.HasPolicies(sec, ptype, ruleArray) is false)
+ if (enforcer.Model.HasPolicies(section, policyType, rulesArray) is false)
{
return false;
}
@@ -306,7 +268,7 @@ internal static bool InternalRemovePolicies(this IEnforcer enforcer, string sec,
{
try
{
- enforcer.Adapter.RemovePolicies(sec, ptype, ruleArray);
+ enforcer.Adapter.RemovePolicies(section, policyType, rulesArray);
}
catch (NotImplementedException)
{
@@ -314,21 +276,14 @@ internal static bool InternalRemovePolicies(this IEnforcer enforcer, string sec,
}
}
- bool ruleRemoved = enforcer.Model.RemovePolicies(sec, ptype, ruleArray);
+ bool ruleRemoved = enforcer.Model.RemovePolicies(section, policyType, rulesArray);
if (ruleRemoved is false)
{
return false;
}
- if (sec.Equals(PermConstants.Section.RoleSection))
- {
- enforcer.Model.BuildIncrementalRoleLinks(enforcer.RoleManager, PolicyOperation.PolicyRemove,
- sec, ptype, ruleArray);
- enforcer.ExpressionHandler.SetGFunctions();
- }
-
- NotifyPolicyChanged(enforcer);
+ OnPoliciesChanged(enforcer, PolicyOperation.PolicyRemove, section, policyType, rulesArray);
return true;
}
@@ -336,15 +291,15 @@ internal static bool InternalRemovePolicies(this IEnforcer enforcer, string sec,
/// Removes rules from the current policy.
///
///
- ///
- ///
+ ///
+ ///
///
///
- internal static async Task InternalRemovePoliciesAsync(this IEnforcer enforcer, string sec, string ptype, IEnumerable> rules)
+ internal static async Task InternalRemovePoliciesAsync(this IEnforcer enforcer, string section, string policyType, IEnumerable> rules)
{
- var ruleArray = rules as IEnumerable[] ?? rules.ToArray();
+ var rulesArray = rules as IEnumerable[] ?? rules.ToArray();
- if (enforcer.Model.HasPolicies(sec, ptype, ruleArray) is false)
+ if (enforcer.Model.HasPolicies(section, policyType, rulesArray) is false)
{
return false;
}
@@ -353,7 +308,7 @@ internal static async Task InternalRemovePoliciesAsync(this IEnforcer enfo
{
try
{
- await enforcer.Adapter.RemovePoliciesAsync(sec, ptype, ruleArray);
+ await enforcer.Adapter.RemovePoliciesAsync(section, policyType, rulesArray);
}
catch (NotImplementedException)
{
@@ -361,21 +316,14 @@ internal static async Task InternalRemovePoliciesAsync(this IEnforcer enfo
}
}
- bool ruleRemoved = enforcer.Model.RemovePolicies(sec, ptype, ruleArray);
+ bool ruleRemoved = enforcer.Model.RemovePolicies(section, policyType, rulesArray);
if (ruleRemoved is false)
{
return false;
}
- if (sec.Equals(PermConstants.Section.RoleSection))
- {
- enforcer.Model.BuildIncrementalRoleLinks(enforcer.RoleManager, PolicyOperation.PolicyRemove,
- sec, ptype, ruleArray);
- enforcer.ExpressionHandler.SetGFunctions();
- }
-
- await NotifyPolicyChangedAsync(enforcer);
+ await OnPoliciesAsyncChanged(enforcer, PolicyOperation.PolicyRemove, section, policyType, rulesArray);
return true;
}
@@ -383,18 +331,18 @@ internal static async Task InternalRemovePoliciesAsync(this IEnforcer enfo
/// Removes rules based on field filters from the current policy.
///
///
- ///
- ///
+ ///
+ ///
///
///
///
- internal static bool InternalRemoveFilteredPolicy(this IEnforcer enforcer, string sec, string ptype, int fieldIndex, params string[] fieldValues)
+ internal static bool InternalRemoveFilteredPolicy(this IEnforcer enforcer, string section, string policyType, int fieldIndex, params string[] fieldValues)
{
if (enforcer.Adapter is not null && enforcer.AutoSave)
{
try
{
- enforcer.Adapter.RemoveFilteredPolicy(sec, ptype, fieldIndex, fieldValues);
+ enforcer.Adapter.RemoveFilteredPolicy(section, policyType, fieldIndex, fieldValues);
}
catch (NotImplementedException)
{
@@ -402,20 +350,14 @@ internal static bool InternalRemoveFilteredPolicy(this IEnforcer enforcer, strin
}
}
- bool ruleRemoved = enforcer.Model.RemoveFilteredPolicy(sec, ptype, fieldIndex, fieldValues);
+ var effectPolices = enforcer.Model.RemoveFilteredPolicy(section, policyType, fieldIndex, fieldValues);
- if (ruleRemoved is false)
+ if (effectPolices is null)
{
return false;
}
- if (sec.Equals(PermConstants.Section.RoleSection))
- {
- enforcer.BuildRoleLinks();
- enforcer.ExpressionHandler.SetGFunctions();
- }
-
- NotifyPolicyChanged(enforcer);
+ OnPoliciesChanged(enforcer, PolicyOperation.PolicyRemove, section, policyType, effectPolices);
return true;
}
@@ -423,18 +365,18 @@ internal static bool InternalRemoveFilteredPolicy(this IEnforcer enforcer, strin
/// Removes rules based on field filters from the current policy.
///
///
- ///
- ///
+ ///
+ ///
///
///
///
- internal static async Task InternalRemoveFilteredPolicyAsync(this IEnforcer enforcer, string sec, string ptype, int fieldIndex, params string[] fieldValues)
+ internal static async Task InternalRemoveFilteredPolicyAsync(this IEnforcer enforcer, string section, string policyType, int fieldIndex, params string[] fieldValues)
{
if (enforcer.Adapter is not null && enforcer.AutoSave)
{
try
{
- await enforcer.Adapter.RemoveFilteredPolicyAsync(sec, ptype, fieldIndex, fieldValues);
+ await enforcer.Adapter.RemoveFilteredPolicyAsync(section, policyType, fieldIndex, fieldValues);
}
catch (NotImplementedException)
{
@@ -442,21 +384,64 @@ internal static async Task InternalRemoveFilteredPolicyAsync(this IEnforce
}
}
- bool ruleRemoved = enforcer.Model.RemoveFilteredPolicy(sec, ptype, fieldIndex, fieldValues);
+ var effectPolicies = enforcer.Model.RemoveFilteredPolicy(section, policyType, fieldIndex, fieldValues);
- if (ruleRemoved is false)
+ if (effectPolicies is null)
{
return false;
}
- if (sec.Equals(PermConstants.Section.RoleSection))
+ await OnPoliciesAsyncChanged(enforcer, PolicyOperation.PolicyRemove, section, policyType, effectPolicies);
+ return true;
+ }
+
+ private static void OnPolicyChanged(IEnforcer enforcer, PolicyOperation policyOperation,
+ string section, string policyType, IEnumerable rule)
+ {
+ if (section.Equals(PermConstants.Section.RoleSection))
+ {
+ enforcer.Model.BuildIncrementalRoleLink(enforcer.RoleManager, policyOperation,
+ section, policyType, rule);
+ enforcer.ExpressionHandler.SetGFunctions();
+ }
+
+ NotifyPolicyChanged(enforcer);
+ }
+
+ private static async Task OnPolicyAsyncChanged(IEnforcer enforcer, PolicyOperation policyOperation,
+ string section, string policyType, IEnumerable rule)
+ {
+ if (section.Equals(PermConstants.Section.RoleSection))
{
- enforcer.BuildRoleLinks();
+ enforcer.Model.BuildIncrementalRoleLink(enforcer.RoleManager, policyOperation,
+ section, policyType, rule);
enforcer.ExpressionHandler.SetGFunctions();
}
+ await NotifyPolicyChangedAsync(enforcer);
+ }
+ private static void OnPoliciesChanged(IEnforcer enforcer, PolicyOperation policyOperation,
+ string section, string policyType, IEnumerable> rules)
+ {
+ if (section.Equals(PermConstants.Section.RoleSection))
+ {
+ enforcer.Model.BuildIncrementalRoleLinks(enforcer.RoleManager, policyOperation,
+ section, policyType, rules);
+ enforcer.ExpressionHandler.SetGFunctions();
+ }
+ NotifyPolicyChanged(enforcer);
+ }
+
+ private static async Task OnPoliciesAsyncChanged(IEnforcer enforcer, PolicyOperation policyOperation,
+ string section, string policyType, IEnumerable> rules)
+ {
+ if (section.Equals(PermConstants.Section.RoleSection))
+ {
+ enforcer.Model.BuildIncrementalRoleLinks(enforcer.RoleManager, policyOperation,
+ section, policyType, rules);
+ enforcer.ExpressionHandler.SetGFunctions();
+ }
await NotifyPolicyChangedAsync(enforcer);
- return true;
}
private static void NotifyPolicyChanged(IEnforcer enforcer)
diff --git a/NetCasbin/Extensions/RbacEnforcerEnxtension.cs b/NetCasbin/Extensions/RbacEnforcerExtension.cs
similarity index 99%
rename from NetCasbin/Extensions/RbacEnforcerEnxtension.cs
rename to NetCasbin/Extensions/RbacEnforcerExtension.cs
index c04f5f05..853c5a43 100644
--- a/NetCasbin/Extensions/RbacEnforcerEnxtension.cs
+++ b/NetCasbin/Extensions/RbacEnforcerExtension.cs
@@ -5,7 +5,7 @@
namespace Casbin.Extensions
{
- public static class RbacEnforcerEnxtension
+ public static class RbacEnforcerExtension
{
#region Get roles or users
diff --git a/NetCasbin/Model/Assertion.cs b/NetCasbin/Model/Assertion.cs
index f45dc476..0b1fb659 100644
--- a/NetCasbin/Model/Assertion.cs
+++ b/NetCasbin/Model/Assertion.cs
@@ -23,7 +23,7 @@ public class Assertion
public List> Policy { get; internal set; }
- private HashSet PolicyStringSet { get; }
+ internal HashSet PolicyStringSet { get; }
public Assertion()
{
diff --git a/NetCasbin/Model/DefaultPolicy.cs b/NetCasbin/Model/DefaultPolicy.cs
index feecad7c..4280b1c9 100644
--- a/NetCasbin/Model/DefaultPolicy.cs
+++ b/NetCasbin/Model/DefaultPolicy.cs
@@ -214,7 +214,7 @@ public bool RemovePolicies(string section, string policyType, IEnumerable> RemoveFilteredPolicy(string section, string policyType, int fieldIndex, params string[] fieldValues)
{
if (fieldValues == null)
{
@@ -223,11 +223,11 @@ public bool RemoveFilteredPolicy(string section, string policyType, int fieldInd
if (fieldValues.Length == 0 || fieldValues.All(string.IsNullOrWhiteSpace))
{
- return true;
+ return null;
}
var newPolicy = new List>();
- bool deleted = false;
+ List> effectPolicies = null;
Assertion assertion = Sections[section][policyType];
foreach (var rule in assertion.Policy)
@@ -241,7 +241,9 @@ public bool RemoveFilteredPolicy(string section, string policyType, int fieldInd
if (matched)
{
- deleted = true;
+ effectPolicies ??= new List>();
+ effectPolicies.Add(rule);
+ assertion.PolicyStringSet.Remove(Utility.RuleToString(rule));
}
else
{
@@ -250,8 +252,7 @@ public bool RemoveFilteredPolicy(string section, string policyType, int fieldInd
}
assertion.Policy = newPolicy;
- assertion.RefreshPolicyStringSet();
- return deleted;
+ return effectPolicies;
}
public IEnumerable GetValuesForFieldInPolicyAllTypes(string section, int fieldIndex)