Skip to content

Commit

Permalink
feat: change mut ref to ref in the parameters of get_roles_for_user a…
Browse files Browse the repository at this point in the history
…nd other similar functions. (#356)

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

* fix: remove empty line after doc comments in enforce_with_context

* fix: fix cargo fmt check
  • Loading branch information
liulifox233 authored Jan 3, 2025
1 parent c5a05d3 commit d7c93e8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 14 deletions.
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 @@ pub trait RbacApi: MgmtApi {
}

fn get_roles_for_user(
&mut self,
&self,
name: &str,
domain: Option<&str>,
) -> Vec<String>;
Expand All @@ -76,7 +76,7 @@ pub trait RbacApi: MgmtApi {
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 @@ pub trait RbacApi: MgmtApi {
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 @@ where
}

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 @@ where
}

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

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 @@ where
}

fn get_implicit_permissions_for_user(
&mut self,
&self,
user: &str,
domain: Option<&str>,
) -> Vec<Vec<String>> {
Expand Down

0 comments on commit d7c93e8

Please sign in to comment.