Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
18 changes: 14 additions & 4 deletions src/main/java/io/supertokens/storage/postgresql/Start.java
Original file line number Diff line number Diff line change
Expand Up @@ -1535,8 +1535,13 @@ public int deleteAllRolesForUser(String userId) throws StorageQueryException {
@Override
public boolean deleteRoleForUser_Transaction(TransactionConnection con, String userId, String role)
throws StorageQueryException {
// TODO
return false;
Connection sqlCon = (Connection) con.getConnection();

try {
return UserRolesQueries.deleteRoleForUser_Transaction(this, sqlCon, userId, role);
} catch (SQLException e) {
throw new StorageQueryException(e);
}
}

@Override
Expand Down Expand Up @@ -1586,7 +1591,12 @@ public int deleteAllPermissionsForRole_Transaction(TransactionConnection con, St

@Override
public boolean doesRoleExist_Transaction(TransactionConnection con, String role) throws StorageQueryException {
// TODO
return false;
Connection sqlCon = (Connection) con.getConnection();
try {
return UserRolesQueries.doesRoleExist_transaction(this, sqlCon, role);
} catch (SQLException e) {
throw new StorageQueryException(e);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -155,4 +155,23 @@ public static String[] getRolesForUser(Start start, String userId) throws SQLExc
return roles.toArray(String[]::new);
});
}

public static boolean deleteRoleForUser_Transaction(Start start, Connection con, String userId, String role)
throws SQLException, StorageQueryException {
String QUERY = "DELETE FROM " + getConfig(start).getUserRolesTable() + " WHERE user_id = ? AND role = ? ;";

// store the number of rows updated
int rowUpdatedCount = update(con, QUERY, pst -> {
pst.setString(1, userId);
pst.setString(2, role);
});
return rowUpdatedCount > 0;
}

public static boolean doesRoleExist_transaction(Start start, Connection con, String role)
throws SQLException, StorageQueryException {
String QUERY = "SELECT 1 FROM " + getConfig(start).getRolesTable() + " WHERE role = ? FOR UPDATE";
return execute(con, QUERY, pst -> pst.setString(1, role), ResultSet::next);
}

}