Skip to content

Commit

Permalink
fix: add lacked existing policy check when adding policy (#349)
Browse files Browse the repository at this point in the history
Signed-off-by: sagilio <[email protected]>
Co-authored-by: sagilio <[email protected]>
  • Loading branch information
sagilio0728 and sagilio committed Apr 5, 2024
1 parent 3306375 commit c13429d
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 partial class InternalEnforcerExtension
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 partial class InternalEnforcerExtension
}

bool ruleAdded = await policyManager.AddPolicyAsync(values);

if (ruleAdded is false)
{
return false;
Expand Down Expand Up @@ -104,7 +107,6 @@ internal static partial class InternalEnforcerExtension
}

bool ruleAdded = policyManager.AddPolicies(valuesList);

if (ruleAdded is false)
{
return false;
Expand Down Expand Up @@ -133,7 +135,6 @@ internal static partial class InternalEnforcerExtension
}

bool ruleAdded = await policyManager.AddPoliciesAsync(valuesList);

if (ruleAdded is false)
{
return false;
Expand Down Expand Up @@ -163,7 +164,6 @@ internal static partial class InternalEnforcerExtension
}

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

if (ruleUpdated is false)
{
return false;
Expand Down Expand Up @@ -193,7 +193,6 @@ internal static partial class InternalEnforcerExtension
}

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

if (ruleUpdated is false)
{
return false;
Expand Down Expand Up @@ -223,7 +222,6 @@ internal static partial class InternalEnforcerExtension
}

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

if (ruleUpdated is false)
{
return false;
Expand Down Expand Up @@ -253,7 +251,6 @@ internal static partial class InternalEnforcerExtension
}

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

if (ruleUpdated is false)
{
return false;
Expand Down Expand Up @@ -282,7 +279,6 @@ internal static partial class InternalEnforcerExtension
}

bool ruleRemoved = policyManager.RemovePolicy(values);

if (ruleRemoved is false)
{
return false;
Expand Down Expand Up @@ -310,7 +306,6 @@ internal static partial class InternalEnforcerExtension
}

bool ruleRemoved = await policyManager.RemovePolicyAsync(rule);

if (ruleRemoved is false)
{
return false;
Expand Down Expand Up @@ -338,7 +333,6 @@ internal static partial class InternalEnforcerExtension
}

bool ruleRemoved = policyManager.RemovePolicies(rules);

if (ruleRemoved is false)
{
return false;
Expand Down Expand Up @@ -366,7 +360,6 @@ internal static partial class InternalEnforcerExtension
}

bool ruleRemoved = await policyManager.RemovePoliciesAsync(rules);

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

0 comments on commit c13429d

Please sign in to comment.