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(multitenancy): move users and tenants to global schema #4781

Merged
merged 68 commits into from
Jun 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
68 commits
Select commit Hold shift + click to select a range
85e3676
feat(multitenancy): add logical sepration of tenant using db schema
jagan-jaya Apr 30, 2024
2265882
feat(multitenancy): add base_url for redirection and pay start
jagan-jaya May 13, 2024
50559b7
feat(multitenancy): format code and remove unused deps
jagan-jaya May 13, 2024
54c1aee
feat(multitenancy): create sessionstate for scheduler
jagan-jaya May 13, 2024
f6d3dac
Merge branch 'main' of https://github.com/juspay/hyperswitch into mul…
jagan-jaya May 14, 2024
7d35c89
chore: run formatter
hyperswitch-bot[bot] May 14, 2024
b2b05c3
feat(multitenancy): update tenants
jagan-jaya May 14, 2024
4a5748c
Merge branch 'multitenancy' of https://github.com/juspay/hyperswitch …
jagan-jaya May 14, 2024
e60f9b5
feat(multitenancy): fix clippy warnings
jagan-jaya May 15, 2024
c1602da
Merge branch 'main' of https://github.com/juspay/hyperswitch into mul…
jagan-jaya May 15, 2024
978fbe4
Merge branch 'main' of https://github.com/juspay/hyperswitch into mul…
jagan-jaya May 17, 2024
d707357
feat(multitenancy): fix clippy warnings
jagan-jaya May 17, 2024
c9405db
feat(multitenancy): fix clippy warnings
jagan-jaya May 17, 2024
dda08c8
Merge branch 'main' of https://github.com/juspay/hyperswitch into mul…
jagan-jaya May 17, 2024
c376ffc
chore: run formatter
hyperswitch-bot[bot] May 17, 2024
c78729e
feat(multitenancy): add support to enable/disable multitenancy support
jagan-jaya May 17, 2024
66d8d4d
Merge branch 'multitenancy' of https://github.com/juspay/hyperswitch …
jagan-jaya May 17, 2024
f103acc
fix: clear redis entry on update operation
jagan-jaya May 21, 2024
b3609b8
Merge branch 'main' of https://github.com/juspay/hyperswitch into mul…
jagan-jaya May 21, 2024
4e941d6
chore: run formatter
hyperswitch-bot[bot] May 21, 2024
f852184
feat: add tenant support in in-memory cache
jagan-jaya May 23, 2024
9e27425
Merge branch 'multitenancy' of https://github.com/juspay/hyperswitch …
jagan-jaya May 23, 2024
6a174a2
Merge branch 'main' of https://github.com/juspay/hyperswitch into mul…
jagan-jaya May 23, 2024
e0cb6f0
feat: add tenant support in in-memory cache
jagan-jaya May 23, 2024
a6d1936
feat: address PR comments
jagan-jaya May 27, 2024
69f5fb4
feat: address PR comments
jagan-jaya May 27, 2024
18a75c0
Merge branch 'main' of https://github.com/juspay/hyperswitch into mul…
jagan-jaya May 27, 2024
983068d
Merge branch 'main' of https://github.com/juspay/hyperswitch into mul…
jagan-jaya May 27, 2024
d740d78
feat: add global tenant for users
jagan-jaya May 27, 2024
2a4bb9b
Merge branch 'multitenancy-users' of https://github.com/juspay/hypers…
jagan-jaya May 27, 2024
a1d7413
Merge branch 'multitenancy' of https://github.com/juspay/hyperswitch …
jagan-jaya May 27, 2024
248bdf7
feat: add global tenant for users
jagan-jaya May 27, 2024
93aa1f9
fix: clippy warnings
jagan-jaya May 27, 2024
5bf788f
Merge branch 'multitenancy' of https://github.com/juspay/hyperswitch …
jagan-jaya May 27, 2024
9516014
chore: run formatter
hyperswitch-bot[bot] May 27, 2024
dac602a
chore: run formatter
hyperswitch-bot[bot] May 27, 2024
827113f
fix: clippy warnings
jagan-jaya May 28, 2024
e6eea95
Merge branch 'multitenancy' of https://github.com/juspay/hyperswitch …
jagan-jaya May 28, 2024
479bb2f
Merge branch 'main' of https://github.com/juspay/hyperswitch into mul…
jagan-jaya May 28, 2024
4cb732e
refactor: drainer to have single redis conn for error handling
jagan-jaya May 28, 2024
fb10f00
refactor: get redis key prefix from config
jagan-jaya May 29, 2024
6f57723
Merge branch 'main' of https://github.com/juspay/hyperswitch into mul…
jagan-jaya May 29, 2024
3688621
fix: clippy warnings
jagan-jaya May 29, 2024
4283f8f
fix: clippy warnings
jagan-jaya May 29, 2024
079f8c7
Merge branch 'main' of https://github.com/juspay/hyperswitch into mul…
jagan-jaya May 30, 2024
2afcf2c
Merge branch 'main' of https://github.com/juspay/hyperswitch into mul…
jagan-jaya May 30, 2024
07ea1e6
chore: run formatter
hyperswitch-bot[bot] May 30, 2024
8e1d9ad
Merge branch 'multitenancy' of https://github.com/juspay/hyperswitch …
jagan-jaya May 30, 2024
c800622
feat(mulitenancy): add global tenant which handles users and other gl…
jagan-jaya May 30, 2024
8a45883
chore: run formatter
hyperswitch-bot[bot] May 30, 2024
083b637
fix: code formatting
jagan-jaya May 30, 2024
2004a02
Merge branch 'multitenancy-users' of https://github.com/juspay/hypers…
jagan-jaya May 30, 2024
5b1099f
fix: clippy warnings
jagan-jaya May 31, 2024
d5d5f84
Merge branch 'main' of https://github.com/juspay/hyperswitch into mul…
jagan-jaya Jun 3, 2024
d1a6a2f
Merge branch 'multitenancy' of https://github.com/juspay/hyperswitch …
jagan-jaya Jun 3, 2024
745f7a6
fix: move use_key interface to global storage
jagan-jaya Jun 3, 2024
49e8a2e
chore: run formatter
hyperswitch-bot[bot] Jun 3, 2024
df02be4
Merge branch 'main' of https://github.com/juspay/hyperswitch into mul…
jagan-jaya Jun 3, 2024
3294ed8
Merge branch 'main' of https://github.com/juspay/hyperswitch into mul…
jagan-jaya Jun 3, 2024
1223f14
Merge branch 'main' into multitenancy
jarnura Jun 3, 2024
b2640c1
Merge branch 'multitenancy' of https://github.com/juspay/hyperswitch …
jagan-jaya Jun 3, 2024
95ac878
Merge branch 'multitenancy-users' of https://github.com/juspay/hypers…
jagan-jaya Jun 4, 2024
983b71e
Merge branch 'main' of https://github.com/juspay/hyperswitch into mul…
jagan-jaya Jun 4, 2024
aeb1c21
Merge branch 'main' into multitenancy-users
jagan-jaya Jun 4, 2024
74af852
Merge branch 'main' into multitenancy-users
jagan-jaya Jun 4, 2024
62ffbfd
feat(multitenancy): remove ununsed join functions for user_role_and_user
jagan-jaya Jun 5, 2024
a4151ee
Merge branch 'main' into multitenancy-users
jagan-jaya Jun 5, 2024
bc4dbf6
Merge branch 'main' into multitenancy-users
jagan-jaya Jun 5, 2024
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
3 changes: 3 additions & 0 deletions crates/common_utils/src/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ pub const MAX_TTL_FOR_EXTENDED_CARD_INFO: u16 = 60 * 60 * 2;
/// Default tenant to be used when multitenancy is disabled
pub const DEFAULT_TENANT: &str = "public";

/// Global tenant to be used when multitenancy is enabled
pub const GLOBAL_TENANT: &str = "global";

/// Max Length for MerchantReferenceId
pub const MAX_ALLOWED_MERCHANT_REFERENCE_ID_LENGTH: u8 = 64;

Expand Down
13 changes: 13 additions & 0 deletions crates/diesel_models/src/query/user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,17 @@ impl User {
_ => report!(err).change_context(errors::DatabaseError::Others),
})
}

pub async fn find_users_by_user_ids(
conn: &PgPooledConn,
user_ids: Vec<String>,
) -> StorageResult<Vec<Self>> {
generics::generic_filter::<
<Self as HasTable>::Table,
_,
<<Self as HasTable>::Table as diesel::Table>::PrimaryKey,
_,
>(conn, users_dsl::user_id.eq_any(user_ids), None, None, None)
.await
}
}
14 changes: 14 additions & 0 deletions crates/diesel_models/src/query/user_role.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,18 @@ impl UserRole {
)
.await
}

pub async fn list_by_merchant_id(
conn: &PgPooledConn,
merchant_id: String,
) -> StorageResult<Vec<Self>> {
generics::generic_filter::<<Self as HasTable>::Table, _, _, _>(
conn,
dsl::merchant_id.eq(merchant_id),
None,
None,
Some(dsl::created_at.asc()),
)
.await
}
}
6 changes: 3 additions & 3 deletions crates/router/src/analytics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ pub mod routes {
&req,
json_payload.into_inner(),
|state, (auth, user_id): auth::AuthenticationDataWithUserId, payload, _| async move {
let user = UserInterface::find_user_by_id(&*state.store, &user_id)
let user = UserInterface::find_user_by_id(&*state.global_store, &user_id)
.await
.change_context(AnalyticsError::UnknownError)?;

Expand Down Expand Up @@ -486,7 +486,7 @@ pub mod routes {
&req,
json_payload.into_inner(),
|state, (auth, user_id): auth::AuthenticationDataWithUserId, payload, _| async move {
let user = UserInterface::find_user_by_id(&*state.store, &user_id)
let user = UserInterface::find_user_by_id(&*state.global_store, &user_id)
.await
.change_context(AnalyticsError::UnknownError)?;

Expand Down Expand Up @@ -528,7 +528,7 @@ pub mod routes {
&req,
json_payload.into_inner(),
|state, (auth, user_id): auth::AuthenticationDataWithUserId, payload, _| async move {
let user = UserInterface::find_user_by_id(&*state.store, &user_id)
let user = UserInterface::find_user_by_id(&*state.global_store, &user_id)
.await
.change_context(AnalyticsError::UnknownError)?;

Expand Down
15 changes: 15 additions & 0 deletions crates/router/src/configs/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,21 @@ impl storage_impl::config::TenantConfig for Tenant {
}
}

#[derive(Debug, Deserialize, Clone, Default)]
pub struct GlobalTenant {
pub schema: String,
pub redis_key_prefix: String,
}

impl storage_impl::config::TenantConfig for GlobalTenant {
fn get_schema(&self) -> &str {
self.schema.as_str()
}
fn get_redis_key_prefix(&self) -> &str {
self.redis_key_prefix.as_str()
}
}

#[derive(Debug, Deserialize, Clone, Default)]
pub struct UnmaskedHeaders {
#[serde(deserialize_with = "deserialize_hashset")]
Expand Down
Loading
Loading