-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(users): setup user authentication methods schema and apis (#4999)
Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com> Co-authored-by: Mani Chandra Dulam <[email protected]>
- Loading branch information
1 parent
5cde7ee
commit 2005d3d
Showing
29 changed files
with
888 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
crates/diesel_models/src/query/user_authentication_method.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
use diesel::{associations::HasTable, ExpressionMethods}; | ||
|
||
use crate::{ | ||
query::generics, schema::user_authentication_methods::dsl, user_authentication_method::*, | ||
PgPooledConn, StorageResult, | ||
}; | ||
|
||
impl UserAuthenticationMethodNew { | ||
pub async fn insert(self, conn: &PgPooledConn) -> StorageResult<UserAuthenticationMethod> { | ||
generics::generic_insert(conn, self).await | ||
} | ||
} | ||
|
||
impl UserAuthenticationMethod { | ||
pub async fn list_user_authentication_methods_for_auth_id( | ||
conn: &PgPooledConn, | ||
auth_id: &str, | ||
) -> StorageResult<Vec<Self>> { | ||
generics::generic_filter::<<Self as HasTable>::Table, _, _, _>( | ||
conn, | ||
dsl::auth_id.eq(auth_id.to_owned()), | ||
None, | ||
None, | ||
Some(dsl::last_modified_at.asc()), | ||
) | ||
.await | ||
} | ||
|
||
pub async fn list_user_authentication_methods_for_owner_id( | ||
conn: &PgPooledConn, | ||
owner_id: &str, | ||
) -> StorageResult<Vec<Self>> { | ||
generics::generic_filter::<<Self as HasTable>::Table, _, _, _>( | ||
conn, | ||
dsl::owner_id.eq(owner_id.to_owned()), | ||
None, | ||
None, | ||
Some(dsl::last_modified_at.asc()), | ||
) | ||
.await | ||
} | ||
|
||
pub async fn update_user_authentication_method( | ||
conn: &PgPooledConn, | ||
id: &str, | ||
user_authentication_method_update: UserAuthenticationMethodUpdate, | ||
) -> StorageResult<Self> { | ||
generics::generic_update_with_unique_predicate_get_result::< | ||
<Self as HasTable>::Table, | ||
_, | ||
_, | ||
_, | ||
>( | ||
conn, | ||
dsl::id.eq(id.to_owned()), | ||
OrgAuthenticationMethodUpdateInternal::from(user_authentication_method_update), | ||
) | ||
.await | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
use diesel::{AsChangeset, Identifiable, Insertable, Queryable}; | ||
use time::PrimitiveDateTime; | ||
|
||
use crate::{encryption::Encryption, enums, schema::user_authentication_methods}; | ||
|
||
#[derive(Clone, Debug, Identifiable, Queryable)] | ||
#[diesel(table_name = user_authentication_methods)] | ||
pub struct UserAuthenticationMethod { | ||
pub id: String, | ||
pub auth_id: String, | ||
pub owner_id: String, | ||
pub owner_type: enums::Owner, | ||
pub auth_type: enums::UserAuthType, | ||
pub private_config: Option<Encryption>, | ||
pub public_config: Option<serde_json::Value>, | ||
pub allow_signup: bool, | ||
pub created_at: PrimitiveDateTime, | ||
pub last_modified_at: PrimitiveDateTime, | ||
} | ||
|
||
#[derive(router_derive::Setter, Clone, Debug, Insertable, router_derive::DebugAsDisplay)] | ||
#[diesel(table_name = user_authentication_methods)] | ||
pub struct UserAuthenticationMethodNew { | ||
pub id: String, | ||
pub auth_id: String, | ||
pub owner_id: String, | ||
pub owner_type: enums::Owner, | ||
pub auth_type: enums::UserAuthType, | ||
pub private_config: Option<Encryption>, | ||
pub public_config: Option<serde_json::Value>, | ||
pub allow_signup: bool, | ||
pub created_at: PrimitiveDateTime, | ||
pub last_modified_at: PrimitiveDateTime, | ||
} | ||
|
||
#[derive(Clone, Debug, AsChangeset, router_derive::DebugAsDisplay)] | ||
#[diesel(table_name = user_authentication_methods)] | ||
pub struct OrgAuthenticationMethodUpdateInternal { | ||
pub private_config: Option<Encryption>, | ||
pub public_config: Option<serde_json::Value>, | ||
pub last_modified_at: PrimitiveDateTime, | ||
} | ||
|
||
pub enum UserAuthenticationMethodUpdate { | ||
UpdateConfig { | ||
private_config: Option<Encryption>, | ||
public_config: Option<serde_json::Value>, | ||
}, | ||
} | ||
|
||
impl From<UserAuthenticationMethodUpdate> for OrgAuthenticationMethodUpdateInternal { | ||
fn from(value: UserAuthenticationMethodUpdate) -> Self { | ||
let last_modified_at = common_utils::date_time::now(); | ||
match value { | ||
UserAuthenticationMethodUpdate::UpdateConfig { | ||
private_config, | ||
public_config, | ||
} => Self { | ||
private_config, | ||
public_config, | ||
last_modified_at, | ||
}, | ||
} | ||
} | ||
} |
Oops, something went wrong.