feat: add profile_id authentication for business profile update and list (#5673)

This commit is contained in:
Hrithikesh
2024-09-03 11:37:06 +05:30
committed by GitHub
parent f822730979
commit e3a9fb16c5
7 changed files with 148 additions and 10 deletions

View File

@ -3717,6 +3717,7 @@ pub async fn create_business_profile(
pub async fn list_business_profile(
state: SessionState,
merchant_id: id_type::MerchantId,
profile_id_list: Option<Vec<id_type::ProfileId>>,
) -> RouterResponse<Vec<api_models::admin::BusinessProfileResponse>> {
let db = state.store.as_ref();
let key_store = db
@ -3732,6 +3733,7 @@ pub async fn list_business_profile(
.await
.to_not_found_response(errors::ApiErrorResponse::InternalServerError)?
.clone();
let profiles = core_utils::filter_objects_based_on_profile_id_list(profile_id_list, profiles);
let mut business_profiles = Vec::new();
for profile in profiles {
let business_profile =

View File

@ -1334,7 +1334,7 @@ pub fn get_incremental_authorization_allowed_value(
}
}
pub(super) trait GetProfileId {
pub(crate) trait GetProfileId {
fn get_profile_id(&self) -> Option<&common_utils::id_type::ProfileId>;
}
@ -1381,6 +1381,12 @@ impl<T, F> GetProfileId for (storage::Payouts, T, F) {
}
}
impl GetProfileId for domain::BusinessProfile {
fn get_profile_id(&self) -> Option<&common_utils::id_type::ProfileId> {
Some(self.get_id())
}
}
/// Filter Objects based on profile ids
pub(super) fn filter_objects_based_on_profile_id_list<T: GetProfileId>(
profile_id_list_auth_layer: Option<Vec<common_utils::id_type::ProfileId>>,
@ -1406,7 +1412,7 @@ pub(super) fn filter_objects_based_on_profile_id_list<T: GetProfileId>(
}
}
pub(super) fn validate_profile_id_from_auth_layer<T: GetProfileId + std::fmt::Debug>(
pub(crate) fn validate_profile_id_from_auth_layer<T: GetProfileId + std::fmt::Debug>(
profile_id_auth_layer: Option<common_utils::id_type::ProfileId>,
object: &T,
) -> RouterResult<()> {