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

feat: change mut ref to ref in the parameters of get_roles_for_user and other similar functions. #356

Merged
merged 3 commits into from
Jan 3, 2025
Merged
Show file tree
Hide file tree
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
1 change: 0 additions & 1 deletion src/enforcer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -628,7 +628,6 @@ impl CoreApi for Enforcer {
/// #[cfg(all(not(feature = "runtime-async-std"), not(feature = "runtime-tokio")))]
/// fn main() {}
/// ```

fn enforce_with_context<ARGS: EnforceArgs>(
&self,
ctx: EnforceContext,
Expand Down
25 changes: 12 additions & 13 deletions src/rbac_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
}

fn get_roles_for_user(
&mut self,
&self,
name: &str,
domain: Option<&str>,
) -> Vec<String>;
Expand All @@ -76,7 +76,7 @@
domain: Option<&str>,
) -> Vec<String>;
fn has_role_for_user(
&mut self,
&self,
name: &str,
role: &str,
domain: Option<&str>,
Expand All @@ -92,12 +92,12 @@
permission: Vec<String>,
) -> bool;
fn get_implicit_roles_for_user(
&mut self,
&self,
name: &str,
domain: Option<&str>,
) -> Vec<String>;
fn get_implicit_permissions_for_user(
&mut self,
&self,
name: &str,
domain: Option<&str>,
) -> Vec<Vec<String>>;
Expand Down Expand Up @@ -212,14 +212,14 @@
}

fn get_roles_for_user(
&mut self,
&self,
name: &str,
domain: Option<&str>,
) -> Vec<String> {
let mut roles = vec![];
if let Some(t1) = self.get_mut_model().get_mut_model().get_mut("g") {
if let Some(t2) = t1.get_mut("g") {
roles = t2.rm.write().get_roles(name, domain);
if let Some(t1) = self.get_model().get_model().get("g") {
if let Some(t2) = t1.get("g") {
roles = t2.rm.read().get_roles(name, domain);
}
}

Expand All @@ -240,7 +240,7 @@
}

fn has_role_for_user(
&mut self,
&self,
name: &str,
role: &str,
domain: Option<&str>,
Expand Down Expand Up @@ -311,16 +311,15 @@
}

fn get_implicit_roles_for_user(
&mut self,
&self,
name: &str,
domain: Option<&str>,
) -> Vec<String> {
let mut res: HashSet<String> = HashSet::new();
let mut q: Vec<String> = vec![name.to_owned()];
while !q.is_empty() {
let name = q.swap_remove(0);
let roles =
self.get_role_manager().write().get_roles(&name, domain);
let roles = self.get_role_manager().read().get_roles(&name, domain);
for r in roles.into_iter() {
if res.insert(r.to_owned()) {
q.push(r);
Expand All @@ -331,7 +330,7 @@
}

fn get_implicit_permissions_for_user(
&mut self,
&self,
user: &str,
domain: Option<&str>,
) -> Vec<Vec<String>> {
Expand Down Expand Up @@ -908,7 +907,7 @@

let adapter =
FileAdapter::new("examples/rbac_with_hierarchy_policy.csv");
let mut e = Enforcer::new(m, adapter).await.unwrap();

Check warning on line 910 in src/rbac_api.rs

View workflow job for this annotation

GitHub Actions / Auto Build CI (ubuntu-latest, beta)

variable does not need to be mutable

Check warning on line 910 in src/rbac_api.rs

View workflow job for this annotation

GitHub Actions / Auto Build CI (ubuntu-latest, beta)

variable does not need to be mutable

Check warning on line 910 in src/rbac_api.rs

View workflow job for this annotation

GitHub Actions / Auto Build CI (ubuntu-latest, stable)

variable does not need to be mutable

Check warning on line 910 in src/rbac_api.rs

View workflow job for this annotation

GitHub Actions / Auto Build CI (ubuntu-latest, stable)

variable does not need to be mutable

Check warning on line 910 in src/rbac_api.rs

View workflow job for this annotation

GitHub Actions / Auto Build CI (windows-latest, beta)

variable does not need to be mutable

Check warning on line 910 in src/rbac_api.rs

View workflow job for this annotation

GitHub Actions / Auto Build CI (windows-latest, beta)

variable does not need to be mutable

Check warning on line 910 in src/rbac_api.rs

View workflow job for this annotation

GitHub Actions / Auto Build CI (windows-latest, stable)

variable does not need to be mutable

Check warning on line 910 in src/rbac_api.rs

View workflow job for this annotation

GitHub Actions / Auto Build CI (windows-latest, stable)

variable does not need to be mutable

Check warning on line 910 in src/rbac_api.rs

View workflow job for this annotation

GitHub Actions / Auto Build CI (macOS-latest, beta)

variable does not need to be mutable

Check warning on line 910 in src/rbac_api.rs

View workflow job for this annotation

GitHub Actions / Auto Build CI (macOS-latest, beta)

variable does not need to be mutable

Check warning on line 910 in src/rbac_api.rs

View workflow job for this annotation

GitHub Actions / Auto Build CI (macOS-latest, stable)

variable does not need to be mutable

Check warning on line 910 in src/rbac_api.rs

View workflow job for this annotation

GitHub Actions / Auto Build CI (macOS-latest, stable)

variable does not need to be mutable

assert_eq!(
vec![vec!["alice", "data1", "read"]],
Expand Down Expand Up @@ -945,7 +944,7 @@

let adapter =
FileAdapter::new("examples/rbac_with_hierarchy_policy.csv");
let mut e = Enforcer::new(m, adapter).await.unwrap();

Check warning on line 947 in src/rbac_api.rs

View workflow job for this annotation

GitHub Actions / Auto Build CI (ubuntu-latest, beta)

variable does not need to be mutable

Check warning on line 947 in src/rbac_api.rs

View workflow job for this annotation

GitHub Actions / Auto Build CI (ubuntu-latest, beta)

variable does not need to be mutable

Check warning on line 947 in src/rbac_api.rs

View workflow job for this annotation

GitHub Actions / Auto Build CI (ubuntu-latest, stable)

variable does not need to be mutable

Check warning on line 947 in src/rbac_api.rs

View workflow job for this annotation

GitHub Actions / Auto Build CI (ubuntu-latest, stable)

variable does not need to be mutable

Check warning on line 947 in src/rbac_api.rs

View workflow job for this annotation

GitHub Actions / Auto Build CI (windows-latest, beta)

variable does not need to be mutable

Check warning on line 947 in src/rbac_api.rs

View workflow job for this annotation

GitHub Actions / Auto Build CI (windows-latest, beta)

variable does not need to be mutable

Check warning on line 947 in src/rbac_api.rs

View workflow job for this annotation

GitHub Actions / Auto Build CI (windows-latest, stable)

variable does not need to be mutable

Check warning on line 947 in src/rbac_api.rs

View workflow job for this annotation

GitHub Actions / Auto Build CI (windows-latest, stable)

variable does not need to be mutable

Check warning on line 947 in src/rbac_api.rs

View workflow job for this annotation

GitHub Actions / Auto Build CI (macOS-latest, beta)

variable does not need to be mutable

Check warning on line 947 in src/rbac_api.rs

View workflow job for this annotation

GitHub Actions / Auto Build CI (macOS-latest, beta)

variable does not need to be mutable

Check warning on line 947 in src/rbac_api.rs

View workflow job for this annotation

GitHub Actions / Auto Build CI (macOS-latest, stable)

variable does not need to be mutable

Check warning on line 947 in src/rbac_api.rs

View workflow job for this annotation

GitHub Actions / Auto Build CI (macOS-latest, stable)

variable does not need to be mutable

assert_eq!(
vec![vec!["alice", "data1", "read"]],
Expand Down Expand Up @@ -1052,7 +1051,7 @@
let adapter = FileAdapter::new(
"examples/rbac_with_hierarchy_with_domains_policy.csv",
);
let mut e = Enforcer::new(m, adapter).await.unwrap();

Check warning on line 1054 in src/rbac_api.rs

View workflow job for this annotation

GitHub Actions / Auto Build CI (ubuntu-latest, beta)

variable does not need to be mutable

Check warning on line 1054 in src/rbac_api.rs

View workflow job for this annotation

GitHub Actions / Auto Build CI (ubuntu-latest, beta)

variable does not need to be mutable

Check warning on line 1054 in src/rbac_api.rs

View workflow job for this annotation

GitHub Actions / Auto Build CI (ubuntu-latest, stable)

variable does not need to be mutable

Check warning on line 1054 in src/rbac_api.rs

View workflow job for this annotation

GitHub Actions / Auto Build CI (ubuntu-latest, stable)

variable does not need to be mutable

Check warning on line 1054 in src/rbac_api.rs

View workflow job for this annotation

GitHub Actions / Auto Build CI (windows-latest, beta)

variable does not need to be mutable

Check warning on line 1054 in src/rbac_api.rs

View workflow job for this annotation

GitHub Actions / Auto Build CI (windows-latest, beta)

variable does not need to be mutable

Check warning on line 1054 in src/rbac_api.rs

View workflow job for this annotation

GitHub Actions / Auto Build CI (windows-latest, stable)

variable does not need to be mutable

Check warning on line 1054 in src/rbac_api.rs

View workflow job for this annotation

GitHub Actions / Auto Build CI (windows-latest, stable)

variable does not need to be mutable

Check warning on line 1054 in src/rbac_api.rs

View workflow job for this annotation

GitHub Actions / Auto Build CI (macOS-latest, beta)

variable does not need to be mutable

Check warning on line 1054 in src/rbac_api.rs

View workflow job for this annotation

GitHub Actions / Auto Build CI (macOS-latest, beta)

variable does not need to be mutable

Check warning on line 1054 in src/rbac_api.rs

View workflow job for this annotation

GitHub Actions / Auto Build CI (macOS-latest, stable)

variable does not need to be mutable

Check warning on line 1054 in src/rbac_api.rs

View workflow job for this annotation

GitHub Actions / Auto Build CI (macOS-latest, stable)

variable does not need to be mutable

assert_eq!(
vec![
Expand All @@ -1076,7 +1075,7 @@
tokio::test
)]
async fn test_pattern_matching_fn() {
let mut e = Enforcer::new(

Check warning on line 1078 in src/rbac_api.rs

View workflow job for this annotation

GitHub Actions / Auto Build CI (ubuntu-latest, beta)

variable does not need to be mutable

Check warning on line 1078 in src/rbac_api.rs

View workflow job for this annotation

GitHub Actions / Auto Build CI (ubuntu-latest, beta)

variable does not need to be mutable

Check warning on line 1078 in src/rbac_api.rs

View workflow job for this annotation

GitHub Actions / Auto Build CI (ubuntu-latest, stable)

variable does not need to be mutable

Check warning on line 1078 in src/rbac_api.rs

View workflow job for this annotation

GitHub Actions / Auto Build CI (ubuntu-latest, stable)

variable does not need to be mutable

Check warning on line 1078 in src/rbac_api.rs

View workflow job for this annotation

GitHub Actions / Auto Build CI (windows-latest, beta)

variable does not need to be mutable

Check warning on line 1078 in src/rbac_api.rs

View workflow job for this annotation

GitHub Actions / Auto Build CI (windows-latest, beta)

variable does not need to be mutable

Check warning on line 1078 in src/rbac_api.rs

View workflow job for this annotation

GitHub Actions / Auto Build CI (windows-latest, stable)

variable does not need to be mutable

Check warning on line 1078 in src/rbac_api.rs

View workflow job for this annotation

GitHub Actions / Auto Build CI (windows-latest, stable)

variable does not need to be mutable

Check warning on line 1078 in src/rbac_api.rs

View workflow job for this annotation

GitHub Actions / Auto Build CI (macOS-latest, beta)

variable does not need to be mutable

Check warning on line 1078 in src/rbac_api.rs

View workflow job for this annotation

GitHub Actions / Auto Build CI (macOS-latest, beta)

variable does not need to be mutable

Check warning on line 1078 in src/rbac_api.rs

View workflow job for this annotation

GitHub Actions / Auto Build CI (macOS-latest, stable)

variable does not need to be mutable

Check warning on line 1078 in src/rbac_api.rs

View workflow job for this annotation

GitHub Actions / Auto Build CI (macOS-latest, stable)

variable does not need to be mutable
"examples/rbac_with_pattern_model.conf",
"examples/rbac_with_pattern_policy.csv",
)
Expand Down Expand Up @@ -1121,7 +1120,7 @@
tokio::test
)]
async fn test_pattern_matching_fn_with_domain() {
let mut e = Enforcer::new(

Check warning on line 1123 in src/rbac_api.rs

View workflow job for this annotation

GitHub Actions / Auto Build CI (ubuntu-latest, beta)

variable does not need to be mutable

Check warning on line 1123 in src/rbac_api.rs

View workflow job for this annotation

GitHub Actions / Auto Build CI (ubuntu-latest, beta)

variable does not need to be mutable

Check warning on line 1123 in src/rbac_api.rs

View workflow job for this annotation

GitHub Actions / Auto Build CI (ubuntu-latest, stable)

variable does not need to be mutable

Check warning on line 1123 in src/rbac_api.rs

View workflow job for this annotation

GitHub Actions / Auto Build CI (ubuntu-latest, stable)

variable does not need to be mutable

Check warning on line 1123 in src/rbac_api.rs

View workflow job for this annotation

GitHub Actions / Auto Build CI (windows-latest, beta)

variable does not need to be mutable

Check warning on line 1123 in src/rbac_api.rs

View workflow job for this annotation

GitHub Actions / Auto Build CI (windows-latest, beta)

variable does not need to be mutable

Check warning on line 1123 in src/rbac_api.rs

View workflow job for this annotation

GitHub Actions / Auto Build CI (windows-latest, stable)

variable does not need to be mutable

Check warning on line 1123 in src/rbac_api.rs

View workflow job for this annotation

GitHub Actions / Auto Build CI (windows-latest, stable)

variable does not need to be mutable

Check warning on line 1123 in src/rbac_api.rs

View workflow job for this annotation

GitHub Actions / Auto Build CI (macOS-latest, beta)

variable does not need to be mutable

Check warning on line 1123 in src/rbac_api.rs

View workflow job for this annotation

GitHub Actions / Auto Build CI (macOS-latest, beta)

variable does not need to be mutable

Check warning on line 1123 in src/rbac_api.rs

View workflow job for this annotation

GitHub Actions / Auto Build CI (macOS-latest, stable)

variable does not need to be mutable

Check warning on line 1123 in src/rbac_api.rs

View workflow job for this annotation

GitHub Actions / Auto Build CI (macOS-latest, stable)

variable does not need to be mutable
"examples/rbac_with_pattern_domain_model.conf",
"examples/rbac_with_pattern_domain_policy.csv",
)
Expand Down Expand Up @@ -1165,7 +1164,7 @@
tokio::test
)]
async fn test_pattern_matching_basic_role() {
let mut e = Enforcer::new(

Check warning on line 1167 in src/rbac_api.rs

View workflow job for this annotation

GitHub Actions / Auto Build CI (ubuntu-latest, beta)

variable does not need to be mutable

Check warning on line 1167 in src/rbac_api.rs

View workflow job for this annotation

GitHub Actions / Auto Build CI (ubuntu-latest, beta)

variable does not need to be mutable

Check warning on line 1167 in src/rbac_api.rs

View workflow job for this annotation

GitHub Actions / Auto Build CI (ubuntu-latest, stable)

variable does not need to be mutable

Check warning on line 1167 in src/rbac_api.rs

View workflow job for this annotation

GitHub Actions / Auto Build CI (ubuntu-latest, stable)

variable does not need to be mutable

Check warning on line 1167 in src/rbac_api.rs

View workflow job for this annotation

GitHub Actions / Auto Build CI (windows-latest, beta)

variable does not need to be mutable

Check warning on line 1167 in src/rbac_api.rs

View workflow job for this annotation

GitHub Actions / Auto Build CI (windows-latest, beta)

variable does not need to be mutable

Check warning on line 1167 in src/rbac_api.rs

View workflow job for this annotation

GitHub Actions / Auto Build CI (windows-latest, stable)

variable does not need to be mutable

Check warning on line 1167 in src/rbac_api.rs

View workflow job for this annotation

GitHub Actions / Auto Build CI (windows-latest, stable)

variable does not need to be mutable

Check warning on line 1167 in src/rbac_api.rs

View workflow job for this annotation

GitHub Actions / Auto Build CI (macOS-latest, beta)

variable does not need to be mutable

Check warning on line 1167 in src/rbac_api.rs

View workflow job for this annotation

GitHub Actions / Auto Build CI (macOS-latest, beta)

variable does not need to be mutable

Check warning on line 1167 in src/rbac_api.rs

View workflow job for this annotation

GitHub Actions / Auto Build CI (macOS-latest, stable)

variable does not need to be mutable

Check warning on line 1167 in src/rbac_api.rs

View workflow job for this annotation

GitHub Actions / Auto Build CI (macOS-latest, stable)

variable does not need to be mutable
"examples/rbac_basic_role_model.conf",
"examples/rbac_basic_role_policy.csv",
)
Expand Down
Loading