Skip to content

Commit 90d1ed3

Browse files
committed
updates: coderabbit suggestions
1 parent 6d716ce commit 90d1ed3

File tree

3 files changed

+26
-141
lines changed

3 files changed

+26
-141
lines changed

src/handlers/http/modal/query/querier_rbac.rs

Lines changed: 0 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -40,55 +40,6 @@ use crate::{
4040
// async aware lock for updating storage metadata and user map atomically
4141
static UPDATE_LOCK: Mutex<()> = Mutex::const_new(());
4242

43-
// // Handler for POST /api/v1/user/{username}
44-
// // Creates a new user by username if it does not exists
45-
// pub async fn post_user(
46-
// username: web::Path<String>,
47-
// body: Option<web::Json<serde_json::Value>>,
48-
// ) -> Result<impl Responder, RBACError> {
49-
// let username = username.into_inner();
50-
51-
// let mut metadata = get_metadata().await?;
52-
53-
// validator::user_name(&username)?;
54-
// let roles: HashSet<String> = if let Some(body) = body {
55-
// serde_json::from_value(body.into_inner())?
56-
// } else {
57-
// return Err(RBACError::RoleValidationError);
58-
// };
59-
60-
// if roles.is_empty() {
61-
// return Err(RBACError::RoleValidationError);
62-
// }
63-
// let _ = UPDATE_LOCK.lock().await;
64-
// if Users.contains(&username)
65-
// || metadata
66-
// .users
67-
// .iter()
68-
// .any(|user| user.username() == username)
69-
// {
70-
// return Err(RBACError::UserExists);
71-
// }
72-
73-
// let (user, password) = user::User::new_basic(username.clone());
74-
75-
// metadata.users.push(user.clone());
76-
77-
// put_metadata(&metadata).await?;
78-
// let created_role = roles.clone();
79-
// Users.put_user(user.clone());
80-
81-
// sync_user_creation_with_ingestors(user, &Some(roles)).await?;
82-
83-
// put_role(
84-
// web::Path::<String>::from(username.clone()),
85-
// web::Json(created_role),
86-
// )
87-
// .await?;
88-
89-
// Ok(password)
90-
// }
91-
9243
// Handler for POST /api/v1/user/{username}
9344
// Creates a new user by username if it does not exists
9445
pub async fn post_user(
@@ -206,40 +157,6 @@ pub async fn delete_user(username: web::Path<String>) -> Result<impl Responder,
206157
Ok(format!("deleted user: {username}"))
207158
}
208159

209-
// // Handler PUT /user/{username}/roles => Put roles for user
210-
// // Put roles for given user
211-
// pub async fn put_role(
212-
// username: web::Path<String>,
213-
// role: web::Json<HashSet<String>>,
214-
// ) -> Result<String, RBACError> {
215-
// let username = username.into_inner();
216-
// let role = role.into_inner();
217-
218-
// if !Users.contains(&username) {
219-
// return Err(RBACError::UserDoesNotExist);
220-
// };
221-
// // update parseable.json first
222-
// let mut metadata = get_metadata().await?;
223-
// if let Some(user) = metadata
224-
// .users
225-
// .iter_mut()
226-
// .find(|user| user.username() == username)
227-
// {
228-
// user.roles.clone_from(&role);
229-
// } else {
230-
// // should be unreachable given state is always consistent
231-
// return Err(RBACError::UserDoesNotExist);
232-
// }
233-
234-
// put_metadata(&metadata).await?;
235-
// // update in mem table
236-
// Users.put_role(&username.clone(), role.clone());
237-
238-
// sync_users_with_roles_with_ingestors(&username, &role).await?;
239-
240-
// Ok(format!("Roles updated successfully for {username}"))
241-
// }
242-
243160
// Handler PATCH /user/{username}/role/add => Add roles to a user
244161
pub async fn add_roles_to_user(
245162
username: web::Path<String>,

src/handlers/http/rbac.rs

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -278,38 +278,6 @@ pub async fn delete_user(username: web::Path<String>) -> Result<impl Responder,
278278
Ok(format!("deleted user: {username}"))
279279
}
280280

281-
// // Handler PUT /user/{username}/roles => Put roles for user
282-
// // Put roles for given user
283-
// pub async fn put_role(
284-
// username: web::Path<String>,
285-
// role: web::Json<HashSet<String>>,
286-
// ) -> Result<String, RBACError> {
287-
// let username = username.into_inner();
288-
// let role = role.into_inner();
289-
290-
// if !Users.contains(&username) {
291-
// return Err(RBACError::UserDoesNotExist);
292-
// };
293-
// // update parseable.json first
294-
// let mut metadata = get_metadata().await?;
295-
// if let Some(user) = metadata
296-
// .users
297-
// .iter_mut()
298-
// .find(|user| user.username() == username)
299-
// {
300-
// user.roles.clone_from(&role);
301-
// } else {
302-
// // should be unreachable given state is always consistent
303-
// return Err(RBACError::UserDoesNotExist);
304-
// }
305-
306-
// put_metadata(&metadata).await?;
307-
// // update in mem table
308-
// Users.add_roles(&username.clone(), role.clone());
309-
310-
// Ok(format!("Roles updated successfully for {username}"))
311-
// }
312-
313281
// Handler PATCH /user/{username}/role/add => Add roles to a user
314282
pub async fn add_roles_to_user(
315283
username: web::Path<String>,

src/rbac/map.rs

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -226,32 +226,32 @@ impl Sessions {
226226
) -> Option<Response> {
227227
self.active_sessions.get(key).map(|(username, perms)| {
228228
// if user is a part of any user groups, then add permissions
229-
let perms: HashSet<Permission> =
230-
if !users().0.get(username).unwrap().user_groups.is_empty() {
231-
let groups = users().0.get(username).unwrap().user_groups.clone();
232-
let all_groups_roles = groups
233-
.iter()
234-
.filter(|id| (read_user_groups().0.contains_key(*id)))
235-
.map(|id| read_user_groups().0.get(id).unwrap().roles.clone())
236-
.reduce(|mut acc, e| {
237-
acc.extend(e);
238-
acc
239-
})
240-
.unwrap_or_default();
241-
let mut privilege_list = Vec::new();
242-
all_groups_roles
243-
.iter()
244-
.filter_map(|role| roles().get(role).cloned())
245-
.for_each(|privileges| privilege_list.extend(privileges));
246-
247-
let mut perms = HashSet::from_iter(perms.clone());
248-
for privs in privilege_list {
249-
perms.extend(RoleBuilder::from(&privs).build())
250-
}
251-
perms
252-
} else {
253-
HashSet::from_iter(perms.clone())
254-
};
229+
let perms: HashSet<Permission> = if let Some(user) = users().0.get(username) {
230+
let all_groups_roles = user
231+
.user_groups
232+
.iter()
233+
.filter(|id| (read_user_groups().0.contains_key(*id)))
234+
.map(|id| read_user_groups().0.get(id).unwrap().roles.clone())
235+
.reduce(|mut acc, e| {
236+
acc.extend(e);
237+
acc
238+
})
239+
.unwrap_or_default();
240+
241+
let mut privilege_list = Vec::new();
242+
all_groups_roles
243+
.iter()
244+
.filter_map(|role| roles().get(role).cloned())
245+
.for_each(|privileges| privilege_list.extend(privileges));
246+
247+
let mut perms = HashSet::from_iter(perms.clone());
248+
for privs in privilege_list {
249+
perms.extend(RoleBuilder::from(&privs).build())
250+
}
251+
perms
252+
} else {
253+
HashSet::from_iter(perms.clone())
254+
};
255255
if perms.iter().any(|user_perm| {
256256
match *user_perm {
257257
// if any action is ALL then we we authorize

0 commit comments

Comments
 (0)