Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(user): add email apis and new enums for metadata #3053

Merged
merged 19 commits into from
Dec 5, 2023
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/api_models/src/refunds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ pub struct RefundListMetaData {
pub currency: Vec<enums::Currency>,
/// The list of available refund status filters
#[schema(value_type = Vec<RefundStatus>)]
pub status: Vec<enums::RefundStatus>,
pub refund_status: Vec<enums::RefundStatus>,
}

/// The status for refunds
Expand Down
23 changes: 23 additions & 0 deletions crates/api_models/src/user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,29 @@ pub struct ChangePasswordRequest {
pub old_password: Secret<String>,
}

#[derive(serde::Deserialize, Debug, serde::Serialize)]
pub struct ForgotPasswordRequest {
pub email: pii::Email,
}

#[derive(serde::Deserialize, Debug, serde::Serialize)]
pub struct ResetPasswordRequest {
pub token: Secret<String>,
pub password: Secret<String>,
}

#[derive(Debug, serde::Deserialize, serde::Serialize, Clone)]
pub struct InviteUserRequest {
pub email: pii::Email,
pub name: Secret<String>,
pub role_id: String,
}

#[derive(Debug, serde::Serialize)]
pub struct InviteUserResponse {
pub is_email_sent: bool,
}

#[derive(Debug, serde::Deserialize, serde::Serialize)]
pub struct SwitchMerchantIdRequest {
pub merchant_id: String,
Expand Down
41 changes: 40 additions & 1 deletion crates/api_models/src/user/dashboard_metadata.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use common_enums::CountryAlpha2;
use common_utils::pii;
use masking::Secret;
use strum::EnumString;

Expand All @@ -12,8 +14,11 @@ pub enum SetMetaDataRequest {
ConfiguredRouting(ConfiguredRouting),
TestPayment(TestPayment),
IntegrationMethod(IntegrationMethod),
ConfigurationType(ConfigurationType),
IntegrationCompleted,
SPRoutingConfigured(ConfiguredRouting),
Feedback(Feedback),
ProdIntent(ProdIntent),
SPTestPayment,
DownloadWoocom,
ConfigureWoocom,
Expand Down Expand Up @@ -49,10 +54,38 @@ pub struct TestPayment {
pub payment_id: String,
}

#[derive(Debug, serde::Deserialize, serde::Serialize)]
#[derive(Debug, serde::Deserialize, serde::Serialize, Clone)]
pub struct IntegrationMethod {
pub integration_type: String,
}
#[derive(Debug, serde::Deserialize, serde::Serialize, Clone)]
pub enum ConfigurationType {
Single,
Multiple,
}

#[derive(Debug, serde::Deserialize, serde::Serialize, Clone)]
pub struct Feedback {
pub email: pii::Email,
pub description: Option<String>,
pub rating: Option<i32>,
pub category: Option<String>,
}
#[derive(Debug, serde::Deserialize, serde::Serialize, Clone)]
pub struct ProdIntent {
pub legal_business_name: Option<String>,
pub business_label: Option<String>,
pub business_location: Option<CountryAlpha2>,
pub display_name: Option<String>,
pub poc_email: Option<String>,
pub business_type: Option<String>,
pub business_identifier: Option<String>,
pub business_website: Option<String>,
pub poc_name: Option<String>,
pub poc_contact: Option<String>,
pub comments: Option<String>,
pub is_completed: bool,
}

#[derive(Debug, serde::Deserialize, EnumString, serde::Serialize)]
pub enum GetMetaDataRequest {
Expand All @@ -65,10 +98,13 @@ pub enum GetMetaDataRequest {
ConfiguredRouting,
TestPayment,
IntegrationMethod,
ConfigurationType,
IntegrationCompleted,
StripeConnected,
PaypalConnected,
SPRoutingConfigured,
Feedback,
ProdIntent,
SPTestPayment,
DownloadWoocom,
ConfigureWoocom,
Expand Down Expand Up @@ -98,10 +134,13 @@ pub enum GetMetaDataResponse {
ConfiguredRouting(Option<ConfiguredRouting>),
TestPayment(Option<TestPayment>),
IntegrationMethod(Option<IntegrationMethod>),
ConfigurationType(Option<ConfigurationType>),
IntegrationCompleted(bool),
StripeConnected(Option<ProcessorConnected>),
PaypalConnected(Option<ProcessorConnected>),
SPRoutingConfigured(Option<ConfiguredRouting>),
Feedback(Option<Feedback>),
ProdIntent(Option<ProdIntent>),
SPTestPayment(bool),
DownloadWoocom(bool),
ConfigureWoocom(bool),
Expand Down
3 changes: 3 additions & 0 deletions crates/diesel_models/src/enums.rs
Original file line number Diff line number Diff line change
Expand Up @@ -452,10 +452,13 @@ pub enum DashboardMetadata {
ConfiguredRouting,
TestPayment,
IntegrationMethod,
ConfigurationType,
IntegrationCompleted,
StripeConnected,
PaypalConnected,
SpRoutingConfigured,
Feedback,
ProdIntent,
SpTestPayment,
DownloadWoocom,
ConfigureWoocom,
Expand Down
45 changes: 30 additions & 15 deletions crates/diesel_models/src/query/dashboard_metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,36 @@ impl DashboardMetadata {
data_key: enums::DashboardMetadata,
dashboard_metadata_update: DashboardMetadataUpdate,
) -> StorageResult<Self> {
generics::generic_update_with_unique_predicate_get_result::<
<Self as HasTable>::Table,
_,
_,
_,
>(
conn,
dsl::user_id
.eq(user_id.to_owned())
.and(dsl::merchant_id.eq(merchant_id.to_owned()))
.and(dsl::org_id.eq(org_id.to_owned()))
.and(dsl::data_key.eq(data_key.to_owned())),
DashboardMetadataUpdateInternal::from(dashboard_metadata_update),
)
.await
let predicate = dsl::merchant_id
.eq(merchant_id.to_owned())
.and(dsl::org_id.eq(org_id.to_owned()))
.and(dsl::data_key.eq(data_key.to_owned()));

if let Some(uid) = user_id {
generics::generic_update_with_unique_predicate_get_result::<
<Self as HasTable>::Table,
_,
_,
_,
>(
conn,
predicate.and(dsl::user_id.eq(uid)),
DashboardMetadataUpdateInternal::from(dashboard_metadata_update),
)
.await
} else {
generics::generic_update_with_unique_predicate_get_result::<
<Self as HasTable>::Table,
_,
_,
_,
>(
conn,
predicate.and(dsl::user_id.is_null()),
DashboardMetadataUpdateInternal::from(dashboard_metadata_update),
)
.await
}
}

pub async fn find_user_scoped_dashboard_metadata(
Expand Down
2 changes: 1 addition & 1 deletion crates/router/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ readme = "README.md"
license.workspace = true

[features]
default = ["kv_store", "stripe", "oltp", "olap", "backwards_compatibility", "accounts_cache", "dummy_connector", "payouts", "profile_specific_fallback_routing", "retry"]
default = ["kv_store", "stripe", "oltp", "olap", "backwards_compatibility", "accounts_cache", "dummy_connector", "payouts", "profile_specific_fallback_routing", "retry", "email"]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we enabling email by default? Is this intentional?

s3 = ["dep:aws-sdk-s3", "dep:aws-config"]
kms = ["external_services/kms", "dep:aws-config"]
email = ["external_services/email", "dep:aws-config", "olap"]
Expand Down
13 changes: 13 additions & 0 deletions crates/router/src/core/errors/user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,12 @@ pub enum UserErrors {
InternalServerError,
#[error("InvalidCredentials")]
InvalidCredentials,
#[error("UserNotFound")]
UserNotFound,
#[error("UserExists")]
UserExists,
#[error("LinkInvalid")]
LinkInvalid,
#[error("InvalidOldPassword")]
InvalidOldPassword,
#[error("EmailParsingError")]
Expand Down Expand Up @@ -60,12 +64,21 @@ impl common_utils::errors::ErrorSwitch<api_models::errors::types::ApiErrorRespon
"Incorrect email or password",
None,
)),
Self::UserNotFound => AER::Unauthorized(ApiError::new(
sub_code,
2,
"Email doesn’t exist. Register",
None,
)),
Self::UserExists => AER::BadRequest(ApiError::new(
sub_code,
3,
"An account already exists with this email",
None,
)),
Self::LinkInvalid => {
AER::Unauthorized(ApiError::new(sub_code, 4, "Invalid or expired link", None))
}
Self::InvalidOldPassword => AER::BadRequest(ApiError::new(
sub_code,
6,
Expand Down
Loading
Loading