Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add lacked existing policy check when adding policy #349

Merged
merged 1 commit into from
Apr 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading