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 6193bbc
Showing 1 changed file with 5 additions and 12 deletions.
17 changes: 5 additions & 12 deletions Casbin/Extensions/Enforcer/InternalEnforcerExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,12 @@ internal static bool InternalAddPolicy(this IEnforcer enforcer, string section,
IPolicyValues values)
{
IPolicyManager policyManager = enforcer.Model.GetPolicyManager(section, policyType);
bool ruleAdded = policyManager.AddPolicy(values);
if (policyManager.HasPolicy(values))
{
return false;
}

bool ruleAdded = policyManager.AddPolicy(values);
if (ruleAdded is false)
{
return false;
Expand Down Expand Up @@ -76,7 +80,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 +107,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 +135,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 +164,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 +193,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 +222,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 +251,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 +279,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 +306,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 +333,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 +360,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 6193bbc

Please sign in to comment.