Skip to content

Commit d7c93e8

Browse files
authored
feat: change mut ref to ref in the parameters of get_roles_for_user and 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
1 parent c5a05d3 commit d7c93e8

File tree

2 files changed

+12
-14
lines changed

2 files changed

+12
-14
lines changed

src/enforcer.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -628,7 +628,6 @@ impl CoreApi for Enforcer {
628628
/// #[cfg(all(not(feature = "runtime-async-std"), not(feature = "runtime-tokio")))]
629629
/// fn main() {}
630630
/// ```
631-
632631
fn enforce_with_context<ARGS: EnforceArgs>(
633632
&self,
634633
ctx: EnforceContext,

src/rbac_api.rs

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ pub trait RbacApi: MgmtApi {
6666
}
6767

6868
fn get_roles_for_user(
69-
&mut self,
69+
&self,
7070
name: &str,
7171
domain: Option<&str>,
7272
) -> Vec<String>;
@@ -76,7 +76,7 @@ pub trait RbacApi: MgmtApi {
7676
domain: Option<&str>,
7777
) -> Vec<String>;
7878
fn has_role_for_user(
79-
&mut self,
79+
&self,
8080
name: &str,
8181
role: &str,
8282
domain: Option<&str>,
@@ -92,12 +92,12 @@ pub trait RbacApi: MgmtApi {
9292
permission: Vec<String>,
9393
) -> bool;
9494
fn get_implicit_roles_for_user(
95-
&mut self,
95+
&self,
9696
name: &str,
9797
domain: Option<&str>,
9898
) -> Vec<String>;
9999
fn get_implicit_permissions_for_user(
100-
&mut self,
100+
&self,
101101
name: &str,
102102
domain: Option<&str>,
103103
) -> Vec<Vec<String>>;
@@ -212,14 +212,14 @@ where
212212
}
213213

214214
fn get_roles_for_user(
215-
&mut self,
215+
&self,
216216
name: &str,
217217
domain: Option<&str>,
218218
) -> Vec<String> {
219219
let mut roles = vec![];
220-
if let Some(t1) = self.get_mut_model().get_mut_model().get_mut("g") {
221-
if let Some(t2) = t1.get_mut("g") {
222-
roles = t2.rm.write().get_roles(name, domain);
220+
if let Some(t1) = self.get_model().get_model().get("g") {
221+
if let Some(t2) = t1.get("g") {
222+
roles = t2.rm.read().get_roles(name, domain);
223223
}
224224
}
225225

@@ -240,7 +240,7 @@ where
240240
}
241241

242242
fn has_role_for_user(
243-
&mut self,
243+
&self,
244244
name: &str,
245245
role: &str,
246246
domain: Option<&str>,
@@ -311,16 +311,15 @@ where
311311
}
312312

313313
fn get_implicit_roles_for_user(
314-
&mut self,
314+
&self,
315315
name: &str,
316316
domain: Option<&str>,
317317
) -> Vec<String> {
318318
let mut res: HashSet<String> = HashSet::new();
319319
let mut q: Vec<String> = vec![name.to_owned()];
320320
while !q.is_empty() {
321321
let name = q.swap_remove(0);
322-
let roles =
323-
self.get_role_manager().write().get_roles(&name, domain);
322+
let roles = self.get_role_manager().read().get_roles(&name, domain);
324323
for r in roles.into_iter() {
325324
if res.insert(r.to_owned()) {
326325
q.push(r);
@@ -331,7 +330,7 @@ where
331330
}
332331

333332
fn get_implicit_permissions_for_user(
334-
&mut self,
333+
&self,
335334
user: &str,
336335
domain: Option<&str>,
337336
) -> Vec<Vec<String>> {

0 commit comments

Comments
 (0)