Skip to content

Commit dc0d4ad

Browse files
feat: multitenancy dashboard (#220)
* fix: providers non null * fix: changelog * fix: build fix * reformats code * fix: changelog * fix: reformat --------- Co-authored-by: rishabhpoddar <[email protected]>
1 parent 16101d0 commit dc0d4ad

File tree

7 files changed

+39
-38
lines changed

7 files changed

+39
-38
lines changed

.idea/gradle.xml

Lines changed: 14 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/vcs.xml

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

CHANGELOG.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,17 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
99

1010
## [7.1.0]
1111

12+
- Compatible with plugin interface version 6.2
1213
- Adds implementation for a new method `getConfigFieldsInfo` to fetch the plugin config fields.
13-
- Adds `null` state for `firstFactors` and `providers` by adding `is_first_factors_null`
14-
and `is_third_party_providers_null` fields in `tenant_configs` table
14+
- Adds `DashboardInfo` annotations to the config properties in `PostgreSQLConfig`
15+
- Adds `null` state for `firstFactors` by adding `is_first_factors_null` field in `tenant_configs` table. The value of
16+
this column is only applicable when there are no entries in the `tenant_first_factors` table for the tenant.
1517

1618
### Migration
1719

1820
```sql
1921
ALTER TABLE tenant_configs ADD COLUMN IF NOT EXISTS is_first_factors_null BOOLEAN DEFAULT TRUE;
20-
ALTER TABLE tenant_configs ADD COLUMN IF NOT EXISTS is_third_party_providers_null BOOLEAN DEFAULT TRUE;
21-
2222
ALTER TABLE tenant_configs ALTER COLUMN is_first_factors_null DROP DEFAULT;
23-
ALTER TABLE tenant_configs ALTER COLUMN is_third_party_providers_null DROP DEFAULT;
2423
```
2524

2625
## [7.0.1] - 2024-04-17

src/main/java/io/supertokens/storage/postgresql/queries/MultitenancyQueries.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@
1818

1919
import io.supertokens.pluginInterface.exceptions.StorageQueryException;
2020
import io.supertokens.pluginInterface.exceptions.StorageTransactionLogicException;
21-
import io.supertokens.pluginInterface.multitenancy.*;
21+
import io.supertokens.pluginInterface.multitenancy.TenantConfig;
22+
import io.supertokens.pluginInterface.multitenancy.TenantIdentifier;
23+
import io.supertokens.pluginInterface.multitenancy.ThirdPartyConfig;
2224
import io.supertokens.pluginInterface.multitenancy.exceptions.TenantOrAppNotFoundException;
2325
import io.supertokens.storage.postgresql.Start;
2426
import io.supertokens.storage.postgresql.config.Config;
@@ -32,8 +34,8 @@
3234
import java.sql.SQLException;
3335
import java.util.HashMap;
3436

35-
import static io.supertokens.storage.postgresql.QueryExecutorTemplate.update;
3637
import static io.supertokens.storage.postgresql.QueryExecutorTemplate.execute;
38+
import static io.supertokens.storage.postgresql.QueryExecutorTemplate.update;
3739
import static io.supertokens.storage.postgresql.config.Config.getConfig;
3840

3941
public class MultitenancyQueries {
@@ -52,7 +54,6 @@ static String getQueryToCreateTenantConfigsTable(Start start) {
5254
+ "passwordless_enabled BOOLEAN,"
5355
+ "third_party_enabled BOOLEAN,"
5456
+ "is_first_factors_null BOOLEAN,"
55-
+ "is_third_party_providers_null BOOLEAN,"
5657
+ "CONSTRAINT " + Utils.getConstraintName(schema, tenantConfigsTable, null, "pkey") +
5758
" PRIMARY KEY (connection_uri_domain, app_id, tenant_id)"
5859
+ ");";

src/main/java/io/supertokens/storage/postgresql/queries/multitenancy/TenantConfigSQLHelper.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,13 @@ public static TenantConfigSQLHelper.TenantConfigRowMapper getInstance(ThirdParty
5656
public TenantConfig map(ResultSet result) throws StorageQueryException {
5757
try {
5858
boolean isFirstFactorsNull = result.getBoolean("is_first_factors_null");
59-
boolean isThirdPartyProvidersNull = result.getBoolean("is_third_party_providers_null");
6059
return new TenantConfig(
6160
new TenantIdentifier(result.getString("connection_uri_domain"), result.getString("app_id"),
6261
result.getString("tenant_id")),
6362
new EmailPasswordConfig(result.getBoolean("email_password_enabled")),
6463
new ThirdPartyConfig(
6564
result.getBoolean("third_party_enabled"),
66-
providers.length == 0 && isThirdPartyProvidersNull ? null : providers),
65+
providers),
6766
new PasswordlessConfig(result.getBoolean("passwordless_enabled")),
6867
firstFactors.length == 0 && isFirstFactorsNull ? null : firstFactors,
6968
requiredSecondaryFactors.length == 0 ? null : requiredSecondaryFactors,
@@ -82,7 +81,7 @@ public static TenantConfig[] selectAll(Start start,
8281
throws SQLException, StorageQueryException {
8382
String QUERY = "SELECT connection_uri_domain, app_id, tenant_id, core_config,"
8483
+ " email_password_enabled, passwordless_enabled, third_party_enabled, "
85-
+ " is_first_factors_null, is_third_party_providers_null FROM "
84+
+ " is_first_factors_null FROM "
8685
+ getConfig(start).getTenantConfigsTable() + ";";
8786

8887
TenantConfig[] tenantConfigs = execute(start, QUERY, pst -> {
@@ -121,8 +120,8 @@ public static void create(Start start, Connection sqlCon, TenantConfig tenantCon
121120
String QUERY = "INSERT INTO " + getConfig(start).getTenantConfigsTable()
122121
+ "(connection_uri_domain, app_id, tenant_id, core_config,"
123122
+ " email_password_enabled, passwordless_enabled, third_party_enabled,"
124-
+ " is_first_factors_null, is_third_party_providers_null)"
125-
+ " VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?)";
123+
+ " is_first_factors_null)"
124+
+ " VALUES(?, ?, ?, ?, ?, ?, ?, ?)";
126125

127126
update(sqlCon, QUERY, pst -> {
128127
pst.setString(1, tenantConfig.tenantIdentifier.getConnectionUriDomain());
@@ -133,7 +132,6 @@ public static void create(Start start, Connection sqlCon, TenantConfig tenantCon
133132
pst.setBoolean(6, tenantConfig.passwordlessConfig.enabled);
134133
pst.setBoolean(7, tenantConfig.thirdPartyConfig.enabled);
135134
pst.setBoolean(8, tenantConfig.firstFactors == null);
136-
pst.setBoolean(9, tenantConfig.thirdPartyConfig.providers == null);
137135
});
138136
}
139137

src/test/java/io/supertokens/storage/postgresql/test/multitenancy/StorageLayerTest.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -174,11 +174,12 @@ public void storageInstanceIsReusedAcrossTenants()
174174
StorageLayer.getStorage(new TenantIdentifier(null, null, null), process.getProcess()));
175175

176176
Assert.assertEquals(
177-
Config.getConfig(new TenantIdentifier(null, null, null), process.getProcess()).getAccessTokenValidity(),
177+
Config.getConfig(new TenantIdentifier(null, null, null), process.getProcess())
178+
.getAccessTokenValidityInMillis(),
178179
(long) 3600 * 1000);
179180

180181
Assert.assertEquals(Config.getConfig(new TenantIdentifier(null, "abc", null), process.getProcess())
181-
.getAccessTokenValidity(),
182+
.getAccessTokenValidityInMillis(),
182183
(long) 3601 * 1000);
183184

184185
Assert.assertEquals(
@@ -238,11 +239,12 @@ public void storageInstanceIsReusedAcrossTenantsComplex()
238239
StorageLayer.getStorage(new TenantIdentifier(null, null, null), process.getProcess()));
239240

240241
Assert.assertEquals(
241-
Config.getConfig(new TenantIdentifier(null, null, null), process.getProcess()).getAccessTokenValidity(),
242+
Config.getConfig(new TenantIdentifier(null, null, null), process.getProcess())
243+
.getAccessTokenValidityInMillis(),
242244
(long) 3600 * 1000);
243245

244246
Assert.assertEquals(Config.getConfig(new TenantIdentifier(null, "abc", null), process.getProcess())
245-
.getAccessTokenValidity(),
247+
.getAccessTokenValidityInMillis(),
246248
(long) 3601 * 1000);
247249

248250
Assert.assertEquals(
@@ -454,11 +456,12 @@ public void newStorageIsNotCreatedWhenSameTenantIsAdded()
454456
existingStorage);
455457

456458
Assert.assertEquals(
457-
Config.getConfig(new TenantIdentifier(null, null, null), process.getProcess()).getAccessTokenValidity(),
459+
Config.getConfig(new TenantIdentifier(null, null, null), process.getProcess())
460+
.getAccessTokenValidityInMillis(),
458461
(long) 3600 * 1000);
459462

460463
Assert.assertEquals(Config.getConfig(new TenantIdentifier(null, "abc", null), process.getProcess())
461-
.getAccessTokenValidity(),
464+
.getAccessTokenValidityInMillis(),
462465
(long) 3601 * 1000);
463466

464467
Assert.assertEquals(

0 commit comments

Comments
 (0)