Skip to content

Commit ad97ff9

Browse files
update is_admin logic
1 parent ab18e39 commit ad97ff9

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

src/utils/mod.rs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -149,12 +149,18 @@ pub async fn user_auth_for_datasets(
149149
pub fn is_admin(req: &HttpRequest) -> Result<bool, anyhow::Error> {
150150
let session_key =
151151
extract_session_key_from_req(req).map_err(|e| anyhow::Error::msg(e.to_string()))?;
152-
let userid = if let Some(u) = Users.get_userid_from_session(&session_key) {
153-
u
154-
} else {
155-
return Err(anyhow::Error::msg("User not found"));
156-
};
157-
let permissions = Users.get_role(&userid);
158152

159-
Ok(permissions.contains(&String::from("admin")))
153+
let permissions = Users.get_permissions(&session_key);
154+
155+
// Check if user has admin permissions (Action::All on All resources)
156+
for permission in permissions.iter() {
157+
match permission {
158+
Permission::Resource(Action::All, ParseableResourceType::All) => {
159+
return Ok(true);
160+
}
161+
_ => continue,
162+
}
163+
}
164+
165+
Ok(false)
160166
}

0 commit comments

Comments
 (0)