mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-11-01 19:42:27 +08:00
refactor(users): change list roles api to also send inactive merchants (#3583)
This commit is contained in:
@ -945,10 +945,13 @@ pub async fn create_merchant_account(
|
|||||||
|
|
||||||
pub async fn list_merchant_ids_for_user(
|
pub async fn list_merchant_ids_for_user(
|
||||||
state: AppState,
|
state: AppState,
|
||||||
user: auth::UserFromToken,
|
user_from_token: auth::UserFromToken,
|
||||||
) -> UserResponse<Vec<user_api::UserMerchantAccount>> {
|
) -> UserResponse<Vec<user_api::UserMerchantAccount>> {
|
||||||
let user_roles =
|
let user_roles = state
|
||||||
utils::user_role::get_active_user_roles_for_user(&state, &user.user_id).await?;
|
.store
|
||||||
|
.list_user_roles_by_user_id(user_from_token.user_id.as_str())
|
||||||
|
.await
|
||||||
|
.change_context(UserErrors::InternalServerError)?;
|
||||||
|
|
||||||
let merchant_accounts = state
|
let merchant_accounts = state
|
||||||
.store
|
.store
|
||||||
|
|||||||
@ -1,11 +1,8 @@
|
|||||||
use api_models::user_role as user_role_api;
|
use api_models::user_role as user_role_api;
|
||||||
use diesel_models::{enums::UserStatus, user_role::UserRole};
|
|
||||||
use error_stack::ResultExt;
|
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
consts,
|
consts,
|
||||||
core::errors::{UserErrors, UserResult},
|
core::errors::{UserErrors, UserResult},
|
||||||
routes::AppState,
|
|
||||||
services::authorization::{
|
services::authorization::{
|
||||||
permissions::Permission,
|
permissions::Permission,
|
||||||
predefined_permissions::{self, RoleInfo},
|
predefined_permissions::{self, RoleInfo},
|
||||||
@ -17,20 +14,6 @@ pub fn is_internal_role(role_id: &str) -> bool {
|
|||||||
|| role_id == consts::user_role::ROLE_ID_INTERNAL_VIEW_ONLY_USER
|
|| role_id == consts::user_role::ROLE_ID_INTERNAL_VIEW_ONLY_USER
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn get_active_user_roles_for_user(
|
|
||||||
state: &AppState,
|
|
||||||
user_id: &str,
|
|
||||||
) -> UserResult<Vec<UserRole>> {
|
|
||||||
Ok(state
|
|
||||||
.store
|
|
||||||
.list_user_roles_by_user_id(user_id)
|
|
||||||
.await
|
|
||||||
.change_context(UserErrors::InternalServerError)?
|
|
||||||
.into_iter()
|
|
||||||
.filter(|ele| ele.status == UserStatus::Active)
|
|
||||||
.collect())
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn validate_role_id(role_id: &str) -> UserResult<()> {
|
pub fn validate_role_id(role_id: &str) -> UserResult<()> {
|
||||||
if predefined_permissions::is_role_invitable(role_id) {
|
if predefined_permissions::is_role_invitable(role_id) {
|
||||||
return Ok(());
|
return Ok(());
|
||||||
|
|||||||
Reference in New Issue
Block a user