mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-11-02 04:04:43 +08:00
feat(analytics): Revert api_event metrics and filters back to merchant_id authentication (#5821)
This commit is contained in:
@ -215,14 +215,6 @@ pub mod routes {
|
||||
web::resource("filters/disputes")
|
||||
.route(web::post().to(get_org_dispute_filters)),
|
||||
)
|
||||
.service(
|
||||
web::resource("filters/api_events")
|
||||
.route(web::post().to(get_org_api_event_filters)),
|
||||
)
|
||||
.service(
|
||||
web::resource("metrics/api_events")
|
||||
.route(web::post().to(get_org_api_events_metrics)),
|
||||
)
|
||||
.service(
|
||||
web::resource("report/dispute")
|
||||
.route(web::post().to(generate_org_dispute_report)),
|
||||
@ -257,14 +249,6 @@ pub mod routes {
|
||||
web::resource("filters/refunds")
|
||||
.route(web::post().to(get_profile_refund_filters)),
|
||||
)
|
||||
.service(
|
||||
web::resource("metrics/api_events")
|
||||
.route(web::post().to(get_profile_api_events_metrics)),
|
||||
)
|
||||
.service(
|
||||
web::resource("filters/api_events")
|
||||
.route(web::post().to(get_profile_api_event_filters)),
|
||||
)
|
||||
.service(
|
||||
web::resource("metrics/disputes")
|
||||
.route(web::post().to(get_profile_dispute_metrics)),
|
||||
@ -1757,100 +1741,13 @@ pub mod routes {
|
||||
&req,
|
||||
payload,
|
||||
|state, auth: AuthenticationData, req, _| async move {
|
||||
let org_id = auth.merchant_account.get_org_id();
|
||||
let merchant_id = auth.merchant_account.get_id();
|
||||
let auth: AuthInfo = AuthInfo::MerchantLevel {
|
||||
org_id: org_id.clone(),
|
||||
merchant_ids: vec![merchant_id.clone()],
|
||||
};
|
||||
analytics::api_event::get_api_event_metrics(&state.pool, &auth, req)
|
||||
.await
|
||||
.map(ApplicationResponse::Json)
|
||||
},
|
||||
&auth::JWTAuth {
|
||||
permission: Permission::Analytics,
|
||||
minimum_entity_level: EntityType::Merchant,
|
||||
},
|
||||
api_locking::LockAction::NotApplicable,
|
||||
))
|
||||
.await
|
||||
}
|
||||
|
||||
/// # Panics
|
||||
///
|
||||
/// Panics if `json_payload` array does not contain one `GetApiEventMetricRequest` element.
|
||||
pub async fn get_org_api_events_metrics(
|
||||
state: web::Data<AppState>,
|
||||
req: actix_web::HttpRequest,
|
||||
json_payload: web::Json<[GetApiEventMetricRequest; 1]>,
|
||||
) -> impl Responder {
|
||||
// safety: This shouldn't panic owing to the data type
|
||||
#[allow(clippy::expect_used)]
|
||||
let payload = json_payload
|
||||
.into_inner()
|
||||
.to_vec()
|
||||
.pop()
|
||||
.expect("Couldn't get GetApiEventMetricRequest");
|
||||
let flow = AnalyticsFlow::GetApiEventMetrics;
|
||||
Box::pin(api::server_wrap(
|
||||
flow,
|
||||
state.clone(),
|
||||
&req,
|
||||
payload,
|
||||
|state, auth: AuthenticationData, req, _| async move {
|
||||
let org_id = auth.merchant_account.get_org_id();
|
||||
let auth: AuthInfo = AuthInfo::OrgLevel {
|
||||
org_id: org_id.clone(),
|
||||
};
|
||||
analytics::api_event::get_api_event_metrics(&state.pool, &auth, req)
|
||||
.await
|
||||
.map(ApplicationResponse::Json)
|
||||
},
|
||||
&auth::JWTAuth {
|
||||
permission: Permission::Analytics,
|
||||
minimum_entity_level: EntityType::Merchant,
|
||||
},
|
||||
api_locking::LockAction::NotApplicable,
|
||||
))
|
||||
.await
|
||||
}
|
||||
|
||||
/// # Panics
|
||||
///
|
||||
/// Panics if `json_payload` array does not contain one `GetApiEventMetricRequest` element.
|
||||
pub async fn get_profile_api_events_metrics(
|
||||
state: web::Data<AppState>,
|
||||
req: actix_web::HttpRequest,
|
||||
json_payload: web::Json<[GetApiEventMetricRequest; 1]>,
|
||||
) -> impl Responder {
|
||||
// safety: This shouldn't panic owing to the data type
|
||||
#[allow(clippy::expect_used)]
|
||||
let payload = json_payload
|
||||
.into_inner()
|
||||
.to_vec()
|
||||
.pop()
|
||||
.expect("Couldn't get GetApiEventMetricRequest");
|
||||
let flow = AnalyticsFlow::GetApiEventMetrics;
|
||||
Box::pin(api::server_wrap(
|
||||
flow,
|
||||
state.clone(),
|
||||
&req,
|
||||
payload,
|
||||
|state, auth: AuthenticationData, req, _| async move {
|
||||
let org_id = auth.merchant_account.get_org_id();
|
||||
let merchant_id = auth.merchant_account.get_id();
|
||||
let profile_id = auth
|
||||
.profile_id
|
||||
.ok_or(report!(UserErrors::JwtProfileIdMissing))
|
||||
.change_context(AnalyticsError::AccessForbiddenError)?;
|
||||
let auth: AuthInfo = AuthInfo::ProfileLevel {
|
||||
org_id: org_id.clone(),
|
||||
merchant_id: merchant_id.clone(),
|
||||
profile_ids: vec![profile_id.clone()],
|
||||
};
|
||||
analytics::api_event::get_api_event_metrics(&state.pool, &auth, req)
|
||||
.await
|
||||
.map(ApplicationResponse::Json)
|
||||
analytics::api_event::get_api_event_metrics(
|
||||
&state.pool,
|
||||
auth.merchant_account.get_id(),
|
||||
req,
|
||||
)
|
||||
.await
|
||||
.map(ApplicationResponse::Json)
|
||||
},
|
||||
&auth::JWTAuth {
|
||||
permission: Permission::Analytics,
|
||||
@ -1873,78 +1770,7 @@ pub mod routes {
|
||||
&req,
|
||||
json_payload.into_inner(),
|
||||
|state, auth: AuthenticationData, req, _| async move {
|
||||
let org_id = auth.merchant_account.get_org_id();
|
||||
let merchant_id = auth.merchant_account.get_id();
|
||||
let auth: AuthInfo = AuthInfo::MerchantLevel {
|
||||
org_id: org_id.clone(),
|
||||
merchant_ids: vec![merchant_id.clone()],
|
||||
};
|
||||
analytics::api_event::get_filters(&state.pool, req, &auth)
|
||||
.await
|
||||
.map(ApplicationResponse::Json)
|
||||
},
|
||||
&auth::JWTAuth {
|
||||
permission: Permission::Analytics,
|
||||
minimum_entity_level: EntityType::Merchant,
|
||||
},
|
||||
api_locking::LockAction::NotApplicable,
|
||||
))
|
||||
.await
|
||||
}
|
||||
|
||||
pub async fn get_org_api_event_filters(
|
||||
state: web::Data<AppState>,
|
||||
req: actix_web::HttpRequest,
|
||||
json_payload: web::Json<GetApiEventFiltersRequest>,
|
||||
) -> impl Responder {
|
||||
let flow = AnalyticsFlow::GetApiEventFilters;
|
||||
Box::pin(api::server_wrap(
|
||||
flow,
|
||||
state.clone(),
|
||||
&req,
|
||||
json_payload.into_inner(),
|
||||
|state, auth: AuthenticationData, req, _| async move {
|
||||
let org_id = auth.merchant_account.get_org_id();
|
||||
let auth: AuthInfo = AuthInfo::OrgLevel {
|
||||
org_id: org_id.clone(),
|
||||
};
|
||||
analytics::api_event::get_filters(&state.pool, req, &auth)
|
||||
.await
|
||||
.map(ApplicationResponse::Json)
|
||||
},
|
||||
&auth::JWTAuth {
|
||||
permission: Permission::Analytics,
|
||||
minimum_entity_level: EntityType::Merchant,
|
||||
},
|
||||
api_locking::LockAction::NotApplicable,
|
||||
))
|
||||
.await
|
||||
}
|
||||
|
||||
pub async fn get_profile_api_event_filters(
|
||||
state: web::Data<AppState>,
|
||||
req: actix_web::HttpRequest,
|
||||
json_payload: web::Json<GetApiEventFiltersRequest>,
|
||||
) -> impl Responder {
|
||||
let flow = AnalyticsFlow::GetApiEventFilters;
|
||||
Box::pin(api::server_wrap(
|
||||
flow,
|
||||
state.clone(),
|
||||
&req,
|
||||
json_payload.into_inner(),
|
||||
|state, auth: AuthenticationData, req, _| async move {
|
||||
let org_id = auth.merchant_account.get_org_id();
|
||||
let merchant_id = auth.merchant_account.get_id();
|
||||
let profile_id = auth
|
||||
.profile_id
|
||||
.ok_or(report!(UserErrors::JwtProfileIdMissing))
|
||||
.change_context(AnalyticsError::AccessForbiddenError)?;
|
||||
let auth: AuthInfo = AuthInfo::ProfileLevel {
|
||||
org_id: org_id.clone(),
|
||||
merchant_id: merchant_id.clone(),
|
||||
profile_ids: vec![profile_id.clone()],
|
||||
};
|
||||
analytics::api_event::get_filters(&state.pool, req, &auth)
|
||||
analytics::api_event::get_filters(&state.pool, req, auth.merchant_account.get_id())
|
||||
.await
|
||||
.map(ApplicationResponse::Json)
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user