mirror of
				https://github.com/juspay/hyperswitch.git
				synced 2025-10-31 10:06:32 +08:00 
			
		
		
		
	feat(users): add some checks for prod-intent send to biz email (#3631)
Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
This commit is contained in:
		 Pritish Budhiraja
					Pritish Budhiraja
				
			
				
					committed by
					
						 GitHub
						GitHub
					
				
			
			
				
	
			
			
			 GitHub
						GitHub
					
				
			
						parent
						
							8853a60bf4
						
					
				
				
					commit
					774a0322aa
				
			| @ -4,10 +4,10 @@ use diesel_models::{ | |||||||
| }; | }; | ||||||
| use error_stack::ResultExt; | use error_stack::ResultExt; | ||||||
| #[cfg(feature = "email")] | #[cfg(feature = "email")] | ||||||
|  | use masking::ExposeInterface; | ||||||
|  | #[cfg(feature = "email")] | ||||||
| use router_env::logger; | use router_env::logger; | ||||||
|  |  | ||||||
| #[cfg(feature = "email")] |  | ||||||
| use crate::services::email::types as email_types; |  | ||||||
| use crate::{ | use crate::{ | ||||||
|     core::errors::{UserErrors, UserResponse, UserResult}, |     core::errors::{UserErrors, UserResponse, UserResult}, | ||||||
|     routes::AppState, |     routes::AppState, | ||||||
| @ -15,6 +15,8 @@ use crate::{ | |||||||
|     types::domain::{user::dashboard_metadata as types, MerchantKeyStore}, |     types::domain::{user::dashboard_metadata as types, MerchantKeyStore}, | ||||||
|     utils::user::dashboard_metadata as utils, |     utils::user::dashboard_metadata as utils, | ||||||
| }; | }; | ||||||
|  | #[cfg(feature = "email")] | ||||||
|  | use crate::{services::email::types as email_types, types::domain}; | ||||||
|  |  | ||||||
| pub async fn set_metadata( | pub async fn set_metadata( | ||||||
|     state: AppState, |     state: AppState, | ||||||
| @ -446,8 +448,8 @@ async fn insert_metadata( | |||||||
|                 metadata = utils::update_user_scoped_metadata( |                 metadata = utils::update_user_scoped_metadata( | ||||||
|                     state, |                     state, | ||||||
|                     user.user_id.clone(), |                     user.user_id.clone(), | ||||||
|                     user.merchant_id, |                     user.merchant_id.clone(), | ||||||
|                     user.org_id, |                     user.org_id.clone(), | ||||||
|                     metadata_key, |                     metadata_key, | ||||||
|                     data.clone(), |                     data.clone(), | ||||||
|                 ) |                 ) | ||||||
| @ -457,7 +459,13 @@ async fn insert_metadata( | |||||||
|  |  | ||||||
|             #[cfg(feature = "email")] |             #[cfg(feature = "email")] | ||||||
|             { |             { | ||||||
|                 if utils::is_prod_email_required(&data) { |                 let user_data = user.get_user(state).await?; | ||||||
|  |                 let user_email = domain::UserEmail::from_pii_email(user_data.email.clone()) | ||||||
|  |                     .change_context(UserErrors::InternalServerError)? | ||||||
|  |                     .get_secret() | ||||||
|  |                     .expose(); | ||||||
|  |  | ||||||
|  |                 if utils::is_prod_email_required(&data, user_email) { | ||||||
|                     let email_contents = email_types::BizEmailProd::new(state, data)?; |                     let email_contents = email_types::BizEmailProd::new(state, data)?; | ||||||
|                     let send_email_result = state |                     let send_email_result = state | ||||||
|                         .email_client |                         .email_client | ||||||
|  | |||||||
| @ -279,9 +279,15 @@ pub fn parse_string_to_enums(query: String) -> UserResult<GetMultipleMetaDataPay | |||||||
|     }) |     }) | ||||||
| } | } | ||||||
|  |  | ||||||
| pub fn is_prod_email_required(data: &ProdIntent) -> bool { | fn not_contains_string(value: &Option<String>, value_to_be_checked: &str) -> bool { | ||||||
|     !(data |     value | ||||||
|         .poc_email |  | ||||||
|         .as_ref() |         .as_ref() | ||||||
|         .map_or(true, |mail| mail.contains("juspay"))) |         .map_or(false, |mail| !mail.contains(value_to_be_checked)) | ||||||
|  | } | ||||||
|  |  | ||||||
|  | pub fn is_prod_email_required(data: &ProdIntent, user_email: String) -> bool { | ||||||
|  |     not_contains_string(&data.poc_email, "juspay") | ||||||
|  |         && not_contains_string(&data.business_website, "juspay") | ||||||
|  |         && not_contains_string(&data.business_website, "hyperswitch") | ||||||
|  |         && not_contains_string(&Some(user_email), "juspay") | ||||||
| } | } | ||||||
|  | |||||||
		Reference in New Issue
	
	Block a user