Skip to content

Commit

Permalink
refactor(users): move roles schema to global interface (#6862)
Browse files Browse the repository at this point in the history
  • Loading branch information
apoorvdixit88 authored Dec 19, 2024
1 parent 6074249 commit 2d8af88
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 20 deletions.
12 changes: 6 additions & 6 deletions crates/router/src/core/user/theme.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub async fn get_theme_using_lineage(
lineage: ThemeLineage,
) -> UserResponse<theme_api::GetThemeResponse> {
let theme = state
.global_store
.store
.find_theme_by_lineage(lineage)
.await
.to_not_found_response(UserErrors::ThemeNotFound)?;
Expand Down Expand Up @@ -55,7 +55,7 @@ pub async fn get_theme_using_theme_id(
theme_id: String,
) -> UserResponse<theme_api::GetThemeResponse> {
let theme = state
.global_store
.store
.find_theme_by_theme_id(theme_id.clone())
.await
.to_not_found_response(UserErrors::ThemeNotFound)?;
Expand Down Expand Up @@ -90,7 +90,7 @@ pub async fn upload_file_to_theme_storage(
request: theme_api::UploadFileRequest,
) -> UserResponse<()> {
let db_theme = state
.global_store
.store
.find_theme_by_lineage(request.lineage)
.await
.to_not_found_response(UserErrors::ThemeNotFound)?;
Expand Down Expand Up @@ -131,7 +131,7 @@ pub async fn create_theme(
);

let db_theme = state
.global_store
.store
.insert_theme(new_theme)
.await
.to_duplicate_response(UserErrors::ThemeAlreadyExists)?;
Expand Down Expand Up @@ -176,7 +176,7 @@ pub async fn update_theme(
request: theme_api::UpdateThemeRequest,
) -> UserResponse<theme_api::GetThemeResponse> {
let db_theme = state
.global_store
.store
.find_theme_by_lineage(request.lineage)
.await
.to_not_found_response(UserErrors::ThemeNotFound)?;
Expand Down Expand Up @@ -225,7 +225,7 @@ pub async fn delete_theme(
lineage: ThemeLineage,
) -> UserResponse<()> {
state
.global_store
.store
.delete_theme_by_lineage_and_theme_id(theme_id.clone(), lineage)
.await
.to_not_found_response(UserErrors::ThemeNotFound)?;
Expand Down
12 changes: 6 additions & 6 deletions crates/router/src/core/user_role/role.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ pub async fn create_role(
}

let role = state
.store
.global_store
.insert_role(RoleNew {
role_id: generate_id_with_default_len("role"),
role_name: role_name.get_role_name(),
Expand Down Expand Up @@ -220,7 +220,7 @@ pub async fn update_role(
}

let updated_role = state
.store
.global_store
.update_role_by_role_id(
role_id,
RoleUpdate::UpdateDetails {
Expand Down Expand Up @@ -271,7 +271,7 @@ pub async fn list_roles_with_info(
let custom_roles =
match utils::user_role::get_min_entity(user_role_entity, request.entity_type)? {
EntityType::Tenant | EntityType::Organization => state
.store
.global_store
.list_roles_for_org_by_parameters(
&user_from_token.org_id,
None,
Expand All @@ -282,7 +282,7 @@ pub async fn list_roles_with_info(
.change_context(UserErrors::InternalServerError)
.attach_printable("Failed to get roles")?,
EntityType::Merchant => state
.store
.global_store
.list_roles_for_org_by_parameters(
&user_from_token.org_id,
Some(&user_from_token.merchant_id),
Expand Down Expand Up @@ -344,7 +344,7 @@ pub async fn list_roles_at_entity_level(

let custom_roles = match req.entity_type {
EntityType::Tenant | EntityType::Organization => state
.store
.global_store
.list_roles_for_org_by_parameters(
&user_from_token.org_id,
None,
Expand All @@ -356,7 +356,7 @@ pub async fn list_roles_at_entity_level(
.attach_printable("Failed to get roles")?,

EntityType::Merchant => state
.store
.global_store
.list_roles_for_org_by_parameters(
&user_from_token.org_id,
Some(&user_from_token.merchant_id),
Expand Down
4 changes: 2 additions & 2 deletions crates/router/src/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,10 @@ pub trait StorageInterface:
+ authorization::AuthorizationInterface
+ user::sample_data::BatchSampleDataInterface
+ health_check::HealthCheckDbInterface
+ role::RoleInterface
+ user_authentication_method::UserAuthenticationMethodInterface
+ authentication::AuthenticationInterface
+ generic_link::GenericLinkInterface
+ user::theme::ThemeInterface
+ 'static
{
fn get_scheduler_db(&self) -> Box<dyn scheduler::SchedulerInterface>;
Expand All @@ -147,7 +147,7 @@ pub trait GlobalStorageInterface:
+ user::UserInterface
+ user_role::UserRoleInterface
+ user_key_store::UserKeyStoreInterface
+ user::theme::ThemeInterface
+ role::RoleInterface
+ 'static
{
}
Expand Down
3 changes: 2 additions & 1 deletion crates/router/src/services/authorization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ where
A: SessionStateInfo + Sync,
{
state
.store()
.session_state()
.global_store
.find_by_role_id_and_org_id(role_id, org_id)
.await
.map(roles::RoleInfo::from)
Expand Down
4 changes: 2 additions & 2 deletions crates/router/src/services/authorization/roles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ impl RoleInfo {
Ok(role.clone())
} else {
state
.store
.global_store
.find_role_by_role_id_in_lineage(role_id, merchant_id, org_id)
.await
.map(Self::from)
Expand All @@ -142,7 +142,7 @@ impl RoleInfo {
Ok(role.clone())
} else {
state
.store
.global_store
.find_by_role_id_and_org_id(role_id, org_id)
.await
.map(Self::from)
Expand Down
4 changes: 2 additions & 2 deletions crates/router/src/utils/user/theme.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ pub async fn get_most_specific_theme_using_lineage(
lineage: ThemeLineage,
) -> UserResult<Option<Theme>> {
match state
.global_store
.store
.find_most_specific_theme_in_lineage(lineage)
.await
{
Expand All @@ -210,7 +210,7 @@ pub async fn get_theme_using_optional_theme_id(
theme_id: Option<String>,
) -> UserResult<Option<Theme>> {
match theme_id
.async_map(|theme_id| state.global_store.find_theme_by_theme_id(theme_id))
.async_map(|theme_id| state.store.find_theme_by_theme_id(theme_id))
.await
.transpose()
{
Expand Down
2 changes: 1 addition & 1 deletion crates/router/src/utils/user_role.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ pub async fn validate_role_name(

// TODO: Create and use find_by_role_name to make this efficient
let is_present_in_custom_roles = state
.store
.global_store
.list_all_roles(merchant_id, org_id)
.await
.change_context(UserErrors::InternalServerError)?
Expand Down

0 comments on commit 2d8af88

Please sign in to comment.