refactor(users): move roles schema to global interface (#6862)

This commit is contained in:
Apoorv Dixit
2024-12-19 18:34:04 +05:30
committed by GitHub
parent 607424992a
commit 2d8af88204
7 changed files with 21 additions and 20 deletions

View File

@ -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)?;
@ -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)?;
@ -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)?;
@ -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)?;
@ -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)?;
@ -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)?;

View File

@ -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(),
@ -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 {
@ -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,
@ -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),
@ -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,
@ -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),

View File

@ -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>;
@ -147,7 +147,7 @@ pub trait GlobalStorageInterface:
+ user::UserInterface
+ user_role::UserRoleInterface
+ user_key_store::UserKeyStoreInterface
+ user::theme::ThemeInterface
+ role::RoleInterface
+ 'static
{
}

View File

@ -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)

View File

@ -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)
@ -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)

View File

@ -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
{
@ -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()
{

View File

@ -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)?