mirror of
				https://github.com/juspay/hyperswitch.git
				synced 2025-10-30 09:38:33 +08:00 
			
		
		
		
	refactor(users): move roles schema to global interface (#6862)
This commit is contained in:
		| @ -21,7 +21,7 @@ pub async fn get_theme_using_lineage( | |||||||
|     lineage: ThemeLineage, |     lineage: ThemeLineage, | ||||||
| ) -> UserResponse<theme_api::GetThemeResponse> { | ) -> UserResponse<theme_api::GetThemeResponse> { | ||||||
|     let theme = state |     let theme = state | ||||||
|         .global_store |         .store | ||||||
|         .find_theme_by_lineage(lineage) |         .find_theme_by_lineage(lineage) | ||||||
|         .await |         .await | ||||||
|         .to_not_found_response(UserErrors::ThemeNotFound)?; |         .to_not_found_response(UserErrors::ThemeNotFound)?; | ||||||
| @ -55,7 +55,7 @@ pub async fn get_theme_using_theme_id( | |||||||
|     theme_id: String, |     theme_id: String, | ||||||
| ) -> UserResponse<theme_api::GetThemeResponse> { | ) -> UserResponse<theme_api::GetThemeResponse> { | ||||||
|     let theme = state |     let theme = state | ||||||
|         .global_store |         .store | ||||||
|         .find_theme_by_theme_id(theme_id.clone()) |         .find_theme_by_theme_id(theme_id.clone()) | ||||||
|         .await |         .await | ||||||
|         .to_not_found_response(UserErrors::ThemeNotFound)?; |         .to_not_found_response(UserErrors::ThemeNotFound)?; | ||||||
| @ -90,7 +90,7 @@ pub async fn upload_file_to_theme_storage( | |||||||
|     request: theme_api::UploadFileRequest, |     request: theme_api::UploadFileRequest, | ||||||
| ) -> UserResponse<()> { | ) -> UserResponse<()> { | ||||||
|     let db_theme = state |     let db_theme = state | ||||||
|         .global_store |         .store | ||||||
|         .find_theme_by_lineage(request.lineage) |         .find_theme_by_lineage(request.lineage) | ||||||
|         .await |         .await | ||||||
|         .to_not_found_response(UserErrors::ThemeNotFound)?; |         .to_not_found_response(UserErrors::ThemeNotFound)?; | ||||||
| @ -131,7 +131,7 @@ pub async fn create_theme( | |||||||
|     ); |     ); | ||||||
|  |  | ||||||
|     let db_theme = state |     let db_theme = state | ||||||
|         .global_store |         .store | ||||||
|         .insert_theme(new_theme) |         .insert_theme(new_theme) | ||||||
|         .await |         .await | ||||||
|         .to_duplicate_response(UserErrors::ThemeAlreadyExists)?; |         .to_duplicate_response(UserErrors::ThemeAlreadyExists)?; | ||||||
| @ -176,7 +176,7 @@ pub async fn update_theme( | |||||||
|     request: theme_api::UpdateThemeRequest, |     request: theme_api::UpdateThemeRequest, | ||||||
| ) -> UserResponse<theme_api::GetThemeResponse> { | ) -> UserResponse<theme_api::GetThemeResponse> { | ||||||
|     let db_theme = state |     let db_theme = state | ||||||
|         .global_store |         .store | ||||||
|         .find_theme_by_lineage(request.lineage) |         .find_theme_by_lineage(request.lineage) | ||||||
|         .await |         .await | ||||||
|         .to_not_found_response(UserErrors::ThemeNotFound)?; |         .to_not_found_response(UserErrors::ThemeNotFound)?; | ||||||
| @ -225,7 +225,7 @@ pub async fn delete_theme( | |||||||
|     lineage: ThemeLineage, |     lineage: ThemeLineage, | ||||||
| ) -> UserResponse<()> { | ) -> UserResponse<()> { | ||||||
|     state |     state | ||||||
|         .global_store |         .store | ||||||
|         .delete_theme_by_lineage_and_theme_id(theme_id.clone(), lineage) |         .delete_theme_by_lineage_and_theme_id(theme_id.clone(), lineage) | ||||||
|         .await |         .await | ||||||
|         .to_not_found_response(UserErrors::ThemeNotFound)?; |         .to_not_found_response(UserErrors::ThemeNotFound)?; | ||||||
|  | |||||||
| @ -86,7 +86,7 @@ pub async fn create_role( | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     let role = state |     let role = state | ||||||
|         .store |         .global_store | ||||||
|         .insert_role(RoleNew { |         .insert_role(RoleNew { | ||||||
|             role_id: generate_id_with_default_len("role"), |             role_id: generate_id_with_default_len("role"), | ||||||
|             role_name: role_name.get_role_name(), |             role_name: role_name.get_role_name(), | ||||||
| @ -220,7 +220,7 @@ pub async fn update_role( | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     let updated_role = state |     let updated_role = state | ||||||
|         .store |         .global_store | ||||||
|         .update_role_by_role_id( |         .update_role_by_role_id( | ||||||
|             role_id, |             role_id, | ||||||
|             RoleUpdate::UpdateDetails { |             RoleUpdate::UpdateDetails { | ||||||
| @ -271,7 +271,7 @@ pub async fn list_roles_with_info( | |||||||
|     let custom_roles = |     let custom_roles = | ||||||
|         match utils::user_role::get_min_entity(user_role_entity, request.entity_type)? { |         match utils::user_role::get_min_entity(user_role_entity, request.entity_type)? { | ||||||
|             EntityType::Tenant | EntityType::Organization => state |             EntityType::Tenant | EntityType::Organization => state | ||||||
|                 .store |                 .global_store | ||||||
|                 .list_roles_for_org_by_parameters( |                 .list_roles_for_org_by_parameters( | ||||||
|                     &user_from_token.org_id, |                     &user_from_token.org_id, | ||||||
|                     None, |                     None, | ||||||
| @ -282,7 +282,7 @@ pub async fn list_roles_with_info( | |||||||
|                 .change_context(UserErrors::InternalServerError) |                 .change_context(UserErrors::InternalServerError) | ||||||
|                 .attach_printable("Failed to get roles")?, |                 .attach_printable("Failed to get roles")?, | ||||||
|             EntityType::Merchant => state |             EntityType::Merchant => state | ||||||
|                 .store |                 .global_store | ||||||
|                 .list_roles_for_org_by_parameters( |                 .list_roles_for_org_by_parameters( | ||||||
|                     &user_from_token.org_id, |                     &user_from_token.org_id, | ||||||
|                     Some(&user_from_token.merchant_id), |                     Some(&user_from_token.merchant_id), | ||||||
| @ -344,7 +344,7 @@ pub async fn list_roles_at_entity_level( | |||||||
|  |  | ||||||
|     let custom_roles = match req.entity_type { |     let custom_roles = match req.entity_type { | ||||||
|         EntityType::Tenant | EntityType::Organization => state |         EntityType::Tenant | EntityType::Organization => state | ||||||
|             .store |             .global_store | ||||||
|             .list_roles_for_org_by_parameters( |             .list_roles_for_org_by_parameters( | ||||||
|                 &user_from_token.org_id, |                 &user_from_token.org_id, | ||||||
|                 None, |                 None, | ||||||
| @ -356,7 +356,7 @@ pub async fn list_roles_at_entity_level( | |||||||
|             .attach_printable("Failed to get roles")?, |             .attach_printable("Failed to get roles")?, | ||||||
|  |  | ||||||
|         EntityType::Merchant => state |         EntityType::Merchant => state | ||||||
|             .store |             .global_store | ||||||
|             .list_roles_for_org_by_parameters( |             .list_roles_for_org_by_parameters( | ||||||
|                 &user_from_token.org_id, |                 &user_from_token.org_id, | ||||||
|                 Some(&user_from_token.merchant_id), |                 Some(&user_from_token.merchant_id), | ||||||
|  | |||||||
| @ -128,10 +128,10 @@ pub trait StorageInterface: | |||||||
|     + authorization::AuthorizationInterface |     + authorization::AuthorizationInterface | ||||||
|     + user::sample_data::BatchSampleDataInterface |     + user::sample_data::BatchSampleDataInterface | ||||||
|     + health_check::HealthCheckDbInterface |     + health_check::HealthCheckDbInterface | ||||||
|     + role::RoleInterface |  | ||||||
|     + user_authentication_method::UserAuthenticationMethodInterface |     + user_authentication_method::UserAuthenticationMethodInterface | ||||||
|     + authentication::AuthenticationInterface |     + authentication::AuthenticationInterface | ||||||
|     + generic_link::GenericLinkInterface |     + generic_link::GenericLinkInterface | ||||||
|  |     + user::theme::ThemeInterface | ||||||
|     + 'static |     + 'static | ||||||
| { | { | ||||||
|     fn get_scheduler_db(&self) -> Box<dyn scheduler::SchedulerInterface>; |     fn get_scheduler_db(&self) -> Box<dyn scheduler::SchedulerInterface>; | ||||||
| @ -147,7 +147,7 @@ pub trait GlobalStorageInterface: | |||||||
|     + user::UserInterface |     + user::UserInterface | ||||||
|     + user_role::UserRoleInterface |     + user_role::UserRoleInterface | ||||||
|     + user_key_store::UserKeyStoreInterface |     + user_key_store::UserKeyStoreInterface | ||||||
|     + user::theme::ThemeInterface |     + role::RoleInterface | ||||||
|     + 'static |     + 'static | ||||||
| { | { | ||||||
| } | } | ||||||
|  | |||||||
| @ -73,7 +73,8 @@ where | |||||||
|     A: SessionStateInfo + Sync, |     A: SessionStateInfo + Sync, | ||||||
| { | { | ||||||
|     state |     state | ||||||
|         .store() |         .session_state() | ||||||
|  |         .global_store | ||||||
|         .find_by_role_id_and_org_id(role_id, org_id) |         .find_by_role_id_and_org_id(role_id, org_id) | ||||||
|         .await |         .await | ||||||
|         .map(roles::RoleInfo::from) |         .map(roles::RoleInfo::from) | ||||||
|  | |||||||
| @ -126,7 +126,7 @@ impl RoleInfo { | |||||||
|             Ok(role.clone()) |             Ok(role.clone()) | ||||||
|         } else { |         } else { | ||||||
|             state |             state | ||||||
|                 .store |                 .global_store | ||||||
|                 .find_role_by_role_id_in_lineage(role_id, merchant_id, org_id) |                 .find_role_by_role_id_in_lineage(role_id, merchant_id, org_id) | ||||||
|                 .await |                 .await | ||||||
|                 .map(Self::from) |                 .map(Self::from) | ||||||
| @ -142,7 +142,7 @@ impl RoleInfo { | |||||||
|             Ok(role.clone()) |             Ok(role.clone()) | ||||||
|         } else { |         } else { | ||||||
|             state |             state | ||||||
|                 .store |                 .global_store | ||||||
|                 .find_by_role_id_and_org_id(role_id, org_id) |                 .find_by_role_id_and_org_id(role_id, org_id) | ||||||
|                 .await |                 .await | ||||||
|                 .map(Self::from) |                 .map(Self::from) | ||||||
|  | |||||||
| @ -190,7 +190,7 @@ pub async fn get_most_specific_theme_using_lineage( | |||||||
|     lineage: ThemeLineage, |     lineage: ThemeLineage, | ||||||
| ) -> UserResult<Option<Theme>> { | ) -> UserResult<Option<Theme>> { | ||||||
|     match state |     match state | ||||||
|         .global_store |         .store | ||||||
|         .find_most_specific_theme_in_lineage(lineage) |         .find_most_specific_theme_in_lineage(lineage) | ||||||
|         .await |         .await | ||||||
|     { |     { | ||||||
| @ -210,7 +210,7 @@ pub async fn get_theme_using_optional_theme_id( | |||||||
|     theme_id: Option<String>, |     theme_id: Option<String>, | ||||||
| ) -> UserResult<Option<Theme>> { | ) -> UserResult<Option<Theme>> { | ||||||
|     match theme_id |     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 |         .await | ||||||
|         .transpose() |         .transpose() | ||||||
|     { |     { | ||||||
|  | |||||||
| @ -57,7 +57,7 @@ pub async fn validate_role_name( | |||||||
|  |  | ||||||
|     // TODO: Create and use find_by_role_name to make this efficient |     // TODO: Create and use find_by_role_name to make this efficient | ||||||
|     let is_present_in_custom_roles = state |     let is_present_in_custom_roles = state | ||||||
|         .store |         .global_store | ||||||
|         .list_all_roles(merchant_id, org_id) |         .list_all_roles(merchant_id, org_id) | ||||||
|         .await |         .await | ||||||
|         .change_context(UserErrors::InternalServerError)? |         .change_context(UserErrors::InternalServerError)? | ||||||
|  | |||||||
		Reference in New Issue
	
	Block a user
	 Apoorv Dixit
					Apoorv Dixit