Skip to content

Commit

Permalink
fix: according to updated interface
Browse files Browse the repository at this point in the history
  • Loading branch information
sattvikc committed Mar 4, 2024
1 parent 02cd419 commit ccf6a12
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 38 deletions.
16 changes: 14 additions & 2 deletions src/main/java/io/supertokens/storage/postgresql/Start.java
Original file line number Diff line number Diff line change
Expand Up @@ -2001,9 +2001,21 @@ public String[] getRolesThatHavePermission(AppIdentifier appIdentifier, String p
}

@Override
public boolean deleteRole(AppIdentifier appIdentifier, String role) throws StorageQueryException {
public boolean deleteRole_Transaction(TransactionConnection con, AppIdentifier appIdentifier, String role) throws StorageQueryException {
try {
return UserRolesQueries.deleteRole(this, appIdentifier, role);
return UserRolesQueries.deleteRole_Transaction(this, (Connection) con.getConnection(), appIdentifier, role);
} catch (SQLException e) {
throw new StorageQueryException(e);
}
}

@Override
public boolean deleteAllUserRoleAssociationsForRole_Transaction(TransactionConnection con,
AppIdentifier appIdentifier, String role)
throws StorageQueryException {
try {
return UserRolesQueries.deleteAllUserRoleAssociationsForRole_Transaction(this,
(Connection) con.getConnection(), appIdentifier, role);
} catch (SQLException e) {
throw new StorageQueryException(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import io.supertokens.pluginInterface.exceptions.StorageTransactionLogicException;
import io.supertokens.pluginInterface.multitenancy.AppIdentifier;
import io.supertokens.pluginInterface.multitenancy.TenantIdentifier;
import io.supertokens.pluginInterface.sqlStorage.TransactionConnection;
import io.supertokens.storage.postgresql.Start;
import io.supertokens.storage.postgresql.config.Config;
import io.supertokens.storage.postgresql.utils.Utils;
Expand Down Expand Up @@ -140,43 +141,15 @@ public static void addPermissionToRoleOrDoNothingIfExists_Transaction(Start star
});
}

public static boolean deleteRole(Start start, AppIdentifier appIdentifier, String role)
public static boolean deleteRole_Transaction(Start start, Connection sqlCon, AppIdentifier appIdentifier,
String role)
throws SQLException, StorageQueryException {
try {
return start.startTransaction(con -> {
boolean deleted = false;
Connection sqlCon = (Connection) con.getConnection();
try {
{
String QUERY = "DELETE FROM " + getConfig(start).getUserRolesTable()
+ " WHERE app_id = ? AND role = ? ;";
deleted = update(sqlCon, QUERY, pst -> {
pst.setString(1, appIdentifier.getAppId());
pst.setString(2, role);
}) == 1;
}
{
String QUERY = "DELETE FROM " + getConfig(start).getRolesTable()
+ " WHERE app_id = ? AND role = ? ;";
return update(sqlCon, QUERY, pst -> {
pst.setString(1, appIdentifier.getAppId());
pst.setString(2, role);
}) == 1 || deleted;
}
} catch (StorageQueryException e) {
throw new StorageTransactionLogicException(e);
} catch (SQLException e) {
throw new StorageTransactionLogicException(e);
}
});
} catch (StorageTransactionLogicException e) {
if (e.actualException instanceof SQLException) {
throw (SQLException) e.actualException;
} else if (e.actualException instanceof StorageQueryException) {
throw (StorageQueryException) e.actualException;
}
throw new IllegalStateException(e.actualException);
}
String QUERY = "DELETE FROM " + getConfig(start).getRolesTable()
+ " WHERE app_id = ? AND role = ? ;";
return update(sqlCon, QUERY, pst -> {
pst.setString(1, appIdentifier.getAppId());
pst.setString(2, role);
}) == 1;
}

public static boolean doesRoleExist(Start start, AppIdentifier appIdentifier, String role)
Expand Down Expand Up @@ -380,4 +353,14 @@ public static int deleteAllRolesForUser_Transaction(Connection con, Start start,
pst.setString(2, userId);
});
}

public static boolean deleteAllUserRoleAssociationsForRole_Transaction(Start start, Connection sqlCon, AppIdentifier appIdentifier, String role)
throws SQLException, StorageQueryException {
String QUERY = "DELETE FROM " + getConfig(start).getUserRolesTable()
+ " WHERE app_id = ? AND role = ? ;";
return update(sqlCon, QUERY, pst -> {
pst.setString(1, appIdentifier.getAppId());
pst.setString(2, role);
}) >= 1;
}
}

0 comments on commit ccf6a12

Please sign in to comment.