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
17 changes: 13 additions & 4 deletions src/main/java/io/supertokens/storage/postgresql/Start.java
Original file line number Diff line number Diff line change
Expand Up @@ -1581,15 +1581,24 @@ public void addPermissionToRoleOrDoNothingIfExists_Transaction(TransactionConnec
@Override
public boolean deletePermissionForRole_Transaction(TransactionConnection con, String role, String permission)
throws StorageQueryException {
// TODO
return false;
Connection sqlCon = (Connection) con.getConnection();
try {
return UserRolesQueries.deletePermissionForRole_Transaction(this, sqlCon, role, permission);
} catch (SQLException e) {
throw new StorageQueryException(e);
}
}

@Override
public int deleteAllPermissionsForRole_Transaction(TransactionConnection con, String role)
throws StorageQueryException {
// TODO
return 0;

Connection sqlCon = (Connection) con.getConnection();
try {
return UserRolesQueries.deleteAllPermissionsForRole_Transaction(this, sqlCon, role);
} catch (SQLException e) {
throw new StorageQueryException(e);
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,4 +184,30 @@ public static String[] getUsersForRole(Start start, String role) throws SQLExcep
return userIds.toArray(String[]::new);
});
}

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

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

return rowUpdatedCount > 0;
}

public static int deleteAllPermissionsForRole_Transaction(Start start, Connection con, String role)
throws SQLException, StorageQueryException {

String QUERY = "DELETE FROM " + getConfig(start).getUserRolesPermissionsTable() + " WHERE role = ? ";
// return the number of rows updated
return update(con, QUERY, pst -> {
pst.setString(1, role);
});

}

}