-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(roles): add list support for roles #5754
Conversation
Review changes with SemanticDiff. Analyzed 13 of 13 files. Overall, the semantic diff is 5% smaller than the GitHub diff.
|
let role_info = roles::RoleInfo::from(role); | ||
role_api::MinimalRoleInfo { | ||
role_id: role_info.get_role_id().to_string(), | ||
role_name: role_info.get_role_name().to_string(), | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add entity type check and is_updatable / is_invitable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
entity type check is already handled in db query, added check for invitable/updatable
crates/router/src/routes/app.rs
Outdated
.service( | ||
web::scope("/list") | ||
.service(web::resource("").route(web::get().to(list_all_roles))) | ||
.service(web::resource("/v2").route(web::get().to(list_roles_with_info))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change this to /v2/list
if possible.
let custom_roles_map = custom_roles.into_iter().filter_map(|role| { | ||
let role_info = roles::RoleInfo::from(role); | ||
|
||
if match check_type { | ||
role_api::RoleCheckType::Invite => role_info.is_invitable(), | ||
role_api::RoleCheckType::Update => role_info.is_updatable(), | ||
} { | ||
Some(role_api::MinimalRoleInfo { | ||
role_id: role_info.get_role_id().to_string(), | ||
role_name: role_info.get_role_name().to_string(), | ||
}) | ||
} else { | ||
None | ||
} | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NIT: Push every thing to a vector once and then do these checks.
&req, | ||
(), | ||
|state, user_from_token, _, _| role_core::list_roles_with_info(state, user_from_token), | ||
&auth::DashboardNoPermissionAuth, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
UserRead
Permission required here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes that would be more precise, for now let's keep this auth only.
05e3483
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor concerns.
@@ -305,7 +305,7 @@ pub async fn list_updatable_roles_at_entity_level( | |||
role_api::RoleCheckType::Update, | |||
) | |||
}, | |||
&auth::DashboardNoPermissionAuth, | |||
&auth::JWTAuth(Permission::UsersRead), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should it be UsersWrite?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, it should be read only, invite function will check for write, list should be read only.
@@ -279,7 +279,7 @@ pub async fn list_invitable_roles_at_entity_level( | |||
role_api::RoleCheckType::Invite, | |||
) | |||
}, | |||
&auth::DashboardNoPermissionAuth, | |||
&auth::JWTAuth(Permission::UsersRead), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should it be UsersWrite?
let list_role_info_response = role_info_vec | ||
.into_iter() | ||
.filter_map(|role_info| { | ||
if user_role_entity >= role_info.get_entity_type() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can use then on bool.
Type of Change
Description
Add support to
Additional Changes
Motivation and Context
Closes #5753
How did you test it?
To List roles available roles in hierarchy with info:
Response
To list roles at entity level for invite:
Entity type can be
organization
,merchant
orprofile
Response:
To list all roles at entity level for update
Response:
Checklist
cargo +nightly fmt --all
cargo clippy