Skip to content

Commit

Permalink
refactor(users): Add V2 user_roles data support (#5763)
Browse files Browse the repository at this point in the history
Co-authored-by: Apoorv Dixit <[email protected]>
Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Sep 1, 2024
1 parent 3798319 commit 6b41050
Show file tree
Hide file tree
Showing 31 changed files with 768 additions and 2,042 deletions.
17 changes: 5 additions & 12 deletions crates/api_models/src/events/user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ use crate::user::{
GetSsoAuthUrlRequest, GetUserAuthenticationMethodsRequest, GetUserDetailsResponse,
GetUserRoleDetailsRequest, GetUserRoleDetailsResponse, InviteUserRequest, ListUsersResponse,
ReInviteUserRequest, RecoveryCodes, ResetPasswordRequest, RotatePasswordRequest,
SendVerifyEmailRequest, SignInResponse, SignUpRequest, SignUpWithMerchantIdRequest,
SsoSignInRequest, SwitchMerchantRequest, SwitchOrganizationRequest, SwitchProfileRequest,
TokenOrPayloadResponse, TokenResponse, TwoFactorAuthStatusResponse,
UpdateUserAccountDetailsRequest, UpdateUserAuthenticationMethodRequest, UserFromEmailRequest,
UserMerchantCreate, VerifyEmailRequest, VerifyRecoveryCodeRequest, VerifyTotpRequest,
SendVerifyEmailRequest, SignUpRequest, SignUpWithMerchantIdRequest, SsoSignInRequest,
SwitchMerchantRequest, SwitchOrganizationRequest, SwitchProfileRequest, TokenResponse,
TwoFactorAuthStatusResponse, UpdateUserAccountDetailsRequest,
UpdateUserAuthenticationMethodRequest, UserFromEmailRequest, UserMerchantCreate,
VerifyEmailRequest, VerifyRecoveryCodeRequest, VerifyTotpRequest,
};

impl ApiEventMetric for DashboardEntryResponse {
Expand All @@ -40,12 +40,6 @@ impl ApiEventMetric for VerifyTokenResponse {
}
}

impl<T> ApiEventMetric for TokenOrPayloadResponse<T> {
fn get_api_event_type(&self) -> Option<ApiEventsType> {
Some(ApiEventsType::Miscellaneous)
}
}

common_utils::impl_api_event_type!(
Miscellaneous,
(
Expand All @@ -72,7 +66,6 @@ common_utils::impl_api_event_type!(
VerifyEmailRequest,
SendVerifyEmailRequest,
AcceptInviteFromEmailRequest,
SignInResponse,
UpdateUserAccountDetailsRequest,
GetUserDetailsResponse,
GetUserRoleDetailsRequest,
Expand Down
7 changes: 2 additions & 5 deletions crates/api_models/src/events/user_role.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ use common_utils::events::{ApiEventMetric, ApiEventsType};

use crate::user_role::{
role::{
CreateRoleRequest, GetRoleFromTokenResponse, GetRoleRequest, ListRolesResponse,
RoleInfoResponse, RoleInfoWithGroupsResponse, RoleInfoWithPermissionsResponse,
UpdateRoleRequest,
CreateRoleRequest, GetRoleRequest, ListRolesResponse, RoleInfoWithGroupsResponse,
RoleInfoWithPermissionsResponse, UpdateRoleRequest,
},
AcceptInvitationRequest, AuthorizationInfoResponse, DeleteUserRoleRequest,
MerchantSelectRequest, UpdateUserRoleRequest,
Expand All @@ -23,8 +22,6 @@ common_utils::impl_api_event_type!(
CreateRoleRequest,
UpdateRoleRequest,
ListRolesResponse,
RoleInfoResponse,
GetRoleFromTokenResponse,
RoleInfoWithGroupsResponse
)
);
31 changes: 0 additions & 31 deletions crates/api_models/src/user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ pub struct SignUpRequest {
pub password: Secret<String>,
}

pub type SignUpResponse = DashboardEntryResponse;

#[derive(serde::Serialize, Debug, Clone)]
pub struct DashboardEntryResponse {
pub token: Secret<String>,
Expand All @@ -40,22 +38,6 @@ pub struct DashboardEntryResponse {

pub type SignInRequest = SignUpRequest;

#[derive(Debug, serde::Serialize)]
#[serde(tag = "flow_type", rename_all = "snake_case")]
pub enum SignInResponse {
MerchantSelect(MerchantSelectResponse),
DashboardEntry(DashboardEntryResponse),
}

#[derive(Debug, serde::Serialize)]
pub struct MerchantSelectResponse {
pub token: Secret<String>,
pub name: Secret<String>,
pub email: pii::Email,
pub verification_days_left: Option<i64>,
pub merchants: Vec<UserMerchantAccount>,
}

#[derive(serde::Deserialize, Debug, Clone, serde::Serialize)]
pub struct ConnectAccountRequest {
pub email: pii::Email,
Expand Down Expand Up @@ -202,8 +184,6 @@ pub struct VerifyEmailRequest {
pub token: Secret<String>,
}

pub type VerifyEmailResponse = SignInResponse;

#[derive(serde::Deserialize, Debug, serde::Serialize)]
pub struct SendVerifyEmailRequest {
pub email: pii::Email,
Expand Down Expand Up @@ -232,11 +212,6 @@ pub struct UpdateUserAccountDetailsRequest {
pub preferred_merchant_id: Option<id_type::MerchantId>,
}

#[derive(Debug, serde::Deserialize, serde::Serialize)]
pub struct TokenOnlyQueryParam {
pub token_only: Option<bool>,
}

#[derive(Debug, serde::Deserialize, serde::Serialize)]
pub struct SkipTwoFactorAuthQueryParam {
pub skip_two_factor_auth: Option<bool>,
Expand All @@ -254,12 +229,6 @@ pub struct TwoFactorAuthStatusResponse {
pub recovery_code: bool,
}

#[derive(Debug, serde::Serialize)]
#[serde(untagged)]
pub enum TokenOrPayloadResponse<T> {
Token(TokenResponse),
Payload(T),
}
#[derive(Debug, serde::Deserialize, serde::Serialize)]
pub struct UserFromEmailRequest {
pub token: Secret<String>,
Expand Down
3 changes: 1 addition & 2 deletions crates/api_models/src/user_role.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,8 @@ pub enum UserStatus {
#[derive(Debug, serde::Deserialize, serde::Serialize)]
pub struct MerchantSelectRequest {
pub merchant_ids: Vec<common_utils::id_type::MerchantId>,
// TODO: Remove this once the token only api is being used
pub need_dashboard_entry_response: Option<bool>,
}

#[derive(Debug, serde::Deserialize, serde::Serialize)]
pub struct AcceptInvitationRequest {
pub merchant_ids: Vec<common_utils::id_type::MerchantId>,
Expand Down
24 changes: 3 additions & 21 deletions crates/api_models/src/user_role/role.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use common_enums::{EntityType, PermissionGroup, RoleScope};
pub use common_enums::PermissionGroup;
use common_enums::{EntityType, RoleScope};

use super::Permission;

Expand All @@ -17,26 +18,7 @@ pub struct UpdateRoleRequest {
}

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

#[derive(Debug, serde::Deserialize)]
pub struct GetGroupsQueryParam {
pub groups: Option<bool>,
}

#[derive(Debug, serde::Serialize)]
#[serde(untagged)]
pub enum GetRoleFromTokenResponse {
Permissions(Vec<Permission>),
Groups(Vec<PermissionGroup>),
}

#[derive(Debug, serde::Serialize)]
#[serde(untagged)]
pub enum RoleInfoResponse {
Permissions(RoleInfoWithPermissionsResponse),
Groups(RoleInfoWithGroupsResponse),
}
pub struct ListRolesResponse(pub Vec<RoleInfoWithGroupsResponse>);

#[derive(Debug, serde::Serialize)]
pub struct RoleInfoWithPermissionsResponse {
Expand Down
Loading

0 comments on commit 6b41050

Please sign in to comment.