Skip to content

Commit

Permalink
fix: Add laked exist check when adding policy
Browse files Browse the repository at this point in the history
Signed-off-by: sagilio <[email protected]>
  • Loading branch information
sagilio committed Apr 4, 2024
1 parent 3306375 commit 0d291ec
Showing 1 changed file with 5 additions and 11 deletions.
16 changes: 5 additions & 11 deletions Casbin/Extensions/Enforcer/InternalEnforcerExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ internal static bool InternalAddPolicy(this IEnforcer enforcer, string section,
IPolicyValues values)
{
IPolicyManager policyManager = enforcer.Model.GetPolicyManager(section, policyType);
if (policyManager.HasPolicy(values))
{
return false;
}

bool ruleAdded = policyManager.AddPolicy(values);

if (ruleAdded is false)
Expand Down Expand Up @@ -76,7 +81,6 @@ internal static async Task<bool> InternalAddPolicyAsync(this IEnforcer enforcer,
}

bool ruleAdded = await policyManager.AddPolicyAsync(values);

if (ruleAdded is false)
{
return false;
Expand Down Expand Up @@ -104,7 +108,6 @@ internal static bool InternalAddPolicies(this IEnforcer enforcer, string section
}

bool ruleAdded = policyManager.AddPolicies(valuesList);

if (ruleAdded is false)
{
return false;
Expand Down Expand Up @@ -133,7 +136,6 @@ internal static async Task<bool> InternalAddPoliciesAsync(this IEnforcer enforce
}

bool ruleAdded = await policyManager.AddPoliciesAsync(valuesList);

if (ruleAdded is false)
{
return false;
Expand Down Expand Up @@ -163,7 +165,6 @@ internal static bool InternalUpdatePolicy(this IEnforcer enforcer, string sectio
}

bool ruleUpdated = policyManager.UpdatePolicy(oldValues, newValues);

if (ruleUpdated is false)
{
return false;
Expand Down Expand Up @@ -193,7 +194,6 @@ internal static async Task<bool> InternalUpdatePolicyAsync(this IEnforcer enforc
}

bool ruleUpdated = await policyManager.UpdatePolicyAsync(oldValues, newValues);

if (ruleUpdated is false)
{
return false;
Expand Down Expand Up @@ -223,7 +223,6 @@ internal static bool InternalUpdatePolicies(this IEnforcer enforcer, string sect
}

bool ruleUpdated = policyManager.UpdatePolicies(oldValuesList, newValuesList);

if (ruleUpdated is false)
{
return false;
Expand Down Expand Up @@ -253,7 +252,6 @@ internal static async Task<bool> InternalUpdatePoliciesAsync(this IEnforcer enfo
}

bool ruleUpdated = await policyManager.UpdatePoliciesAsync(oldValuesList, newValuesList);

if (ruleUpdated is false)
{
return false;
Expand Down Expand Up @@ -282,7 +280,6 @@ internal static bool InternalRemovePolicy(this IEnforcer enforcer, string sectio
}

bool ruleRemoved = policyManager.RemovePolicy(values);

if (ruleRemoved is false)
{
return false;
Expand Down Expand Up @@ -310,7 +307,6 @@ internal static async Task<bool> InternalRemovePolicyAsync(this IEnforcer enforc
}

bool ruleRemoved = await policyManager.RemovePolicyAsync(rule);

if (ruleRemoved is false)
{
return false;
Expand Down Expand Up @@ -338,7 +334,6 @@ internal static bool InternalRemovePolicies(this IEnforcer enforcer, string sect
}

bool ruleRemoved = policyManager.RemovePolicies(rules);

if (ruleRemoved is false)
{
return false;
Expand Down Expand Up @@ -366,7 +361,6 @@ internal static async Task<bool> InternalRemovePoliciesAsync(this IEnforcer enfo
}

bool ruleRemoved = await policyManager.RemovePoliciesAsync(rules);

if (ruleRemoved is false)
{
return false;
Expand Down

0 comments on commit 0d291ec

Please sign in to comment.