From b0a8c7b657502027e374a1f55f4d7d8a3220a848 Mon Sep 17 00:00:00 2001 From: liulifox233 Date: Fri, 3 Jan 2025 18:09:56 +0800 Subject: [PATCH 1/3] feat: change mut ref to ref in the parameters of get_roles_for_user and other similar functions. --- src/rbac_api.rs | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/rbac_api.rs b/src/rbac_api.rs index 1630b833..18f66547 100644 --- a/src/rbac_api.rs +++ b/src/rbac_api.rs @@ -66,7 +66,7 @@ pub trait RbacApi: MgmtApi { } fn get_roles_for_user( - &mut self, + &self, name: &str, domain: Option<&str>, ) -> Vec; @@ -76,7 +76,7 @@ pub trait RbacApi: MgmtApi { domain: Option<&str>, ) -> Vec; fn has_role_for_user( - &mut self, + &self, name: &str, role: &str, domain: Option<&str>, @@ -92,12 +92,12 @@ pub trait RbacApi: MgmtApi { permission: Vec, ) -> bool; fn get_implicit_roles_for_user( - &mut self, + &self, name: &str, domain: Option<&str>, ) -> Vec; fn get_implicit_permissions_for_user( - &mut self, + &self, name: &str, domain: Option<&str>, ) -> Vec>; @@ -212,14 +212,14 @@ where } fn get_roles_for_user( - &mut self, + &self, name: &str, domain: Option<&str>, ) -> Vec { 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); } } @@ -240,7 +240,7 @@ where } fn has_role_for_user( - &mut self, + &self, name: &str, role: &str, domain: Option<&str>, @@ -311,7 +311,7 @@ where } fn get_implicit_roles_for_user( - &mut self, + &self, name: &str, domain: Option<&str>, ) -> Vec { @@ -320,7 +320,7 @@ where while !q.is_empty() { let name = q.swap_remove(0); let roles = - self.get_role_manager().write().get_roles(&name, domain); + self.get_role_manager().read().get_roles(&name, domain); for r in roles.into_iter() { if res.insert(r.to_owned()) { q.push(r); @@ -331,7 +331,7 @@ where } fn get_implicit_permissions_for_user( - &mut self, + &self, user: &str, domain: Option<&str>, ) -> Vec> { From a9b08ae55e592a9c6219ea33ad5e343023f44b7b Mon Sep 17 00:00:00 2001 From: liulifox233 Date: Fri, 3 Jan 2025 18:18:57 +0800 Subject: [PATCH 2/3] fix: remove empty line after doc comments in enforce_with_context --- src/enforcer.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/enforcer.rs b/src/enforcer.rs index 7f87eae1..4a007dc9 100644 --- a/src/enforcer.rs +++ b/src/enforcer.rs @@ -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( &self, ctx: EnforceContext, From 62338dee14daaf7819c3da56c3a5852658784b78 Mon Sep 17 00:00:00 2001 From: liulifox233 Date: Fri, 3 Jan 2025 18:33:52 +0800 Subject: [PATCH 3/3] fix: fix cargo fmt check --- src/rbac_api.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/rbac_api.rs b/src/rbac_api.rs index 18f66547..57f224aa 100644 --- a/src/rbac_api.rs +++ b/src/rbac_api.rs @@ -319,8 +319,7 @@ where let mut q: Vec = vec![name.to_owned()]; while !q.is_empty() { let name = q.swap_remove(0); - let roles = - self.get_role_manager().read().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);