From 899ec23565f99daaad821c1ec1482b4c0cc408c5 Mon Sep 17 00:00:00 2001 From: Summer Gram <42691057+SummerGram@users.noreply.github.com> Date: Wed, 16 Oct 2024 14:47:15 +0800 Subject: [PATCH] refactor(users): Move hardcoded email subjects to constants (#6110) --- crates/router/src/consts.rs | 5 +++++ crates/router/src/consts/user.rs | 7 +++++++ crates/router/src/core/recon.rs | 5 +++-- crates/router/src/core/user.rs | 16 ++++++++-------- crates/router/src/services/email/types.rs | 2 +- crates/router/src/workflows/api_key_expiry.rs | 4 ++-- 6 files changed, 26 insertions(+), 13 deletions(-) diff --git a/crates/router/src/consts.rs b/crates/router/src/consts.rs index 721dd9de1c..28f3f23ccb 100644 --- a/crates/router/src/consts.rs +++ b/crates/router/src/consts.rs @@ -87,6 +87,11 @@ pub const EMAIL_TOKEN_TIME_IN_SECS: u64 = 60 * 60 * 24; // 1 day #[cfg(feature = "email")] pub const EMAIL_TOKEN_BLACKLIST_PREFIX: &str = "BET_"; +pub const EMAIL_SUBJECT_API_KEY_EXPIRY: &str = "API Key Expiry Notice"; +pub const EMAIL_SUBJECT_DASHBOARD_FEATURE_REQUEST: &str = "Dashboard Pro Feature Request by"; +pub const EMAIL_SUBJECT_APPROVAL_RECON_REQUEST: &str = + "Approval of Recon Request - Access Granted to Recon Dashboard"; + pub const ROLE_INFO_CACHE_PREFIX: &str = "CR_INFO_"; #[cfg(feature = "olap")] diff --git a/crates/router/src/consts/user.rs b/crates/router/src/consts/user.rs index 6ac2b08e6b..5984a87650 100644 --- a/crates/router/src/consts/user.rs +++ b/crates/router/src/consts/user.rs @@ -26,3 +26,10 @@ pub const REDIS_TOTP_SECRET_TTL_IN_SECS: i64 = 15 * 60; // 15 minutes pub const REDIS_SSO_PREFIX: &str = "SSO_"; pub const REDIS_SSO_TTL: i64 = 5 * 60; // 5 minutes + +/// Email subject +pub const EMAIL_SUBJECT_SIGNUP: &str = "Welcome to the Hyperswitch community!"; +pub const EMAIL_SUBJECT_INVITATION: &str = "You have been invited to join Hyperswitch Community!"; +pub const EMAIL_SUBJECT_MAGIC_LINK: &str = "Unlock Hyperswitch: Use Your Magic Link to Sign In"; +pub const EMAIL_SUBJECT_RESET_PASSWORD: &str = "Get back to Hyperswitch - Reset Your Password Now"; +pub const EMAIL_SUBJECT_NEW_PROD_INTENT: &str = "New Prod Intent"; diff --git a/crates/router/src/core/recon.rs b/crates/router/src/core/recon.rs index d5f824e0cc..ea3459709c 100644 --- a/crates/router/src/core/recon.rs +++ b/crates/router/src/core/recon.rs @@ -39,7 +39,8 @@ pub async fn send_recon_request( .attach_printable("Failed to convert recipient's email to UserEmail")?, settings: state.conf.clone(), subject: format!( - "Dashboard Pro Feature Request by {}", + "{} {}", + consts::EMAIL_SUBJECT_DASHBOARD_FEATURE_REQUEST, user_email.expose().peek() ), }; @@ -145,7 +146,7 @@ pub async fn recon_merchant_account_update( .change_context(errors::ApiErrorResponse::InternalServerError) .attach_printable("Failed to form username")?, settings: state.conf.clone(), - subject: "Approval of Recon Request - Access Granted to Recon Dashboard", + subject: consts::EMAIL_SUBJECT_APPROVAL_RECON_REQUEST, }; if req.recon_status == enums::ReconStatus::Active { diff --git a/crates/router/src/core/user.rs b/crates/router/src/core/user.rs index 046675f520..c816c73a52 100644 --- a/crates/router/src/core/user.rs +++ b/crates/router/src/core/user.rs @@ -74,7 +74,7 @@ pub async fn signup_with_merchant_id( recipient_email: user_from_db.get_email().try_into()?, user_name: domain::UserName::new(user_from_db.get_name())?, settings: state.conf.clone(), - subject: "Get back to Hyperswitch - Reset Your Password Now", + subject: consts::user::EMAIL_SUBJECT_RESET_PASSWORD, auth_id, }; @@ -202,7 +202,7 @@ pub async fn connect_account( recipient_email: domain::UserEmail::from_pii_email(user_from_db.get_email())?, settings: state.conf.clone(), user_name: domain::UserName::new(user_from_db.get_name())?, - subject: "Unlock Hyperswitch: Use Your Magic Link to Sign In", + subject: consts::user::EMAIL_SUBJECT_MAGIC_LINK, auth_id, }; @@ -251,7 +251,7 @@ pub async fn connect_account( let email_contents = email_types::VerifyEmail { recipient_email: domain::UserEmail::from_pii_email(user_from_db.get_email())?, settings: state.conf.clone(), - subject: "Welcome to the Hyperswitch community!", + subject: consts::user::EMAIL_SUBJECT_SIGNUP, auth_id, }; @@ -371,7 +371,7 @@ pub async fn forgot_password( recipient_email: domain::UserEmail::from_pii_email(user_from_db.get_email())?, settings: state.conf.clone(), user_name: domain::UserName::new(user_from_db.get_name())?, - subject: "Get back to Hyperswitch - Reset Your Password Now", + subject: consts::user::EMAIL_SUBJECT_RESET_PASSWORD, auth_id, }; @@ -709,7 +709,7 @@ async fn handle_existing_user_invitation( recipient_email: invitee_email, user_name: domain::UserName::new(invitee_user_from_db.get_name())?, settings: state.conf.clone(), - subject: "You have been invited to join Hyperswitch Community!", + subject: consts::user::EMAIL_SUBJECT_INVITATION, entity, auth_id: auth_id.clone(), }; @@ -840,7 +840,7 @@ async fn handle_new_user_invitation( recipient_email: invitee_email, user_name: domain::UserName::new(new_user.get_name())?, settings: state.conf.clone(), - subject: "You have been invited to join Hyperswitch Community!", + subject: consts::user::EMAIL_SUBJECT_INVITATION, entity, auth_id: auth_id.clone(), }; @@ -959,7 +959,7 @@ pub async fn resend_invite( recipient_email: invitee_email, user_name: domain::UserName::new(user.get_name())?, settings: state.conf.clone(), - subject: "You have been invited to join Hyperswitch Community!", + subject: consts::user::EMAIL_SUBJECT_INVITATION, entity: email_types::Entity { entity_id, entity_type, @@ -1498,7 +1498,7 @@ pub async fn send_verification_mail( let email_contents = email_types::VerifyEmail { recipient_email: domain::UserEmail::from_pii_email(user.email)?, settings: state.conf.clone(), - subject: "Welcome to the Hyperswitch community!", + subject: consts::user::EMAIL_SUBJECT_SIGNUP, auth_id, }; diff --git a/crates/router/src/services/email/types.rs b/crates/router/src/services/email/types.rs index 1c4ce79ac8..cedd17828f 100644 --- a/crates/router/src/services/email/types.rs +++ b/crates/router/src/services/email/types.rs @@ -417,7 +417,7 @@ impl BizEmailProd { state.conf.email.prod_intent_recipient_email.clone(), )?, settings: state.conf.clone(), - subject: "New Prod Intent", + subject: consts::user::EMAIL_SUBJECT_NEW_PROD_INTENT, user_name: data.poc_name.unwrap_or_default().into(), poc_email: data.poc_email.unwrap_or_default().into(), legal_business_name: data.legal_business_name.unwrap_or_default(), diff --git a/crates/router/src/workflows/api_key_expiry.rs b/crates/router/src/workflows/api_key_expiry.rs index b26e9862e8..c04e4c5d57 100644 --- a/crates/router/src/workflows/api_key_expiry.rs +++ b/crates/router/src/workflows/api_key_expiry.rs @@ -6,7 +6,7 @@ use router_env::{logger, metrics::add_attributes}; use scheduler::{workflows::ProcessTrackerWorkflow, SchedulerSessionState}; use crate::{ - errors, + consts, errors, logger::error, routes::{metrics, SessionState}, services::email::types::ApiKeyExpiryReminder, @@ -81,7 +81,7 @@ impl ProcessTrackerWorkflow for ApiKeyExpiryWorkflow { ); errors::ProcessTrackerError::EApiErrorResponse })?, - subject: "API Key Expiry Notice", + subject: consts::EMAIL_SUBJECT_API_KEY_EXPIRY, expires_in: *expires_in, api_key_name, prefix,