Skip to content

Commit

Permalink
fix: refactor transaction functions (#120)
Browse files Browse the repository at this point in the history
  • Loading branch information
sattvikc authored Oct 3, 2023
1 parent 7dbc14f commit e18b86a
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright (c) 2023, VRAI Labs and/or its affiliates. All rights reserved.
*
* This software is licensed under the Apache License, Version 2.0 (the
* "License") as published by the Apache Software Foundation.
*
* You may not use this file except in compliance with the License. You may
* obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/

package io.supertokens.pluginInterface;

import io.supertokens.pluginInterface.exceptions.StorageQueryException;
import io.supertokens.pluginInterface.multitenancy.AppIdentifier;
import io.supertokens.pluginInterface.sqlStorage.SQLStorage;
import io.supertokens.pluginInterface.sqlStorage.TransactionConnection;

public interface ActiveUsersSQLStorage extends ActiveUsersStorage, SQLStorage {
/* Delete a user from active users table */
void deleteUserActive_Transaction(TransactionConnection con, AppIdentifier appIdentifier, String userId)
throws StorageQueryException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,5 @@ public interface ActiveUsersStorage extends NonAuthRecipeStorage {
/* Count the number of users who have enabled MFA and are active */
int countUsersEnabledMfaAndActiveSince(AppIdentifier appIdentifier, long time) throws StorageQueryException;

/* Delete a user from active users table */
void deleteUserActive_Transaction(TransactionConnection con, AppIdentifier appIdentifier, String userId)
throws StorageQueryException;

int countUsersThatHaveMoreThanOneLoginMethodAndActiveSince(AppIdentifier appIdentifier, long sinceTime) throws StorageQueryException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import io.supertokens.pluginInterface.multitenancy.AppIdentifier;
import io.supertokens.pluginInterface.multitenancy.TenantIdentifier;
import io.supertokens.pluginInterface.nonAuthRecipe.NonAuthRecipeStorage;
import io.supertokens.pluginInterface.sqlStorage.TransactionConnection;

public interface MfaStorage extends NonAuthRecipeStorage {
// Enable (insert) a factor for a user and return true if it actually inserted something.
Expand All @@ -15,9 +16,6 @@ public interface MfaStorage extends NonAuthRecipeStorage {
// Disable (delete) a factor for a user and return true if it actually deleted something.
boolean disableFactor(TenantIdentifier tenantIdentifier, String userId, String factorId) throws StorageQueryException;

// Delete a user across all tenants (with all the relevant factors)
boolean deleteMfaInfoForUser(AppIdentifier appIdentifier, String userId) throws StorageQueryException;

// Delete a user from a tenant (with all the relevant factors)
boolean deleteMfaInfoForUser(TenantIdentifier tenantIdentifier, String userId) throws StorageQueryException;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright (c) 2023, VRAI Labs and/or its affiliates. All rights reserved.
*
* This software is licensed under the Apache License, Version 2.0 (the
* "License") as published by the Apache Software Foundation.
*
* You may not use this file except in compliance with the License. You may
* obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/

package io.supertokens.pluginInterface.mfa.sqlStorage;

import io.supertokens.pluginInterface.exceptions.StorageQueryException;
import io.supertokens.pluginInterface.mfa.MfaStorage;
import io.supertokens.pluginInterface.multitenancy.AppIdentifier;
import io.supertokens.pluginInterface.sqlStorage.SQLStorage;
import io.supertokens.pluginInterface.sqlStorage.TransactionConnection;

public interface MfaSQLStorage extends MfaStorage, SQLStorage {
// Delete a user across all tenants (with all the relevant factors)
boolean deleteMfaInfoForUser_Transaction(TransactionConnection con, AppIdentifier appIdentifier, String userId) throws
StorageQueryException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,18 @@

package io.supertokens.pluginInterface.multitenancy;

import io.supertokens.pluginInterface.ActiveUsersStorage;
import io.supertokens.pluginInterface.ActiveUsersSQLStorage;
import io.supertokens.pluginInterface.STORAGE_TYPE;
import io.supertokens.pluginInterface.Storage;
import io.supertokens.pluginInterface.authRecipe.AuthRecipeStorage;
import io.supertokens.pluginInterface.dashboard.sqlStorage.DashboardSQLStorage;
import io.supertokens.pluginInterface.emailpassword.sqlStorage.EmailPasswordSQLStorage;
import io.supertokens.pluginInterface.emailverification.sqlStorage.EmailVerificationSQLStorage;
import io.supertokens.pluginInterface.mfa.sqlStorage.MfaSQLStorage;
import io.supertokens.pluginInterface.passwordless.sqlStorage.PasswordlessSQLStorage;
import io.supertokens.pluginInterface.session.SessionStorage;
import io.supertokens.pluginInterface.thirdparty.sqlStorage.ThirdPartySQLStorage;
import io.supertokens.pluginInterface.totp.sqlStorage.TOTPSQLStorage;
import io.supertokens.pluginInterface.mfa.MfaStorage;
import io.supertokens.pluginInterface.useridmapping.UserIdMappingStorage;
import io.supertokens.pluginInterface.usermetadata.sqlStorage.UserMetadataSQLStorage;
import io.supertokens.pluginInterface.userroles.sqlStorage.UserRolesSQLStorage;
Expand Down Expand Up @@ -153,19 +153,19 @@ public TOTPSQLStorage getTOTPStorage() {
return (TOTPSQLStorage) this.storage;
}

public MfaStorage getMfaStorage() {
public MfaSQLStorage getMfaStorage() {
if (this.storage.getType() != STORAGE_TYPE.SQL) {
// we only support SQL for now
throw new UnsupportedOperationException("");
}
return (MfaStorage) this.storage;
return (MfaSQLStorage) this.storage;
}

public ActiveUsersStorage getActiveUsersStorage() {
public ActiveUsersSQLStorage getActiveUsersStorage() {
if (this.storage.getType() != STORAGE_TYPE.SQL) {
// we only support SQL for now
throw new UnsupportedOperationException("");
}
return (ActiveUsersStorage) this.storage;
return (ActiveUsersSQLStorage) this.storage;
}
}

0 comments on commit e18b86a

Please sign in to comment.