text
stringlengths
70
351k
source
stringclasses
4 values
<|fim_prefix|> // file: hyperswitch/crates/router/src/types/domain/user.rs | crate: router use common_utils::{ crypto::Encryptable, id_type, new_type::MerchantName, pii, type_name, types::keymanager::Identifier, }; use diesel_models::{ enums::{TotpStatus, UserRoleVersion, UserStatus}, organization::{self as diesel_org, Organization, OrganizationBridge}, user as storage_user, user_role::{UserRole, UserRoleNew}, }; use {base64::Engine, common_utils::types::keymanager::EncryptionTransferRequest}; use crate::{ consts, core::{ admin, errors::{UserErrors, UserResult}, }, db::GlobalStorageInterface, routes::SessionState, services::{self, authentication::UserFromToken}, types::{domain, transformers::ForeignFrom}, utils::user::password, }; fn try_from(value: NewUser) -> UserResult<Self> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
// file: hyperswitch/crates/router/src/types/domain/user.rs | crate: router use diesel_models::{ enums::{TotpStatus, UserRoleVersion, UserStatus}, organization::{self as diesel_org, Organization, OrganizationBridge}, user as storage_user, user_role::{UserRole, UserRoleNew}, }; use crate::{ consts, core::{ admin, errors::{UserErrors, UserResult}, }, db::GlobalStorageInterface, routes::SessionState, services::{self, authentication::UserFromToken}, types::{domain, transformers::ForeignFrom}, utils::user::password, }; pub use decision_manager::*; pub async fn insert_org_level_user_role_in_db( self, state: SessionState, role_id: String, user_status: UserStatus, ) -> UserResult<UserRole> { let org_id = self .get_new_merchant() .get_new_organization() .get_organization_id(); let org_user_role = self .get_no_level_user_role(role_id, user_status) .add_entity(OrganizationLevel { tenant_id: state.tenant.tenant_id.clone(), org_id, }); org_user_role.insert_in_v2(&state).await }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/types/domain/user.rs | crate: router use common_utils::{ crypto::Encryptable, id_type, new_type::MerchantName, pii, type_name, types::keymanager::Identifier, }; use diesel_models::{ enums::{TotpStatus, UserRoleVersion, UserStatus}, organization::{self as diesel_org, Organization, OrganizationBridge}, user as storage_user, user_role::{UserRole, UserRoleNew}, }; use {base64::Engine, common_utils::types::keymanager::EncryptionTransferRequest}; use crate::{ consts, core::{ admin, errors::{UserErrors, UserResult}, }, db::GlobalStorageInterface, routes::SessionState, services::{self, authentication::UserFromToken}, types::{domain, transformers::ForeignFrom}, utils::user::password, }; pub use decision_manager::*; pub fn get_no_level_user_role( self, role_id: String, user_status: UserStatus, ) -> NewUserRole<NoLevel> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/types/domain/user.rs | crate: router use api_models::{ admin as admin_api, organization as api_org, user as user_api, user_role as user_role_api, }; use diesel_models::{ enums::{TotpStatus, UserRoleVersion, UserStatus}, organization::{self as diesel_org, Organization, OrganizationBridge}, user as storage_user, user_role::{UserRole, UserRoleNew}, }; use crate::{ consts, core::{ admin, errors::{UserErrors, UserResult}, }, db::GlobalStorageInterface, routes::SessionState, services::{self, authentication::UserFromToken}, types::{domain, transformers::ForeignFrom}, utils::user::password, }; pub use decision_manager::*; type UserMerchantCreateRequestWithToken = (UserFromStorage, user_api::UserMerchantCreate, UserFromToken); pub async fn insert_user_and_merchant_in_db( &self, state: SessionState, ) -> UserResult<UserFromStorage> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
// file: hyperswitch/crates/router/src/types/domain/user.rs | crate: router use diesel_models::{ enums::{TotpStatus, UserRoleVersion, UserStatus}, organization::{self as diesel_org, Organization, OrganizationBridge}, user as storage_user, user_role::{UserRole, UserRoleNew}, }; use error_stack::{report, ResultExt}; use crate::{ consts, core::{ admin, errors::{UserErrors, UserResult}, }, db::GlobalStorageInterface, routes::SessionState, services::{self, authentication::UserFromToken}, types::{domain, transformers::ForeignFrom}, utils::user::password, }; pub use decision_manager::*; pub async fn check_if_already_exists_in_db(&self, state: SessionState) -> UserResult<()> { if state .global_store .find_user_by_email(&self.get_email()) .await .is_ok() { return Err(report!(UserErrors::UserExists)); } Ok(()) }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/types/domain/user.rs | crate: router use api_models::{ admin as admin_api, organization as api_org, user as user_api, user_role as user_role_api, }; use diesel_models::{ enums::{TotpStatus, UserRoleVersion, UserStatus}, organization::{self as diesel_org, Organization, OrganizationBridge}, user as storage_user, user_role::{UserRole, UserRoleNew}, }; use crate::{ consts, core::{ admin, errors::{UserErrors, UserResult}, }, db::GlobalStorageInterface, routes::SessionState, services::{self, authentication::UserFromToken}, types::{domain, transformers::ForeignFrom}, utils::user::password, }; pub use decision_manager::*; type UserMerchantCreateRequestWithToken = (UserFromStorage, user_api::UserMerchantCreate, UserFromToken); pub async fn insert_user_in_db( &self, db: &dyn GlobalStorageInterface, ) -> UserResult<UserFromStorage> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/types/domain/user.rs | crate: router use diesel_models::{ enums::{TotpStatus, UserRoleVersion, UserStatus}, organization::{self as diesel_org, Organization, OrganizationBridge}, user as storage_user, user_role::{UserRole, UserRoleNew}, }; use crate::{ consts, core::{ admin, errors::{UserErrors, UserResult}, }, db::GlobalStorageInterface, routes::SessionState, services::{self, authentication::UserFromToken}, types::{domain, transformers::ForeignFrom}, utils::user::password, }; pub use decision_manager::*; pub fn get_password(&self) -> Option<UserPassword> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/types/domain/user.rs | crate: router use diesel_models::{ enums::{TotpStatus, UserRoleVersion, UserStatus}, organization::{self as diesel_org, Organization, OrganizationBridge}, user as storage_user, user_role::{UserRole, UserRoleNew}, }; use crate::{ consts, core::{ admin, errors::{UserErrors, UserResult}, }, db::GlobalStorageInterface, routes::SessionState, services::{self, authentication::UserFromToken}, types::{domain, transformers::ForeignFrom}, utils::user::password, }; pub use decision_manager::*; pub fn get_new_merchant(&self) -> NewUserMerchant { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/types/domain/user.rs | crate: router use diesel_models::{ enums::{TotpStatus, UserRoleVersion, UserStatus}, organization::{self as diesel_org, Organization, OrganizationBridge}, user as storage_user, user_role::{UserRole, UserRoleNew}, }; use crate::{ consts, core::{ admin, errors::{UserErrors, UserResult}, }, db::GlobalStorageInterface, routes::SessionState, services::{self, authentication::UserFromToken}, types::{domain, transformers::ForeignFrom}, utils::user::password, }; pub use decision_manager::*; pub fn get_email(&self) -> UserEmail { <|fim_suffix|> <|fim_middle|> }
ast_fragments
// file: hyperswitch/crates/router/src/types/domain/user.rs | crate: router use diesel_models::{ enums::{TotpStatus, UserRoleVersion, UserStatus}, organization::{self as diesel_org, Organization, OrganizationBridge}, user as storage_user, user_role::{UserRole, UserRoleNew}, }; use crate::{ consts, core::{ admin, errors::{UserErrors, UserResult}, }, db::GlobalStorageInterface, routes::SessionState, services::{self, authentication::UserFromToken}, types::{domain, transformers::ForeignFrom}, utils::user::password, }; pub use decision_manager::*; pub fn get_user_id(&self) -> String { self.user_id.clone() }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/types/domain/user.rs | crate: router use common_utils::{ crypto::Encryptable, id_type, new_type::MerchantName, pii, type_name, types::keymanager::Identifier, }; use router_env::env; use crate::{ consts, core::{ admin, errors::{UserErrors, UserResult}, }, db::GlobalStorageInterface, routes::SessionState, services::{self, authentication::UserFromToken}, types::{domain, transformers::ForeignFrom}, utils::user::password, }; type UserMerchantCreateRequestWithToken = (UserFromStorage, user_api::UserMerchantCreate, UserFromToken); fn try_from(value: UserMerchantCreateRequestWithToken) -> UserResult<Self> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
// file: hyperswitch/crates/router/src/types/domain/user.rs | crate: router use api_models::{ admin as admin_api, organization as api_org, user as user_api, user_role as user_role_api, }; type InviteeUserRequestWithInvitedUserToken = (user_api::InviteUserRequest, UserFromToken); type UserMerchantCreateRequestWithToken = (UserFromStorage, user_api::UserMerchantCreate, UserFromToken); fn from(value: (user_api::CreateTenantUserRequest, MerchantAccountIdentifier)) -> Self { let merchant_id = value.1.merchant_id.clone(); let new_organization = NewUserOrganization::from(value); Self { company_name: None, merchant_id, new_organization, product_type: None, } }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/types/domain/user.rs | crate: router use api_models::{ admin as admin_api, organization as api_org, user as user_api, user_role as user_role_api, }; use common_utils::{ crypto::Encryptable, id_type, new_type::MerchantName, pii, type_name, types::keymanager::Identifier, }; use diesel_models::{ enums::{TotpStatus, UserRoleVersion, UserStatus}, organization::{self as diesel_org, Organization, OrganizationBridge}, user as storage_user, user_role::{UserRole, UserRoleNew}, }; use crate::{ consts, core::{ admin, errors::{UserErrors, UserResult}, }, db::GlobalStorageInterface, routes::SessionState, services::{self, authentication::UserFromToken}, types::{domain, transformers::ForeignFrom}, utils::user::password, }; type InviteeUserRequestWithInvitedUserToken = (user_api::InviteUserRequest, UserFromToken); type UserMerchantCreateRequestWithToken = (UserFromStorage, user_api::UserMerchantCreate, UserFromToken); fn try_from( value: (user_api::CreateInternalUserRequest, id_type::OrganizationId), ) -> UserResult<Self> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/types/domain/user.rs | crate: router use api_models::{ admin as admin_api, organization as api_org, user as user_api, user_role as user_role_api, }; use diesel_models::{ enums::{TotpStatus, UserRoleVersion, UserStatus}, organization::{self as diesel_org, Organization, OrganizationBridge}, user as storage_user, user_role::{UserRole, UserRoleNew}, }; use masking::{ExposeInterface, PeekInterface, Secret}; use crate::{ consts, core::{ admin, errors::{UserErrors, UserResult}, }, db::GlobalStorageInterface, routes::SessionState, services::{self, authentication::UserFromToken}, types::{domain, transformers::ForeignFrom}, utils::user::password, }; fn create_merchant_account_request(&self) -> UserResult<admin_api::MerchantAccountCreate> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/types/domain/user.rs | crate: router use diesel_models::{ enums::{TotpStatus, UserRoleVersion, UserStatus}, organization::{self as diesel_org, Organization, OrganizationBridge}, user as storage_user, user_role::{UserRole, UserRoleNew}, }; use crate::{ consts, core::{ admin, errors::{UserErrors, UserResult}, }, db::GlobalStorageInterface, routes::SessionState, services::{self, authentication::UserFromToken}, types::{domain, transformers::ForeignFrom}, utils::user::password, }; pub use decision_manager::*; pub async fn check_if_already_exists_in_db(&self, state: SessionState) -> UserResult<()> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/types/domain/user.rs | crate: router use common_enums::EntityType; use diesel_models::{ enums::{TotpStatus, UserRoleVersion, UserStatus}, organization::{self as diesel_org, Organization, OrganizationBridge}, user as storage_user, user_role::{UserRole, UserRoleNew}, }; use crate::{ consts, core::{ admin, errors::{UserErrors, UserResult}, }, db::GlobalStorageInterface, routes::SessionState, services::{self, authentication::UserFromToken}, types::{domain, transformers::ForeignFrom}, utils::user::password, }; pub use decision_manager::*; pub fn get_product_type(&self) -> Option<common_enums::MerchantProductType> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/types/domain/user.rs | crate: router use diesel_models::{ enums::{TotpStatus, UserRoleVersion, UserStatus}, organization::{self as diesel_org, Organization, OrganizationBridge}, user as storage_user, user_role::{UserRole, UserRoleNew}, }; use crate::{ consts, core::{ admin, errors::{UserErrors, UserResult}, }, db::GlobalStorageInterface, routes::SessionState, services::{self, authentication::UserFromToken}, types::{domain, transformers::ForeignFrom}, utils::user::password, }; pub use decision_manager::*; pub fn get_new_organization(&self) -> NewUserOrganization { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/types/domain/user.rs | crate: router use common_utils::{ crypto::Encryptable, id_type, new_type::MerchantName, pii, type_name, types::keymanager::Identifier, }; use diesel_models::{ enums::{TotpStatus, UserRoleVersion, UserStatus}, organization::{self as diesel_org, Organization, OrganizationBridge}, user as storage_user, user_role::{UserRole, UserRoleNew}, }; use crate::{ consts, core::{ admin, errors::{UserErrors, UserResult}, }, db::GlobalStorageInterface, routes::SessionState, services::{self, authentication::UserFromToken}, types::{domain, transformers::ForeignFrom}, utils::user::password, }; pub use decision_manager::*; pub fn get_merchant_id(&self) -> id_type::MerchantId { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/types/domain/user.rs | crate: router use diesel_models::{ enums::{TotpStatus, UserRoleVersion, UserStatus}, organization::{self as diesel_org, Organization, OrganizationBridge}, user as storage_user, user_role::{UserRole, UserRoleNew}, }; use crate::{ consts, core::{ admin, errors::{UserErrors, UserResult}, }, db::GlobalStorageInterface, routes::SessionState, services::{self, authentication::UserFromToken}, types::{domain, transformers::ForeignFrom}, utils::user::password, }; pub use decision_manager::*; pub fn get_company_name(&self) -> Option<String> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/types/domain/user.rs | crate: router use crate::{ consts, core::{ admin, errors::{UserErrors, UserResult}, }, db::GlobalStorageInterface, routes::SessionState, services::{self, authentication::UserFromToken}, types::{domain, transformers::ForeignFrom}, utils::user::password, }; fn try_from(company_name: UserCompanyName) -> Result<Self, Self::Error> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/types/domain/user.rs | crate: router use std::{ collections::HashSet, ops::{Deref, Not}, str::FromStr, }; use api_models::{ admin as admin_api, organization as api_org, user as user_api, user_role as user_role_api, }; use diesel_models::{ enums::{TotpStatus, UserRoleVersion, UserStatus}, organization::{self as diesel_org, Organization, OrganizationBridge}, user as storage_user, user_role::{UserRole, UserRoleNew}, }; use crate::{ consts, core::{ admin, errors::{UserErrors, UserResult}, }, db::GlobalStorageInterface, routes::SessionState, services::{self, authentication::UserFromToken}, types::{domain, transformers::ForeignFrom}, utils::user::password, }; type InviteeUserRequestWithInvitedUserToken = (user_api::InviteUserRequest, UserFromToken); type UserMerchantCreateRequestWithToken = (UserFromStorage, user_api::UserMerchantCreate, UserFromToken); fn try_from(value: MerchantId) -> Result<Self, Self::Error> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/types/domain/user.rs | crate: router use diesel_models::{ enums::{TotpStatus, UserRoleVersion, UserStatus}, organization::{self as diesel_org, Organization, OrganizationBridge}, user as storage_user, user_role::{UserRole, UserRoleNew}, }; use crate::{ consts, core::{ admin, errors::{UserErrors, UserResult}, }, db::GlobalStorageInterface, routes::SessionState, services::{self, authentication::UserFromToken}, types::{domain, transformers::ForeignFrom}, utils::user::password, }; pub use decision_manager::*; pub fn get_secret(&self) -> String { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/types/domain/user.rs | crate: router use crate::{ consts, core::{ admin, errors::{UserErrors, UserResult}, }, db::GlobalStorageInterface, routes::SessionState, services::{self, authentication::UserFromToken}, types::{domain, transformers::ForeignFrom}, utils::user::password, }; pub use decision_manager::*; pub fn new(merchant_id: String) -> UserResult<Self> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/types/domain/user.rs | crate: router use api_models::{ admin as admin_api, organization as api_org, user as user_api, user_role as user_role_api, }; use common_utils::{ crypto::Encryptable, id_type, new_type::MerchantName, pii, type_name, types::keymanager::Identifier, }; use diesel_models::{ enums::{TotpStatus, UserRoleVersion, UserStatus}, organization::{self as diesel_org, Organization, OrganizationBridge}, user as storage_user, user_role::{UserRole, UserRoleNew}, }; use crate::{ consts, core::{ admin, errors::{UserErrors, UserResult}, }, db::GlobalStorageInterface, routes::SessionState, services::{self, authentication::UserFromToken}, types::{domain, transformers::ForeignFrom}, utils::user::password, }; fn foreign_from(item: api_models::user::UserOrgMerchantCreateRequest) -> Self { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/types/domain/user.rs | crate: router use api_models::{ admin as admin_api, organization as api_org, user as user_api, user_role as user_role_api, }; use crate::{ consts, core::{ admin, errors::{UserErrors, UserResult}, }, db::GlobalStorageInterface, routes::SessionState, services::{self, authentication::UserFromToken}, types::{domain, transformers::ForeignFrom}, utils::user::password, }; type InviteeUserRequestWithInvitedUserToken = (user_api::InviteUserRequest, UserFromToken); type UserMerchantCreateRequestWithToken = (UserFromStorage, user_api::UserMerchantCreate, UserFromToken); fn from( (_value, merchant_account_identifier): ( user_api::CreateTenantUserRequest, MerchantAccountIdentifier, ), ) -> Self { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/types/domain/user.rs | crate: router use api_models::{ admin as admin_api, organization as api_org, user as user_api, user_role as user_role_api, }; use crate::{ consts, core::{ admin, errors::{UserErrors, UserResult}, }, db::GlobalStorageInterface, routes::SessionState, services::{self, authentication::UserFromToken}, types::{domain, transformers::ForeignFrom}, utils::user::password, }; type InviteeUserRequestWithInvitedUserToken = (user_api::InviteUserRequest, UserFromToken); fn from(_value: InviteeUserRequestWithInvitedUserToken) -> Self { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/types/domain/user.rs | crate: router use diesel_models::{ enums::{TotpStatus, UserRoleVersion, UserStatus}, organization::{self as diesel_org, Organization, OrganizationBridge}, user as storage_user, user_role::{UserRole, UserRoleNew}, }; type UserMerchantCreateRequestWithToken = (UserFromStorage, user_api::UserMerchantCreate, UserFromToken); fn from(value: UserMerchantCreateRequestWithToken) -> Self { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/types/domain/user.rs | crate: router use api_models::{ admin as admin_api, organization as api_org, user as user_api, user_role as user_role_api, }; use common_utils::{ crypto::Encryptable, id_type, new_type::MerchantName, pii, type_name, types::keymanager::Identifier, }; use crate::{ consts, core::{ admin, errors::{UserErrors, UserResult}, }, db::GlobalStorageInterface, routes::SessionState, services::{self, authentication::UserFromToken}, types::{domain, transformers::ForeignFrom}, utils::user::password, }; type InviteeUserRequestWithInvitedUserToken = (user_api::InviteUserRequest, UserFromToken); type UserMerchantCreateRequestWithToken = (UserFromStorage, user_api::UserMerchantCreate, UserFromToken); fn from( (_value, org_id): (user_api::CreateInternalUserRequest, id_type::OrganizationId), ) -> Self { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/types/domain/user.rs | crate: router use api_models::{ admin as admin_api, organization as api_org, user as user_api, user_role as user_role_api, }; use crate::{ consts, core::{ admin, errors::{UserErrors, UserResult}, }, db::GlobalStorageInterface, routes::SessionState, services::{self, authentication::UserFromToken}, types::{domain, transformers::ForeignFrom}, utils::user::password, }; type InviteeUserRequestWithInvitedUserToken = (user_api::InviteUserRequest, UserFromToken); type UserMerchantCreateRequestWithToken = (UserFromStorage, user_api::UserMerchantCreate, UserFromToken); fn from(_value: user_api::ConnectAccountRequest) -> Self { <|fim_suffix|> <|fim_middle|> }
ast_fragments
// file: hyperswitch/crates/router/src/types/domain/user.rs | crate: router use api_models::{ admin as admin_api, organization as api_org, user as user_api, user_role as user_role_api, }; use crate::{ consts, core::{ admin, errors::{UserErrors, UserResult}, }, db::GlobalStorageInterface, routes::SessionState, services::{self, authentication::UserFromToken}, types::{domain, transformers::ForeignFrom}, utils::user::password, }; type InviteeUserRequestWithInvitedUserToken = (user_api::InviteUserRequest, UserFromToken); type UserMerchantCreateRequestWithToken = (UserFromStorage, user_api::UserMerchantCreate, UserFromToken); fn from(_value: user_api::SignUpRequest) -> Self { let new_organization = api_org::OrganizationNew::new(None); let db_organization = ForeignFrom::foreign_from(new_organization); Self(db_organization) }
ast_fragments
// file: hyperswitch/crates/router/src/types/domain/user.rs | crate: router use common_utils::{ crypto::Encryptable, id_type, new_type::MerchantName, pii, type_name, types::keymanager::Identifier, }; use diesel_models::{ enums::{TotpStatus, UserRoleVersion, UserStatus}, organization::{self as diesel_org, Organization, OrganizationBridge}, user as storage_user, user_role::{UserRole, UserRoleNew}, }; use crate::{ consts, core::{ admin, errors::{UserErrors, UserResult}, }, db::GlobalStorageInterface, routes::SessionState, services::{self, authentication::UserFromToken}, types::{domain, transformers::ForeignFrom}, utils::user::password, }; pub use decision_manager::*; pub fn get_organization_id(&self) -> id_type::OrganizationId { self.0.get_organization_id() }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/types/domain/user.rs | crate: router use api_models::{ admin as admin_api, organization as api_org, user as user_api, user_role as user_role_api, }; use diesel_models::{ enums::{TotpStatus, UserRoleVersion, UserStatus}, organization::{self as diesel_org, Organization, OrganizationBridge}, user as storage_user, user_role::{UserRole, UserRoleNew}, }; use crate::{ consts, core::{ admin, errors::{UserErrors, UserResult}, }, db::GlobalStorageInterface, routes::SessionState, services::{self, authentication::UserFromToken}, types::{domain, transformers::ForeignFrom}, utils::user::password, }; pub use decision_manager::*; pub async fn insert_org_in_db(self, state: SessionState) -> UserResult<Organization> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/types/domain/user.rs | crate: router use api_models::{ admin as admin_api, organization as api_org, user as user_api, user_role as user_role_api, }; use diesel_models::{ enums::{TotpStatus, UserRoleVersion, UserStatus}, organization::{self as diesel_org, Organization, OrganizationBridge}, user as storage_user, user_role::{UserRole, UserRoleNew}, }; use crate::{ consts, core::{ admin, errors::{UserErrors, UserResult}, }, db::GlobalStorageInterface, routes::SessionState, services::{self, authentication::UserFromToken}, types::{domain, transformers::ForeignFrom}, utils::user::password, }; pub use decision_manager::*; pub fn new(company_name: String) -> UserResult<Self> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/types/domain/user.rs | crate: router use diesel_models::{ enums::{TotpStatus, UserRoleVersion, UserStatus}, organization::{self as diesel_org, Organization, OrganizationBridge}, user as storage_user, user_role::{UserRole, UserRoleNew}, }; use masking::{ExposeInterface, PeekInterface, Secret}; use crate::{ consts, core::{ admin, errors::{UserErrors, UserResult}, }, db::GlobalStorageInterface, routes::SessionState, services::{self, authentication::UserFromToken}, types::{domain, transformers::ForeignFrom}, utils::user::password, }; pub use decision_manager::*; pub fn get_secret(&self) -> Secret<String> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/types/domain/user.rs | crate: router use masking::{ExposeInterface, PeekInterface, Secret}; use crate::{ consts, core::{ admin, errors::{UserErrors, UserResult}, }, db::GlobalStorageInterface, routes::SessionState, services::{self, authentication::UserFromToken}, types::{domain, transformers::ForeignFrom}, utils::user::password, }; pub use decision_manager::*; pub fn new_password_without_validation(password: Secret<String>) -> UserResult<Self> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/types/domain/user.rs | crate: router use common_utils::{ crypto::Encryptable, id_type, new_type::MerchantName, pii, type_name, types::keymanager::Identifier, }; fn try_from(value: pii::Email) -> Result<Self, Self::Error> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/types/domain/user.rs | crate: router use std::{ collections::HashSet, ops::{Deref, Not}, str::FromStr, }; use diesel_models::{ enums::{TotpStatus, UserRoleVersion, UserStatus}, organization::{self as diesel_org, Organization, OrganizationBridge}, user as storage_user, user_role::{UserRole, UserRoleNew}, }; use crate::{ consts, core::{ admin, errors::{UserErrors, UserResult}, }, db::GlobalStorageInterface, routes::SessionState, services::{self, authentication::UserFromToken}, types::{domain, transformers::ForeignFrom}, utils::user::password, }; pub use decision_manager::*; pub fn extract_domain(&self) -> UserResult<&str> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/types/domain/user.rs | crate: router use common_utils::{ crypto::Encryptable, id_type, new_type::MerchantName, pii, type_name, types::keymanager::Identifier, }; use diesel_models::{ enums::{TotpStatus, UserRoleVersion, UserStatus}, organization::{self as diesel_org, Organization, OrganizationBridge}, user as storage_user, user_role::{UserRole, UserRoleNew}, }; use masking::{ExposeInterface, PeekInterface, Secret}; use crate::{ consts, core::{ admin, errors::{UserErrors, UserResult}, }, db::GlobalStorageInterface, routes::SessionState, services::{self, authentication::UserFromToken}, types::{domain, transformers::ForeignFrom}, utils::user::password, }; pub use decision_manager::*; pub fn get_secret(self) -> Secret<String, pii::EmailStrategy> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/types/domain/user.rs | crate: router use common_utils::{ crypto::Encryptable, id_type, new_type::MerchantName, pii, type_name, types::keymanager::Identifier, }; use diesel_models::{ enums::{TotpStatus, UserRoleVersion, UserStatus}, organization::{self as diesel_org, Organization, OrganizationBridge}, user as storage_user, user_role::{UserRole, UserRoleNew}, }; use crate::{ consts, core::{ admin, errors::{UserErrors, UserResult}, }, db::GlobalStorageInterface, routes::SessionState, services::{self, authentication::UserFromToken}, types::{domain, transformers::ForeignFrom}, utils::user::password, }; pub use decision_manager::*; pub fn get_inner(&self) -> &pii::Email { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/types/domain/user.rs | crate: router use common_utils::{ crypto::Encryptable, id_type, new_type::MerchantName, pii, type_name, types::keymanager::Identifier, }; use diesel_models::{ enums::{TotpStatus, UserRoleVersion, UserStatus}, organization::{self as diesel_org, Organization, OrganizationBridge}, user as storage_user, user_role::{UserRole, UserRoleNew}, }; use crate::{ consts, core::{ admin, errors::{UserErrors, UserResult}, }, db::GlobalStorageInterface, routes::SessionState, services::{self, authentication::UserFromToken}, types::{domain, transformers::ForeignFrom}, utils::user::password, }; pub use decision_manager::*; pub fn into_inner(self) -> pii::Email { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/types/domain/user.rs | crate: router use common_utils::{ crypto::Encryptable, id_type, new_type::MerchantName, pii, type_name, types::keymanager::Identifier, }; use crate::{ consts, core::{ admin, errors::{UserErrors, UserResult}, }, db::GlobalStorageInterface, routes::SessionState, services::{self, authentication::UserFromToken}, types::{domain, transformers::ForeignFrom}, utils::user::password, }; pub use decision_manager::*; pub fn from_pii_email(email: pii::Email) -> UserResult<Self> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/types/domain/user.rs | crate: router pub struct UserEmail(pii::Email); static BLOCKED_EMAIL: Lazy<HashSet<String>> = Lazy::new(|| { let blocked_emails_content = include_str!("../../utils/user/blocker_emails.txt"); let blocked_emails: HashSet<String> = blocked_emails_content .lines() .map(|s| s.trim().to_owned()) .collect(); blocked_emails }); impl UserEmail { pub fn new(email: Secret<String, pii::EmailStrategy>) -> UserResult<Self> { use validator::ValidateEmail; let email_string = email.expose().to_lowercase(); let email = pii::Email::from_str(&email_string).change_context(UserErrors::EmailParsingError)?; if email_string.validate_email() { let (_username, domain) = match email_string.as_str().split_once('@') { Some((u, d)) => (u, d), None => return Err(UserErrors::EmailParsingError.into()), }; pub fn new(email: Secret<String, pii::EmailStrategy>) -> UserResult<Self> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/types/domain/user.rs | crate: router use common_utils::{ crypto::Encryptable, id_type, new_type::MerchantName, pii, type_name, types::keymanager::Identifier, }; use masking::{ExposeInterface, PeekInterface, Secret}; use crate::{ consts, core::{ admin, errors::{UserErrors, UserResult}, }, db::GlobalStorageInterface, routes::SessionState, services::{self, authentication::UserFromToken}, types::{domain, transformers::ForeignFrom}, utils::user::password, }; fn try_from(value: pii::Email) -> UserResult<Self> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/types/domain/user.rs | crate: router use api_models::{ admin as admin_api, organization as api_org, user as user_api, user_role as user_role_api, }; use diesel_models::{ enums::{TotpStatus, UserRoleVersion, UserStatus}, organization::{self as diesel_org, Organization, OrganizationBridge}, user as storage_user, user_role::{UserRole, UserRoleNew}, }; use masking::{ExposeInterface, PeekInterface, Secret}; use crate::{ consts, core::{ admin, errors::{UserErrors, UserResult}, }, db::GlobalStorageInterface, routes::SessionState, services::{self, authentication::UserFromToken}, types::{domain, transformers::ForeignFrom}, utils::user::password, }; pub use decision_manager::*; pub fn new(name: Secret<String>) -> UserResult<Self> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/types/domain/user/dashboard_metadata.rs | crate: router fn from(value: &MetaData) -> Self { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/types/domain/user/dashboard_metadata.rs | crate: router fn from(value: &MetaData) -> Self { { MetaData::ProductionAgreement(_) => Self::ProductionAgreement,<|fim_suffix|> <|fim_middle|> MetaData::ReconStatus(_) => Self::ReconStatus, } }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/types/domain/user/decision_manager.rs | crate: router use diesel_models::{enums::UserStatus, user_role::UserRole}; use masking::Secret; use crate::{ core::errors::{UserErrors, UserResult}, db::user_role::ListUserRolesByUserIdPayload, routes::SessionState, services::authentication as auth, utils, }; pub async fn get_token(&self, state: &SessionState) -> UserResult<Secret<String>> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/types/domain/user/decision_manager.rs | crate: router use diesel_models::{enums::UserStatus, user_role::UserRole}; use masking::Secret; use crate::{ core::errors::{UserErrors, UserResult}, db::user_role::ListUserRolesByUserIdPayload, routes::SessionState, services::authentication as auth, utils, }; pub async fn get_token_with_user_role( &self, state: &SessionState, user_role: &UserRole, ) -> UserResult<Secret<String>> { { UserFlow::SPTFlow(spt_flow) => spt_flow.generate_spt(state, self).await,<|fim_suffix|> <|fim_middle|> UserFlow::JWTFlow(jwt_flow) => { #[cfg(feature = "email")] { self.user.get_verification_days_left(state)?; } utils::user_role::set_role_info_in_cache_by_user_role(state, user_role).await; jwt_flow.generate_jwt(state, self, user_role).await } } }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/types/domain/user/decision_manager.rs | crate: router fn get_flows(&self) -> &'static [UserFlow] { { Self::SignInWithSSO => &SIGNIN_WITH_SSO_FLOW,<|fim_suffix|> <|fim_middle|> Self::ResetPassword => &RESET_PASSWORD_FLOW, } }
ast_fragments
// file: hyperswitch/crates/router/src/types/domain/user/decision_manager.rs | crate: router fn from(value: JWTFlow) -> Self { Self::JWTFlow(value) }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/types/domain/user/decision_manager.rs | crate: router fn from(value: SPTFlow) -> Self { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/types/domain/user/decision_manager.rs | crate: router fn from(value: JWTFlow) -> Self { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/types/domain/user/decision_manager.rs | crate: router fn from(value: UserFlow) -> Self { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/types/domain/user/decision_manager.rs | crate: router use super::UserFromStorage; use crate::{ core::errors::{UserErrors, UserResult}, db::user_role::ListUserRolesByUserIdPayload, routes::SessionState, services::authentication as auth, utils, }; pub async fn skip(self, user: UserFromStorage, state: &SessionState) -> UserResult<Self> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/types/domain/user/decision_manager.rs | crate: router use diesel_models::{enums::UserStatus, user_role::UserRole}; use masking::Secret; use crate::{ core::errors::{UserErrors, UserResult}, db::user_role::ListUserRolesByUserIdPayload, routes::SessionState, services::authentication as auth, utils, }; pub async fn get_token_with_user_role( &self, state: &SessionState, user_role: &UserRole, ) -> UserResult<Secret<String>> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/types/domain/user/decision_manager.rs | crate: router pub fn get_flow(&self) -> UserFlow { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/types/domain/user/decision_manager.rs | crate: router use super::UserFromStorage; use crate::{ core::errors::{UserErrors, UserResult}, db::user_role::ListUserRolesByUserIdPayload, routes::SessionState, services::authentication as auth, utils, }; pub async fn from_origin( origin: Origin, user: UserFromStorage, state: &SessionState, ) -> UserResult<Self> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/types/domain/user/decision_manager.rs | crate: router use super::UserFromStorage; use crate::{ core::errors::{UserErrors, UserResult}, db::user_role::ListUserRolesByUserIdPayload, routes::SessionState, services::authentication as auth, utils, }; pub async fn next(self, user: UserFromStorage, state: &SessionState) -> UserResult<NextFlow> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/types/domain/user/decision_manager.rs | crate: router use crate::{ core::errors::{UserErrors, UserResult}, db::user_role::ListUserRolesByUserIdPayload, routes::SessionState, services::authentication as auth, utils, }; pub fn new( token: auth::UserFromSinglePurposeToken, current_flow: UserFlow, ) -> UserResult<Self> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/types/domain/user/decision_manager.rs | crate: router fn get_flows(&self) -> &'static [UserFlow] { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/types/domain/user/decision_manager.rs | crate: router use diesel_models::{enums::UserStatus, user_role::UserRole}; use masking::Secret; use crate::{ core::errors::{UserErrors, UserResult}, db::user_role::ListUserRolesByUserIdPayload, routes::SessionState, services::authentication as auth, utils, }; pub async fn generate_jwt( self, state: &SessionState, next_flow: &NextFlow, user_role: &UserRole, ) -> UserResult<Secret<String>> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/types/domain/user/decision_manager.rs | crate: router use super::UserFromStorage; use crate::{ core::errors::{UserErrors, UserResult}, db::user_role::ListUserRolesByUserIdPayload, routes::SessionState, services::authentication as auth, utils, }; async fn is_required( &self, _user: &UserFromStorage, _state: &SessionState, ) -> UserResult<bool> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/types/domain/user/decision_manager.rs | crate: router use masking::Secret; use crate::{ core::errors::{UserErrors, UserResult}, db::user_role::ListUserRolesByUserIdPayload, routes::SessionState, services::authentication as auth, utils, }; pub async fn generate_spt( self, state: &SessionState, next_flow: &NextFlow, ) -> UserResult<Secret<String>> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/types/domain/user/decision_manager.rs | crate: router use common_enums::TokenPurpose; use common_utils::id_type; use super::UserFromStorage; use crate::{ core::errors::{UserErrors, UserResult}, db::user_role::ListUserRolesByUserIdPayload, routes::SessionState, services::authentication as auth, utils, }; async fn is_required( &self, user: &UserFromStorage, path: &[TokenPurpose], state: &SessionState, user_tenant_id: &id_type::TenantId, ) -> UserResult<bool> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/workflows/outgoing_webhook_retry.rs | crate: router use api_models::{ enums::EventType, webhook_events::OutgoingWebhookRequestContent, webhooks::{OutgoingWebhook, OutgoingWebhookContent}, }; use common_utils::{ consts::DEFAULT_LOCALE, ext_traits::{StringExt, ValueExt}, }; use scheduler::{ consumer::{self, workflows::ProcessTrackerWorkflow}, types::process_data, utils as scheduler_utils, }; use crate::core::payouts; use crate::{ core::{ payments, webhooks::{self as webhooks_core, types::OutgoingWebhookTrackingData}, }, db::StorageInterface, errors, logger, routes::{app::ReqState, SessionState}, types::{domain, storage}, }; pub(crate) async fn get_webhook_delivery_retry_schedule_time( db: &dyn StorageInterface, merchant_id: &common_utils::id_type::MerchantId, retry_count: i32, ) -> Option<time::PrimitiveDateTime> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/workflows/outgoing_webhook_retry.rs | crate: router use common_utils::{ consts::DEFAULT_LOCALE, ext_traits::{StringExt, ValueExt}, }; use diesel_models::process_tracker::business_status; use crate::core::payouts; use crate::{ core::{ payments, webhooks::{self as webhooks_core, types::OutgoingWebhookTrackingData}, }, db::StorageInterface, errors, logger, routes::{app::ReqState, SessionState}, types::{domain, storage}, }; pub(crate) async fn retry_webhook_delivery_task( db: &dyn StorageInterface, merchant_id: &common_utils::id_type::MerchantId, process: storage::ProcessTracker, ) -> errors::CustomResult<(), errors::StorageError> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
// file: hyperswitch/crates/router/src/workflows/outgoing_webhook_retry.rs | crate: router use common_utils::{ consts::DEFAULT_LOCALE, ext_traits::{StringExt, ValueExt}, }; use diesel_models::process_tracker::business_status; use crate::core::payouts; use crate::{ core::{ payments, webhooks::{self as webhooks_core, types::OutgoingWebhookTrackingData}, }, db::StorageInterface, errors, logger, routes::{app::ReqState, SessionState}, types::{domain, storage}, }; pub(crate) async fn retry_webhook_delivery_task( db: &dyn StorageInterface, merchant_id: &common_utils::id_type::MerchantId, process: storage::ProcessTracker, ) -> errors::CustomResult<(), errors::StorageError> { let schedule_time = get_webhook_delivery_retry_schedule_time(db, merchant_id, process.retry_count + 1).await; match schedule_time { Some(schedule_time) => { db.as_scheduler() .retry_process(process, schedule_time) .await } None => { db.as_scheduler() .finish_process_with_business_status(process, business_status::RETRIES_EXCEEDED) .await } } }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/workflows/outgoing_webhook_retry.rs | crate: router use router_env::tracing::{self, instrument}; use scheduler::{ consumer::{self, workflows::ProcessTrackerWorkflow}, types::process_data, utils as scheduler_utils, }; use crate::{ core::{ payments, webhooks::{self as webhooks_core, types::OutgoingWebhookTrackingData}, }, db::StorageInterface, errors, logger, routes::{app::ReqState, SessionState}, types::{domain, storage}, }; async fn error_handler<'a>( &'a self, state: &'a SessionState, process: storage::ProcessTracker, error: errors::ProcessTrackerError, ) -> errors::CustomResult<(), errors::ProcessTrackerError> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
// file: hyperswitch/crates/router/src/workflows/outgoing_webhook_retry.rs | crate: router use router_env::tracing::{self, instrument}; use scheduler::{ consumer::{self, workflows::ProcessTrackerWorkflow}, types::process_data, utils as scheduler_utils, }; use crate::{ core::{ payments, webhooks::{self as webhooks_core, types::OutgoingWebhookTrackingData}, }, db::StorageInterface, errors, logger, routes::{app::ReqState, SessionState}, types::{domain, storage}, }; async fn execute_workflow<'a>( &'a self, _state: &'a SessionState, _process: storage::ProcessTracker, ) -> Result<(), errors::ProcessTrackerError> { todo!() }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/workflows/outgoing_webhook_retry.rs | crate: router use api_models::payouts as payout_models; use api_models::{ enums::EventType, webhook_events::OutgoingWebhookRequestContent, webhooks::{OutgoingWebhook, OutgoingWebhookContent}, }; use common_utils::{ consts::DEFAULT_LOCALE, ext_traits::{StringExt, ValueExt}, }; use diesel_models::process_tracker::business_status; use error_stack::ResultExt; use masking::PeekInterface; use router_env::tracing::{self, instrument}; use scheduler::{ consumer::{self, workflows::ProcessTrackerWorkflow}, types::process_data, utils as scheduler_utils, }; use crate::core::payouts; use crate::{ core::{ payments, webhooks::{self as webhooks_core, types::OutgoingWebhookTrackingData}, }, db::StorageInterface, errors, logger, routes::{app::ReqState, SessionState}, types::{domain, storage}, }; async fn get_outgoing_webhook_content_and_event_type( state: SessionState, req_state: ReqState, merchant_account: domain::MerchantAccount, key_store: domain::MerchantKeyStore, tracking_data: &OutgoingWebhookTrackingData, ) -> Result<(OutgoingWebhookContent, Option<EventType>), errors::ProcessTrackerError> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/workflows/payment_sync.rs | crate: router /// "frequency": [300], /// "count": [5] /// }, /// "max_retries_count": 5 /// } /// ``` /// /// This config represents /// /// `start_after`: The first psync should happen after 60 seconds /// /// `frequency` and `count`: The next 5 retries should have an interval of 300 seconds between them pub async fn get_sync_process_schedule_time( db: &dyn StorageInterface, connector: &str, merchant_id: &common_utils::id_type::MerchantId, retry_count: i32, ) -> Result<Option<time::PrimitiveDateTime>, errors::ProcessTrackerError> { let mapping: common_utils::errors::CustomResult< process_data::ConnectorPTMapping, errors::StorageError, > = db .find_config_by_key(&format!("pt_mapping_{connector}")) .await .map(|value| value.config) /// } /// ``` /// /// This config represents /// /// `start_after`: The first psync should happen after 60 seconds /// /// `frequency` and `count`: The next 5 retries should have an interval of 300 seconds between them pub async fn get_sync_process_schedule_time( db: &dyn StorageInterface, connector: &str, merchant_id: &common_utils::id_type::MerchantId, retry_count: i32, ) -> Result<Option<time::PrimitiveDateTime>, errors::ProcessTrackerError> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/workflows/payment_sync.rs | crate: router #[async_trait::async_trait] impl ProcessTrackerWorkflow<SessionState> for PaymentsSyncWorkflow { #[cfg(feature = "v2")] async fn execute_workflow<'a>( &'a self, _state: &'a SessionState, _process: storage::ProcessTracker, ) -> Result<(), sch_errors::ProcessTrackerError> { todo!() } #[cfg(feature = "v1")] async fn execute_workflow<'a>( &'a self, state: &'a SessionState, process: storage::ProcessTracker, ) -> Result<(), sch_errors::ProcessTrackerError> { let db: &dyn StorageInterface = &*state.store; let tracking_data: api::PaymentsRetrieveRequest = process .tracking_data .clone() .parse_value("PaymentsRetrieveRequest")?; let key_manager_state = &state.into(); let key_store = db .get_merchant_key_store_by_merchant_id( async fn execute_workflow<'a>( &'a self, state: &'a SessionState, process: storage::ProcessTracker, ) -> Result<(), sch_errors::ProcessTrackerError> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/workflows/payment_sync.rs | crate: router use common_utils::ext_traits::{OptionExt, StringExt, ValueExt}; use scheduler::{ consumer::{self, types::process_data, workflows::ProcessTrackerWorkflow}, errors as sch_errors, utils as scheduler_utils, }; fn test_get_default_schedule_time() { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/workflows/payment_sync.rs | crate: router use common_utils::ext_traits::{OptionExt, StringExt, ValueExt}; use diesel_models::process_tracker::business_status; use scheduler::{ consumer::{self, types::process_data, workflows::ProcessTrackerWorkflow}, errors as sch_errors, utils as scheduler_utils, }; use crate::{ consts, core::{ errors::StorageErrorExt, payments::{self as payment_flows, operations}, }, db::StorageInterface, errors, routes::SessionState, services, types::{ api, storage::{self, enums}, }, utils, }; /// Schedule the task for retry /// /// Returns bool which indicates whether this was the last retry or not pub async fn retry_sync_task( db: &dyn StorageInterface, connector: String, merchant_id: common_utils::id_type::MerchantId, pt: storage::ProcessTracker, ) -> Result<bool, sch_errors::ProcessTrackerError> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/workflows/payment_sync.rs | crate: router use scheduler::{ consumer::{self, types::process_data, workflows::ProcessTrackerWorkflow}, errors as sch_errors, utils as scheduler_utils, }; use crate::{ consts, core::{ errors::StorageErrorExt, payments::{self as payment_flows, operations}, }, db::StorageInterface, errors, routes::SessionState, services, types::{ api, storage::{self, enums}, }, utils, }; async fn error_handler<'a>( &'a self, state: &'a SessionState, process: storage::ProcessTracker, error: sch_errors::ProcessTrackerError, ) -> errors::CustomResult<(), sch_errors::ProcessTrackerError> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/workflows/payment_sync.rs | crate: router use scheduler::{ consumer::{self, types::process_data, workflows::ProcessTrackerWorkflow}, errors as sch_errors, utils as scheduler_utils, }; use crate::{ consts, core::{ errors::StorageErrorExt, payments::{self as payment_flows, operations}, }, db::StorageInterface, errors, routes::SessionState, services, types::{ api, storage::{self, enums}, }, utils, }; async fn execute_workflow<'a>( &'a self, _state: &'a SessionState, _process: storage::ProcessTracker, ) -> Result<(), sch_errors::ProcessTrackerError> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
// file: hyperswitch/crates/router/src/workflows/payment_sync.rs | crate: router use common_utils::ext_traits::{OptionExt, StringExt, ValueExt}; use diesel_models::process_tracker::business_status; use router_env::logger; use scheduler::{ consumer::{self, types::process_data, workflows::ProcessTrackerWorkflow}, errors as sch_errors, utils as scheduler_utils, }; use crate::{ consts, core::{ errors::StorageErrorExt, payments::{self as payment_flows, operations}, }, db::StorageInterface, errors, routes::SessionState, services, types::{ api, storage::{self, enums}, }, utils, }; async fn execute_workflow<'a>( &'a self, state: &'a SessionState, process: storage::ProcessTracker, ) -> Result<(), sch_errors::ProcessTrackerError> { let db: &dyn StorageInterface = &*state.store; let tracking_data: api::PaymentsRetrieveRequest = process .tracking_data .clone() .parse_value("PaymentsRetrieveRequest")?; let key_manager_state = &state.into(); let key_store = db .get_merchant_key_store_by_merchant_id( key_manager_state, tracking_data .merchant_id .as_ref() .get_required_value("merchant_id")?, &db.get_master_key().to_vec().into(), ) .await?; let merchant_account = db .find_merchant_account_by_merchant_id( key_manager_state, tracking_data .merchant_id .as_ref() .get_required_value("merchant_id")?, &key_store, ) .await?; // TODO: Add support for ReqState in PT flows let (mut payment_data, _, customer, _, _) = Box::pin(payment_flows::payments_operation_core::< api::PSync, _, _, _, payment_flows::PaymentData<api::PSync>, >( state, state.get_req_state(), merchant_account.clone(), None, key_store.clone(), operations::PaymentStatus, tracking_data.clone(), payment_flows::CallConnectorAction::Trigger, services::AuthFlow::Client, None, hyperswitch_domain_models::payments::HeaderPayload::default(), None, //Platform merchant account )) .await?; let terminal_status = [ enums::AttemptStatus::RouterDeclined, enums::AttemptStatus::Charged, enums::AttemptStatus::AutoRefunded, enums::AttemptStatus::Voided, enums::AttemptStatus::VoidFailed, enums::AttemptStatus::CaptureFailed, enums::AttemptStatus::Failure, ]; match &payment_data.payment_attempt.status { status if terminal_status.contains(status) => { state .store .as_scheduler() .finish_process_with_business_status(process, business_status::COMPLETED_BY_PT) .await? } _ => { let connector = payment_data .payment_attempt .connector .clone() .ok_or(sch_errors::ProcessTrackerError::MissingRequiredField)?; let is_last_retry = retry_sync_task( db, connector, payment_data.payment_attempt.merchant_id.clone(), process, ) .await?; // If the payment status is still processing and there is no connector transaction_id // then change the payment status to failed if all retries exceeded if is_last_retry && payment_data.payment_attempt.status == enums::AttemptStatus::Pending && payment_data .payment_attempt .connector_transaction_id .as_ref() .is_none() { let payment_intent_update = hyperswitch_domain_models::payments::payment_intent::PaymentIntentUpdate::PGStatusUpdate { status: api_models::enums::IntentStatus::Failed,updated_by: merchant_account.storage_scheme.to_string(), incremental_authorization_allowed: Some(false) }; let payment_attempt_update = hyperswitch_domain_models::payments::payment_attempt::PaymentAttemptUpdate::ErrorUpdate { connector: None, status: api_models::enums::AttemptStatus::Failure, error_code: None, error_message: None, error_reason: Some(Some( consts::REQUEST_TIMEOUT_ERROR_MESSAGE_FROM_PSYNC.to_string(), )), amount_capturable: Some(common_utils::types::MinorUnit::new(0)), updated_by: merchant_account.storage_scheme.to_string(), unified_code: None, unified_message: None, connector_transaction_id: None, payment_method_data: None, authentication_type: None, issuer_error_code: None, issuer_error_message: None, }; payment_data.payment_attempt = db .update_payment_attempt_with_attempt_id( payment_data.payment_attempt, payment_attempt_update, merchant_account.storage_scheme, ) .await .to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)?; payment_data.payment_intent = db .update_payment_intent( &state.into(), payment_data.payment_intent, payment_intent_update, &key_store, merchant_account.storage_scheme, ) .await .to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)?; let profile_id = payment_data .payment_intent .profile_id .as_ref() .get_required_value("profile_id") .change_context(errors::ApiErrorResponse::InternalServerError) .attach_printable("Could not find profile_id in payment intent")?; let business_profile = db .find_business_profile_by_profile_id( key_manager_state, &key_store, profile_id, ) .await .to_not_found_response(errors::ApiErrorResponse::ProfileNotFound { id: profile_id.get_string_repr().to_owned(), })?; // Trigger the outgoing webhook to notify the merchant about failed payment let operation = operations::PaymentStatus; Box::pin(utils::trigger_payments_webhook( merchant_account, business_profile, &key_store, payment_data, customer, state, operation, )) .await .map_err(|error| logger::warn!(payments_outgoing_webhook_error=?error)) .ok(); } } }; Ok(()) }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/workflows/payment_method_status_update.rs | crate: router use scheduler::{ consumer::types::process_data, utils as pt_utils, workflows::ProcessTrackerWorkflow, }; use crate::{ errors, logger::error, routes::SessionState, types::storage::{self, PaymentMethodStatusTrackingData}, }; async fn execute_workflow<'a>( &'a self, state: &'a SessionState, process: storage::ProcessTracker, ) -> Result<(), errors::ProcessTrackerError> { { Some(s_time) => db .as_scheduler() .retry_process(process, s_time) .await .map_err(Into::<errors::ProcessTrackerError>::into)?,<|fim_suffix|> <|fim_middle|> None => db .as_scheduler() .finish_process_with_business_status(process, "RETRIES_EXCEEDED") .await .map_err(Into::<errors::ProcessTrackerError>::into)?, } }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/utils/ext_traits.rs | crate: router use crate::{ core::errors::{self, ApiErrorResponse, CustomResult, RouterResult}, utils::when, }; fn validate_opt(self, func: F) -> CustomResult<(), errors::ValidationError> { { Some(val) => func(val),<|fim_suffix|> <|fim_middle|> None => Ok(()), } }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/utils/ext_traits.rs | crate: router use error_stack::{Report, ResultExt}; use crate::{ core::errors::{self, ApiErrorResponse, CustomResult, RouterResult}, utils::when, }; fn get_required_value(self, field_name: &'static str) -> RouterResult<T> { { Some(v) => Ok(v),<|fim_suffix|> <|fim_middle|> None => Err( Report::new(ApiErrorResponse::MissingRequiredField { field_name }) .attach_printable(format!("Missing required field {field_name}")), ), } }
ast_fragments
// file: hyperswitch/crates/router/src/utils/ext_traits.rs | crate: router use crate::{ core::errors::{self, ApiErrorResponse, CustomResult, RouterResult}, utils::when, }; fn validate_opt(self, func: F) -> CustomResult<(), errors::ValidationError> { match self { Some(val) => func(val), None => Ok(()), } }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/utils/ext_traits.rs | crate: router use error_stack::{Report, ResultExt}; use crate::{ core::errors::{self, ApiErrorResponse, CustomResult, RouterResult}, utils::when, }; fn get_required_value(self, field_name: &'static str) -> RouterResult<T> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/utils/ext_traits.rs | crate: router use error_stack::{Report, ResultExt}; use crate::{ core::errors::{self, ApiErrorResponse, CustomResult, RouterResult}, utils::when, }; fn check_value_present(&self, field_name: &'static str) -> RouterResult<()> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/utils/user.rs | crate: router use api_models::user as user_api; use common_enums::UserAuthType; use common_utils::{ encryption::Encryption, errors::CustomResult, id_type, type_name, types::keymanager::Identifier, }; use diesel_models::organization::{self, OrganizationBridge}; use masking::{ExposeInterface, Secret}; use router_env::env; use crate::{ consts::user::{REDIS_SSO_PREFIX, REDIS_SSO_TTL}, core::errors::{StorageError, UserErrors, UserResult}, routes::SessionState, services::{ authentication::{AuthToken, UserFromToken}, authorization::roles::RoleInfo, }, types::{ domain::{self, MerchantAccount, UserFromStorage}, transformers::ForeignFrom, }, }; pub fn create_merchant_account_request_for_org( req: user_api::UserOrgMerchantCreateRequest, org: organization::Organization, product_type: common_enums::MerchantProductType, ) -> UserResult<api_models::admin::MerchantAccountCreate> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/utils/user.rs | crate: router use api_models::user as user_api; use common_utils::{ encryption::Encryption, errors::CustomResult, id_type, type_name, types::keymanager::Identifier, }; use diesel_models::organization::{self, OrganizationBridge}; use masking::{ExposeInterface, Secret}; use crate::{ consts::user::{REDIS_SSO_PREFIX, REDIS_SSO_TTL}, core::errors::{StorageError, UserErrors, UserResult}, routes::SessionState, services::{ authentication::{AuthToken, UserFromToken}, authorization::roles::RoleInfo, }, types::{ domain::{self, MerchantAccount, UserFromStorage}, transformers::ForeignFrom, }, }; pub async fn decrypt_oidc_private_config( state: &SessionState, encrypted_config: Option<Encryption>, id: String, ) -> UserResult<user_api::OpenIdConnectPrivateConfig> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/utils/user.rs | crate: router use api_models::user as user_api; use common_utils::{ encryption::Encryption, errors::CustomResult, id_type, type_name, types::keymanager::Identifier, }; use diesel_models::organization::{self, OrganizationBridge}; use masking::{ExposeInterface, Secret}; use crate::{ consts::user::{REDIS_SSO_PREFIX, REDIS_SSO_TTL}, core::errors::{StorageError, UserErrors, UserResult}, routes::SessionState, services::{ authentication::{AuthToken, UserFromToken}, authorization::roles::RoleInfo, }, types::{ domain::{self, MerchantAccount, UserFromStorage}, transformers::ForeignFrom, }, }; pub async fn construct_public_and_private_db_configs( state: &SessionState, auth_config: &user_api::AuthConfig, encryption_key: &[u8], id: String, ) -> UserResult<(Option<Encryption>, Option<serde_json::Value>)> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/utils/user.rs | crate: router use diesel_models::organization::{self, OrganizationBridge}; use crate::{ consts::user::{REDIS_SSO_PREFIX, REDIS_SSO_TTL}, core::errors::{StorageError, UserErrors, UserResult}, routes::SessionState, services::{ authentication::{AuthToken, UserFromToken}, authorization::roles::RoleInfo, }, types::{ domain::{self, MerchantAccount, UserFromStorage}, transformers::ForeignFrom, }, }; pub async fn get_merchant_account_from_db( &self, state: SessionState, ) -> UserResult<MerchantAccount> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/utils/user.rs | crate: router use common_enums::UserAuthType; pub fn is_sso_auth_type(auth_type: UserAuthType) -> bool { { UserAuthType::OpenIdConnect => true,<|fim_suffix|> <|fim_middle|> UserAuthType::Password | UserAuthType::MagicLink => false, } }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/utils/user.rs | crate: router use api_models::user as user_api; fn foreign_from(from: &user_api::AuthConfig) -> Self { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/utils/user.rs | crate: router use common_enums::UserAuthType; use crate::{ consts::user::{REDIS_SSO_PREFIX, REDIS_SSO_TTL}, core::errors::{StorageError, UserErrors, UserResult}, routes::SessionState, services::{ authentication::{AuthToken, UserFromToken}, authorization::roles::RoleInfo, }, types::{ domain::{self, MerchantAccount, UserFromStorage}, transformers::ForeignFrom, }, }; pub async fn validate_email_domain_auth_type_using_db( state: &SessionState, email: &domain::UserEmail, required_auth_type: UserAuthType, ) -> UserResult<()> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/utils/user.rs | crate: router use common_enums::UserAuthType; pub fn is_sso_auth_type(auth_type: UserAuthType) -> bool { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/utils/user.rs | crate: router use api_models::user as user_api; use crate::{ consts::user::{REDIS_SSO_PREFIX, REDIS_SSO_TTL}, core::errors::{StorageError, UserErrors, UserResult}, routes::SessionState, services::{ authentication::{AuthToken, UserFromToken}, authorization::roles::RoleInfo, }, types::{ domain::{self, MerchantAccount, UserFromStorage}, transformers::ForeignFrom, }, }; pub fn get_oidc_sso_redirect_url(state: &SessionState, provider: &str) -> String { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/utils/user.rs | crate: router use crate::{ consts::user::{REDIS_SSO_PREFIX, REDIS_SSO_TTL}, core::errors::{StorageError, UserErrors, UserResult}, routes::SessionState, services::{ authentication::{AuthToken, UserFromToken}, authorization::roles::RoleInfo, }, types::{ domain::{self, MerchantAccount, UserFromStorage}, transformers::ForeignFrom, }, }; fn get_oidc_key(oidc_state: &str) -> String { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/utils/user.rs | crate: router use masking::{ExposeInterface, Secret}; use crate::{ consts::user::{REDIS_SSO_PREFIX, REDIS_SSO_TTL}, core::errors::{StorageError, UserErrors, UserResult}, routes::SessionState, services::{ authentication::{AuthToken, UserFromToken}, authorization::roles::RoleInfo, }, types::{ domain::{self, MerchantAccount, UserFromStorage}, transformers::ForeignFrom, }, }; pub async fn get_sso_id_from_redis( state: &SessionState, oidc_state: Secret<String>, ) -> UserResult<String> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/utils/user.rs | crate: router use masking::{ExposeInterface, Secret}; use crate::{ consts::user::{REDIS_SSO_PREFIX, REDIS_SSO_TTL}, core::errors::{StorageError, UserErrors, UserResult}, routes::SessionState, services::{ authentication::{AuthToken, UserFromToken}, authorization::roles::RoleInfo, }, types::{ domain::{self, MerchantAccount, UserFromStorage}, transformers::ForeignFrom, }, }; pub async fn set_sso_id_in_redis( state: &SessionState, oidc_state: Secret<String>, sso_id: String, ) -> UserResult<()> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/utils/user.rs | crate: router use common_utils::{ encryption::Encryption, errors::CustomResult, id_type, type_name, types::keymanager::Identifier, }; use crate::{ consts::user::{REDIS_SSO_PREFIX, REDIS_SSO_TTL}, core::errors::{StorageError, UserErrors, UserResult}, routes::SessionState, services::{ authentication::{AuthToken, UserFromToken}, authorization::roles::RoleInfo, }, types::{ domain::{self, MerchantAccount, UserFromStorage}, transformers::ForeignFrom, }, }; pub fn parse_value<T>(value: serde_json::Value, type_name: &str) -> UserResult<T> where T: serde::de::DeserializeOwned, { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/utils/user.rs | crate: router use api_models::user as user_api; fn foreign_from(from: &user_api::AuthConfig) -> Self { { user_api::AuthConfig::OpenIdConnect { .. } => Self::OpenIdConnect,<|fim_suffix|> <|fim_middle|> user_api::AuthConfig::MagicLink => Self::MagicLink, } }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/utils/user.rs | crate: router use std::sync::Arc; use redis_interface::RedisConnectionPool; use crate::{ consts::user::{REDIS_SSO_PREFIX, REDIS_SSO_TTL}, core::errors::{StorageError, UserErrors, UserResult}, routes::SessionState, services::{ authentication::{AuthToken, UserFromToken}, authorization::roles::RoleInfo, }, types::{ domain::{self, MerchantAccount, UserFromStorage}, transformers::ForeignFrom, }, }; pub fn get_redis_connection(state: &SessionState) -> UserResult<Arc<RedisConnectionPool>> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/utils/user.rs | crate: router use common_utils::{ encryption::Encryption, errors::CustomResult, id_type, type_name, types::keymanager::Identifier, }; use crate::{ consts::user::{REDIS_SSO_PREFIX, REDIS_SSO_TTL}, core::errors::{StorageError, UserErrors, UserResult}, routes::SessionState, services::{ authentication::{AuthToken, UserFromToken}, authorization::roles::RoleInfo, }, types::{ domain::{self, MerchantAccount, UserFromStorage}, transformers::ForeignFrom, }, }; pub async fn get_user_from_db_by_email( state: &SessionState, email: domain::UserEmail, ) -> CustomResult<UserFromStorage, StorageError> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/utils/user.rs | crate: router use api_models::user as user_api; use crate::{ consts::user::{REDIS_SSO_PREFIX, REDIS_SSO_TTL}, core::errors::{StorageError, UserErrors, UserResult}, routes::SessionState, services::{ authentication::{AuthToken, UserFromToken}, authorization::roles::RoleInfo, }, types::{ domain::{self, MerchantAccount, UserFromStorage}, transformers::ForeignFrom, }, }; pub fn get_verification_days_left( state: &SessionState, user: &UserFromStorage, ) -> UserResult<Option<i64>> { <|fim_suffix|> <|fim_middle|> }
ast_fragments