mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-11-01 02:57:02 +08:00
feat(user): create apis for custom role (#3763)
Co-authored-by: Mani Chandra Dulam <mani.dchandra@juspay.in> Co-authored-by: Mani Chandra <84711804+ThisIsMani@users.noreply.github.com>
This commit is contained in:
@ -1,6 +1,11 @@
|
||||
use api_models::user_role as user_role_api;
|
||||
use error_stack::ResultExt;
|
||||
|
||||
use crate::services::authorization::permissions::Permission;
|
||||
use crate::{
|
||||
core::errors::{UserErrors, UserResult},
|
||||
routes::AppState,
|
||||
services::authorization::permissions::Permission,
|
||||
};
|
||||
|
||||
impl From<Permission> for user_role_api::Permission {
|
||||
fn from(value: Permission) -> Self {
|
||||
@ -34,3 +39,24 @@ impl From<Permission> for user_role_api::Permission {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn is_role_name_already_present_for_merchant(
|
||||
state: &AppState,
|
||||
role_name: &str,
|
||||
merchant_id: &str,
|
||||
org_id: &str,
|
||||
) -> UserResult<()> {
|
||||
let role_name_list: Vec<String> = state
|
||||
.store
|
||||
.list_all_roles(merchant_id, org_id)
|
||||
.await
|
||||
.change_context(UserErrors::InternalServerError)?
|
||||
.iter()
|
||||
.map(|role| role.role_name.to_owned())
|
||||
.collect();
|
||||
|
||||
if role_name_list.contains(&role_name.to_string()) {
|
||||
return Err(UserErrors::RoleNameAlreadyExists.into());
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user