Skip to content

Commit

Permalink
Merge branch 'main' into volt-dynamic-field
Browse files Browse the repository at this point in the history
  • Loading branch information
prasunna09 authored Dec 4, 2023
2 parents a238f71 + 3ce04ab commit 4516a90
Show file tree
Hide file tree
Showing 22 changed files with 476 additions and 88 deletions.
5 changes: 3 additions & 2 deletions crates/api_models/src/events/user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::user::{
GetMetaDataRequest, GetMetaDataResponse, GetMultipleMetaDataPayload, SetMetaDataRequest,
},
ChangePasswordRequest, ConnectAccountRequest, ConnectAccountResponse,
CreateInternalUserRequest, SwitchMerchantIdRequest, UserMerchantCreate,
CreateInternalUserRequest, GetUsersResponse, SwitchMerchantIdRequest, UserMerchantCreate,
};

impl ApiEventMetric for ConnectAccountResponse {
Expand All @@ -29,7 +29,8 @@ common_utils::impl_misc_api_event_type!(
SetMetaDataRequest,
SwitchMerchantIdRequest,
CreateInternalUserRequest,
UserMerchantCreate
UserMerchantCreate,
GetUsersResponse
);

#[cfg(feature = "dummy_connector")]
Expand Down
11 changes: 8 additions & 3 deletions crates/api_models/src/payments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,9 @@ pub struct PaymentsRequest {
#[schema(example = "187282ab-40ef-47a9-9206-5099ba31e432")]
pub payment_token: Option<String>,

/// This is used when payment is to be confirmed and the card is not saved
#[schema(value_type = Option<String>)]
/// This is used when payment is to be confirmed and the card is not saved.
/// This field will be deprecated soon, use the CardToken object instead
#[schema(value_type = Option<String>, deprecated)]
pub card_cvc: Option<Secret<String>>,

/// The shipping address for the payment
Expand Down Expand Up @@ -720,12 +721,16 @@ pub struct Card {
pub nick_name: Option<Secret<String>>,
}

#[derive(Eq, PartialEq, Debug, serde::Deserialize, serde::Serialize, Clone, ToSchema)]
#[derive(Eq, PartialEq, Debug, serde::Deserialize, serde::Serialize, Clone, ToSchema, Default)]
#[serde(rename_all = "snake_case")]
pub struct CardToken {
/// The card holder's name
#[schema(value_type = String, example = "John Test")]
pub card_holder_name: Option<Secret<String>>,

/// The CVC number for the card
#[schema(value_type = Option<String>)]
pub card_cvc: Option<Secret<String>>,
}

#[derive(Eq, PartialEq, Clone, Debug, serde::Deserialize, serde::Serialize, ToSchema)]
Expand Down
17 changes: 17 additions & 0 deletions crates/api_models/src/user.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use common_utils::pii;
use masking::Secret;

use crate::user_role::UserStatus;
pub mod dashboard_metadata;
#[cfg(feature = "dummy_connector")]
pub mod sample_data;
Expand Down Expand Up @@ -45,3 +47,18 @@ pub struct CreateInternalUserRequest {
pub struct UserMerchantCreate {
pub company_name: String,
}

#[derive(Debug, serde::Serialize)]
pub struct GetUsersResponse(pub Vec<UserDetails>);

#[derive(Debug, serde::Serialize)]
pub struct UserDetails {
pub user_id: String,
pub email: pii::Email,
pub name: Secret<String>,
pub role_id: String,
pub role_name: String,
pub status: UserStatus,
#[serde(with = "common_utils::custom_serde::iso8601")]
pub last_modified_at: time::PrimitiveDateTime,
}
6 changes: 6 additions & 0 deletions crates/api_models/src/user_role.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,9 @@ pub struct UpdateUserRoleRequest {
pub user_id: String,
pub role_id: String,
}

#[derive(Debug, serde::Serialize)]
pub enum UserStatus {
Active,
InvitationSent,
}
30 changes: 29 additions & 1 deletion crates/diesel_models/src/query/dashboard_metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ use crate::{
enums,
query::generics,
schema::dashboard_metadata::dsl,
user::dashboard_metadata::{DashboardMetadata, DashboardMetadataNew},
user::dashboard_metadata::{
DashboardMetadata, DashboardMetadataNew, DashboardMetadataUpdate,
DashboardMetadataUpdateInternal,
},
PgPooledConn, StorageResult,
};

Expand All @@ -17,6 +20,31 @@ impl DashboardMetadataNew {
}

impl DashboardMetadata {
pub async fn update(
conn: &PgPooledConn,
user_id: Option<String>,
merchant_id: String,
org_id: String,
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
}

pub async fn find_user_scoped_dashboard_metadata(
conn: &PgPooledConn,
user_id: String,
Expand Down
47 changes: 39 additions & 8 deletions crates/diesel_models/src/query/user.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,24 @@
use diesel::{associations::HasTable, ExpressionMethods};
use error_stack::report;
use router_env::tracing::{self, instrument};
use async_bb8_diesel::AsyncRunQueryDsl;
use diesel::{
associations::HasTable, debug_query, result::Error as DieselError, ExpressionMethods,
JoinOnDsl, QueryDsl,
};
use error_stack::{report, IntoReport};
use router_env::{
logger,
tracing::{self, instrument},
};
pub mod sample_data;

use crate::{
errors::{self},
query::generics,
schema::users::dsl,
schema::{
user_roles::{self, dsl as user_roles_dsl},
users::dsl as users_dsl,
},
user::*,
user_role::UserRole,
PgPooledConn, StorageResult,
};

Expand All @@ -22,15 +33,15 @@ impl User {
pub async fn find_by_user_email(conn: &PgPooledConn, user_email: &str) -> StorageResult<Self> {
generics::generic_find_one::<<Self as HasTable>::Table, _, _>(
conn,
dsl::email.eq(user_email.to_owned()),
users_dsl::email.eq(user_email.to_owned()),
)
.await
}

pub async fn find_by_user_id(conn: &PgPooledConn, user_id: &str) -> StorageResult<Self> {
generics::generic_find_one::<<Self as HasTable>::Table, _, _>(
conn,
dsl::user_id.eq(user_id.to_owned()),
users_dsl::user_id.eq(user_id.to_owned()),
)
.await
}
Expand All @@ -42,7 +53,7 @@ impl User {
) -> StorageResult<Self> {
generics::generic_update_with_results::<<Self as HasTable>::Table, _, _, _>(
conn,
dsl::user_id.eq(user_id.to_owned()),
users_dsl::user_id.eq(user_id.to_owned()),
UserUpdateInternal::from(user),
)
.await?
Expand All @@ -56,8 +67,28 @@ impl User {
pub async fn delete_by_user_id(conn: &PgPooledConn, user_id: &str) -> StorageResult<bool> {
generics::generic_delete::<<Self as HasTable>::Table, _>(
conn,
dsl::user_id.eq(user_id.to_owned()),
users_dsl::user_id.eq(user_id.to_owned()),
)
.await
}

pub async fn find_joined_users_and_roles_by_merchant_id(
conn: &PgPooledConn,
mid: &str,
) -> StorageResult<Vec<(Self, UserRole)>> {
let query = Self::table()
.inner_join(user_roles::table.on(user_roles_dsl::user_id.eq(users_dsl::user_id)))
.filter(user_roles_dsl::merchant_id.eq(mid.to_owned()));

logger::debug!(query = %debug_query::<diesel::pg::Pg,_>(&query).to_string());

query
.get_results_async::<(Self, UserRole)>(conn)
.await
.into_report()
.map_err(|err| match err.current_context() {
DieselError::NotFound => err.change_context(errors::DatabaseError::NotFound),
_ => err.change_context(errors::DatabaseError::Others),
})
}
}
37 changes: 37 additions & 0 deletions crates/diesel_models/src/user/dashboard_metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,40 @@ pub struct DashboardMetadataNew {
pub last_modified_by: String,
pub last_modified_at: PrimitiveDateTime,
}

#[derive(
router_derive::Setter, Clone, Debug, Insertable, router_derive::DebugAsDisplay, AsChangeset,
)]
#[diesel(table_name = dashboard_metadata)]
pub struct DashboardMetadataUpdateInternal {
pub data_key: enums::DashboardMetadata,
pub data_value: serde_json::Value,
pub last_modified_by: String,
pub last_modified_at: PrimitiveDateTime,
}

pub enum DashboardMetadataUpdate {
UpdateData {
data_key: enums::DashboardMetadata,
data_value: serde_json::Value,
last_modified_by: String,
},
}

impl From<DashboardMetadataUpdate> for DashboardMetadataUpdateInternal {
fn from(metadata_update: DashboardMetadataUpdate) -> Self {
let last_modified_at = common_utils::date_time::now();
match metadata_update {
DashboardMetadataUpdate::UpdateData {
data_key,
data_value,
last_modified_by,
} => Self {
data_key,
data_value,
last_modified_by,
last_modified_at,
},
}
}
}
6 changes: 0 additions & 6 deletions crates/router/src/core/payment_methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ pub trait PaymentMethodRetrieve {
key_store: &domain::MerchantKeyStore,
token: &storage::PaymentTokenData,
payment_intent: &PaymentIntent,
card_cvc: Option<masking::Secret<String>>,
card_token_data: Option<&CardToken>,
) -> RouterResult<Option<(payments::PaymentMethodData, enums::PaymentMethod)>>;
}
Expand Down Expand Up @@ -126,7 +125,6 @@ impl PaymentMethodRetrieve for Oss {
merchant_key_store: &domain::MerchantKeyStore,
token_data: &storage::PaymentTokenData,
payment_intent: &PaymentIntent,
card_cvc: Option<masking::Secret<String>>,
card_token_data: Option<&CardToken>,
) -> RouterResult<Option<(payments::PaymentMethodData, enums::PaymentMethod)>> {
match token_data {
Expand All @@ -135,7 +133,6 @@ impl PaymentMethodRetrieve for Oss {
state,
&generic_token.token,
payment_intent,
card_cvc,
merchant_key_store,
card_token_data,
)
Expand All @@ -147,7 +144,6 @@ impl PaymentMethodRetrieve for Oss {
state,
&generic_token.token,
payment_intent,
card_cvc,
merchant_key_store,
card_token_data,
)
Expand All @@ -159,7 +155,6 @@ impl PaymentMethodRetrieve for Oss {
state,
&card_token.token,
payment_intent,
card_cvc,
card_token_data,
)
.await
Expand All @@ -171,7 +166,6 @@ impl PaymentMethodRetrieve for Oss {
state,
&card_token.token,
payment_intent,
card_cvc,
card_token_data,
)
.await
Expand Down
Loading

0 comments on commit 4516a90

Please sign in to comment.