Skip to content

Commit

Permalink
fix: function updates
Browse files Browse the repository at this point in the history
  • Loading branch information
sattvikc committed Sep 13, 2023
1 parent 6b52b86 commit f1ace2b
Show file tree
Hide file tree
Showing 9 changed files with 190 additions and 112 deletions.
57 changes: 48 additions & 9 deletions src/main/java/io/supertokens/inmemorydb/Start.java
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,12 @@ public void updateSessionInfo_Transaction(TenantIdentifier tenantIdentifier, Tra
@Override
public void deleteSessionsOfUser_Transaction(TransactionConnection con, AppIdentifier appIdentifier, String userId)
throws StorageQueryException {
// TODO:..
Connection sqlCon = (Connection) con.getConnection();
try {
SessionQueries.deleteSessionsOfUser_Transaction(sqlCon, this, appIdentifier, userId);
} catch (SQLException e) {
throw new StorageQueryException(e);
}
}

@Override
Expand Down Expand Up @@ -871,7 +876,12 @@ public void updateUsersEmail_Transaction(AppIdentifier appIdentifier, Transactio
public void deleteEmailPasswordUser_Transaction(TransactionConnection con, AppIdentifier appIdentifier,
String userId, boolean deleteUserIdMappingToo)
throws StorageQueryException {
// TODO..
try {
Connection sqlCon = (Connection) con.getConnection();
EmailPasswordQueries.deleteUser_Transaction(sqlCon, this, appIdentifier, userId, deleteUserIdMappingToo);
} catch (SQLException e) {
throw new StorageQueryException(e);
}
}

@Override
Expand Down Expand Up @@ -949,7 +959,12 @@ public void updateIsEmailVerified_Transaction(AppIdentifier appIdentifier, Trans
@Override
public void deleteEmailVerificationUserInfo_Transaction(TransactionConnection con, AppIdentifier appIdentifier,
String userId) throws StorageQueryException {
// TODO..
try {
Connection sqlCon = (Connection) con.getConnection();
EmailVerificationQueries.deleteUserInfo_Transaction(sqlCon, this, appIdentifier, userId);
} catch (SQLException e) {
throw new StorageQueryException(e);
}
}

@Override
Expand Down Expand Up @@ -1070,7 +1085,12 @@ public void updateUserEmail_Transaction(AppIdentifier appIdentifier, Transaction
public void deleteThirdPartyUser_Transaction(TransactionConnection con, AppIdentifier appIdentifier, String userId,
boolean deleteUserIdMappingToo)
throws StorageQueryException {
// TODO..
try {
Connection sqlCon = (Connection) con.getConnection();
ThirdPartyQueries.deleteUser_Transaction(sqlCon, this, appIdentifier, userId, deleteUserIdMappingToo);
} catch (SQLException e) {
throw new StorageQueryException(e);
}
}

@Override
Expand Down Expand Up @@ -1203,7 +1223,12 @@ public int countUsersEnabledTotpAndActiveSince(AppIdentifier appIdentifier, long
@Override
public void deleteUserActive_Transaction(TransactionConnection con, AppIdentifier appIdentifier, String userId)
throws StorageQueryException {
// TODO:..
try {
Connection sqlCon = (Connection) con.getConnection();
ActiveUsersQueries.deleteUserActive_Transaction(sqlCon, this, appIdentifier, userId);
} catch (SQLException e) {
throw new StorageQueryException(e);
}
}

@Override
Expand Down Expand Up @@ -1539,7 +1564,12 @@ public void updateUserPhoneNumber_Transaction(AppIdentifier appIdentifier, Trans
public void deletePasswordlessUser_Transaction(TransactionConnection con, AppIdentifier appIdentifier,
String userId, boolean deleteUserIdMappingToo)
throws StorageQueryException {
// TODO..
try {
Connection sqlCon = (Connection) con.getConnection();
PasswordlessQueries.deleteUser_Transaction(sqlCon, this, appIdentifier, userId, deleteUserIdMappingToo);
} catch (SQLException e) {
throw new StorageQueryException(e);
}
}

@Override
Expand Down Expand Up @@ -1795,8 +1825,12 @@ public int setUserMetadata_Transaction(AppIdentifier appIdentifier, TransactionC
@Override
public int deleteUserMetadata_Transaction(TransactionConnection con, AppIdentifier appIdentifier, String userId)
throws StorageQueryException {
// TODO:..
return 0;
try {
Connection sqlCon = (Connection) con.getConnection();
return UserMetadataQueries.deleteUserMetadata_Transaction(sqlCon, this, appIdentifier, userId);
} catch (SQLException e) {
throw new StorageQueryException(e);
}
}

@Override
Expand Down Expand Up @@ -2032,7 +2066,12 @@ public boolean doesRoleExist_Transaction(AppIdentifier appIdentifier, Transactio
@Override
public void deleteAllRolesForUser_Transaction(TransactionConnection con, AppIdentifier appIdentifier, String userId)
throws StorageQueryException {
// TODO..
try {
Connection sqlCon = (Connection) con.getConnection();
UserRoleQueries.deleteAllRolesForUser_Transaction(sqlCon, this, appIdentifier, userId);
} catch (SQLException e) {
throw new StorageQueryException(e);
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.supertokens.inmemorydb.queries;

import java.sql.Connection;
import java.sql.SQLException;

import io.supertokens.inmemorydb.config.Config;
Expand Down Expand Up @@ -101,12 +102,12 @@ public static Long getLastActiveByUserId(Start start, AppIdentifier appIdentifie
}
}

public static void deleteUserActive(Start start, AppIdentifier appIdentifier, String userId)
public static void deleteUserActive_Transaction(Connection con, Start start, AppIdentifier appIdentifier, String userId)
throws StorageQueryException, SQLException {
String QUERY = "DELETE FROM " + Config.getConfig(start).getUserLastActiveTable()
+ " WHERE app_id = ? AND user_id = ?";

update(start, QUERY, pst -> {
update(con, QUERY, pst -> {
pst.setString(1, appIdentifier.getAppId());
pst.setString(2, userId);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -294,27 +294,35 @@ public static AuthRecipeUserInfo signUp(Start start, TenantIdentifier tenantIden
});
}

public static void deleteUser(Start start, AppIdentifier appIdentifier, String userId)
throws StorageQueryException, StorageTransactionLogicException {
start.startTransaction(con -> {
Connection sqlCon = (Connection) con.getConnection();
try {
{
String QUERY = "DELETE FROM " + getConfig(start).getAppIdToUserIdTable()
+ " WHERE app_id = ? AND user_id = ?";
public static void deleteUser_Transaction(Connection sqlCon, Start start, AppIdentifier appIdentifier, String userId, boolean deleteUserIdMappingToo)
throws StorageQueryException, SQLException {
if (deleteUserIdMappingToo) {
String QUERY = "DELETE FROM " + getConfig(start).getAppIdToUserIdTable()
+ " WHERE app_id = ? AND user_id = ?";

update(sqlCon, QUERY, pst -> {
pst.setString(1, appIdentifier.getAppId());
pst.setString(2, userId);
});
}
update(sqlCon, QUERY, pst -> {
pst.setString(1, appIdentifier.getAppId());
pst.setString(2, userId);
});
} else {
{
String QUERY = "DELETE FROM " + getConfig(start).getUsersTable()
+ " WHERE app_id = ? AND user_id = ?";
update(sqlCon, QUERY, pst -> {
pst.setString(1, appIdentifier.getAppId());
pst.setString(2, userId);
});
}

sqlCon.commit();
} catch (SQLException throwables) {
throw new StorageTransactionLogicException(throwables);
{
String QUERY = "DELETE FROM " + getConfig(start).getEmailPasswordUsersTable()
+ " WHERE app_id = ? AND user_id = ?";
update(sqlCon, QUERY, pst -> {
pst.setString(1, appIdentifier.getAppId());
pst.setString(2, userId);
});
}
return null;
});
}
}

public static UserInfoPartial getUserInfoUsingId(Start start, Connection sqlCon, AppIdentifier appIdentifier,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -278,36 +278,26 @@ public static List<String> isEmailVerified_transaction(Start start, Connection s
});
}

public static void deleteUserInfo(Start start, AppIdentifier appIdentifier, String userId)
throws StorageQueryException, StorageTransactionLogicException {
start.startTransaction(con -> {
Connection sqlCon = (Connection) con.getConnection();
try {
{
String QUERY = "DELETE FROM " + getConfig(start).getEmailVerificationTable()
+ " WHERE app_id = ? AND user_id = ?";
update(sqlCon, QUERY, pst -> {
pst.setString(1, appIdentifier.getAppId());
pst.setString(2, userId);
});
}

{
String QUERY = "DELETE FROM " + getConfig(start).getEmailVerificationTokensTable()
+ " WHERE app_id = ? AND user_id = ?";
public static void deleteUserInfo_Transaction(Connection sqlCon, Start start, AppIdentifier appIdentifier, String userId)
throws StorageQueryException, SQLException {
{
String QUERY = "DELETE FROM " + getConfig(start).getEmailVerificationTable()
+ " WHERE app_id = ? AND user_id = ?";
update(sqlCon, QUERY, pst -> {
pst.setString(1, appIdentifier.getAppId());
pst.setString(2, userId);
});
}

update(sqlCon, QUERY, pst -> {
pst.setString(1, appIdentifier.getAppId());
pst.setString(2, userId);
});
}
{
String QUERY = "DELETE FROM " + getConfig(start).getEmailVerificationTokensTable()
+ " WHERE app_id = ? AND user_id = ?";

sqlCon.commit();
} catch (SQLException throwables) {
throw new StorageTransactionLogicException(throwables);
}
return null;
});
update(sqlCon, QUERY, pst -> {
pst.setString(1, appIdentifier.getAppId());
pst.setString(2, userId);
});
}
}

public static boolean deleteUserInfo(Start start, TenantIdentifier tenantIdentifier, String userId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -460,46 +460,54 @@ private static UserInfoWithTenantId[] getUserInfosWithTenant(Start start, Connec
});
}

public static void deleteUser(Start start, AppIdentifier appIdentifier, String userId)
throws StorageQueryException, StorageTransactionLogicException {
start.startTransaction(con -> {
Connection sqlCon = (Connection) con.getConnection();
try {
UserInfoWithTenantId[] userInfos = getUserInfosWithTenant(start, sqlCon, appIdentifier, userId);
public static void deleteUser_Transaction(Connection sqlCon, Start start, AppIdentifier appIdentifier, String userId, boolean deleteUserIdMappingToo)
throws StorageQueryException, SQLException {
UserInfoWithTenantId[] userInfos = getUserInfosWithTenant(start, sqlCon, appIdentifier, userId);

{
String QUERY = "DELETE FROM " + getConfig(start).getAppIdToUserIdTable()
+ " WHERE app_id = ? AND user_id = ?";
if (deleteUserIdMappingToo) {
String QUERY = "DELETE FROM " + getConfig(start).getAppIdToUserIdTable()
+ " WHERE app_id = ? AND user_id = ?";

update(sqlCon, QUERY, pst -> {
pst.setString(1, appIdentifier.getAppId());
pst.setString(2, userId);
});
}
update(sqlCon, QUERY, pst -> {
pst.setString(1, appIdentifier.getAppId());
pst.setString(2, userId);
});
} else {
{
String QUERY = "DELETE FROM " + getConfig(start).getUsersTable()
+ " WHERE app_id = ? AND user_id = ?";
update(sqlCon, QUERY, pst -> {
pst.setString(1, appIdentifier.getAppId());
pst.setString(2, userId);
});
}

for (UserInfoWithTenantId userInfo : userInfos) {
if (userInfo.email != null) {
deleteDevicesByEmail_Transaction(start, sqlCon,
new TenantIdentifier(
appIdentifier.getConnectionUriDomain(), appIdentifier.getAppId(),
userInfo.tenantId),
userInfo.email);
}
if (userInfo.phoneNumber != null) {
deleteDevicesByPhoneNumber_Transaction(start, sqlCon,
new TenantIdentifier(
appIdentifier.getConnectionUriDomain(), appIdentifier.getAppId(),
userInfo.tenantId),
userInfo.phoneNumber);
}
}
{
String QUERY = "DELETE FROM " + getConfig(start).getPasswordlessUsersTable()
+ " WHERE app_id = ? AND user_id = ?";
update(sqlCon, QUERY, pst -> {
pst.setString(1, appIdentifier.getAppId());
pst.setString(2, userId);
});
}
}

sqlCon.commit();
} catch (SQLException throwables) {
throw new StorageTransactionLogicException(throwables);
for (UserInfoWithTenantId userInfo : userInfos) {
if (userInfo.email != null) {
deleteDevicesByEmail_Transaction(start, sqlCon,
new TenantIdentifier(
appIdentifier.getConnectionUriDomain(), appIdentifier.getAppId(),
userInfo.tenantId),
userInfo.email);
}
return null;
});
if (userInfo.phoneNumber != null) {
deleteDevicesByPhoneNumber_Transaction(start, sqlCon,
new TenantIdentifier(
appIdentifier.getConnectionUriDomain(), appIdentifier.getAppId(),
userInfo.tenantId),
userInfo.phoneNumber);
}
}
}

public static int updateUserEmail_Transaction(Start start, Connection con, AppIdentifier appIdentifier,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,18 @@ public static int deleteSession(Start start, TenantIdentifier tenantIdentifier,
});
}

public static void deleteSessionsOfUser_Transaction(Connection sqlCon, Start start, AppIdentifier appIdentifier,
String userId)
throws SQLException, StorageQueryException {
String QUERY = "DELETE FROM " + getConfig(start).getSessionInfoTable()
+ " WHERE app_id = ? AND user_id = ?";

update(sqlCon, QUERY.toString(), pst -> {
pst.setString(1, appIdentifier.getAppId());
pst.setString(2, userId);
});
}

public static void deleteSessionsOfUser(Start start, AppIdentifier appIdentifier, String userId)
throws SQLException, StorageQueryException {
String QUERY = "DELETE FROM " + getConfig(start).getSessionInfoTable()
Expand Down
Loading

0 comments on commit f1ace2b

Please sign in to comment.