bug5774: removed security check from expandable sortable columns to enable the default handling of premium settings.

- cleaned up some logs and todo's
- removed default premium DetailTypes, because they would now be active also without premium rights.
This commit is contained in:
Udo Wessels committed 2024-05-03 15:43:47 +02:00
1 parent 59490f04fd
commit 0e5f582ff5
6 files changed
+9 -23

No files matched your search

@@ -6,7 +6,6 @@ import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import com.google.gwt.core.client.GWT;
import com.google.gwt.core.client.Scheduler;
import com.google.gwt.core.client.Scheduler.ScheduledCommand;
import com.google.gwt.i18n.client.NumberFormat;
@@ -166,8 +165,6 @@ public class LiveRaceWithRacemapAndLeaderBoardPresenterImpl
@Override
public void onSuccess(StrippedLeaderboardDTO strippedLeaderboardDto) {
// TODO bug5774 Test if this code works
GWT.log("++++++ loaded stripped leaderboard DTO successfully +++++");
SecurityChildSettingsContext context = new SecurityChildSettingsContext(strippedLeaderboardDto,
new PaywallResolverImpl(getClientFactory().getUserService(),
getClientFactory().getSubscriptionServiceFactory()));
@@ -51,8 +51,6 @@ public abstract class LeaderboardSettings extends AbstractGenericSerializableSet
maneuverDetailsToShow = new SecuredEnumSetSetting<>("maneuverDetailsToShow", this, maneuverDetails, DetailType::valueOfString,
context.getPaywallResolver(), context.getSecuredDTO());
List<DetailType> legDetails = new ArrayList<>();
legDetails.add(DetailType.LEG_DISTANCE_TRAVELED);
legDetails.add(DetailType.LEG_AVERAGE_SPEED_OVER_GROUND_IN_KNOTS);
legDetails.add(DetailType.LEG_RANK_GAIN);
legDetailsToShow = new SecuredEnumSetSetting<>("legDetailsToShow", this, legDetails, DetailType::valueOfString,
context.getPaywallResolver(), context.getSecuredDTO());
@@ -117,15 +117,13 @@ public abstract class ExpandableSortableColumn<C> extends LeaderboardSortableCol
* if {@code true}, returns only columns for {@link DetailType}s for which the user has permissions to
* view
*/
protected Iterable<AbstractSortableColumnWithMinMax<LeaderboardRowDTO, ?>> getDirectChildren(boolean filterByPermissions) {
protected Iterable<AbstractSortableColumnWithMinMax<LeaderboardRowDTO, ?>> getDirectChildren() {
List<AbstractSortableColumnWithMinMax<LeaderboardRowDTO, ?>> result;
if (isExpanded()) {
result = new ArrayList<AbstractSortableColumnWithMinMax<LeaderboardRowDTO,?>>();
for (DetailType detailColumnType : detailSelection) {
AbstractSortableColumnWithMinMax<LeaderboardRowDTO, ?> selectedColumn = detailColumnsMap.get(detailColumnType);
if (selectedColumn != null &&
(!filterByPermissions || detailColumnType.getPremiumAction() == null ||
getLeaderboardPanel().getPaywallResolver().hasPermission(detailColumnType.getPremiumAction(), getLeaderboardPanel().getLeaderboard()))) {
if (selectedColumn != null) {
result.add(selectedColumn);
}
}
@@ -151,19 +149,16 @@ public abstract class ExpandableSortableColumn<C> extends LeaderboardSortableCol
* Note that for columns not currently visible or currently being expanded (see
* {@link #changeExpansionState(boolean)}), the column collection returned does not necessarily contain only columns
* really part of the {@link CellTable} used to display this column.
*
* @param filterByPermissions
* if {@code true}, returns only columns for {@link DetailType}s for which the user has permissions to view
*/
private Collection<AbstractSortableColumnWithMinMax<LeaderboardRowDTO, ?>> getAllVisibleChildren(boolean filterByPermissions) {
private Collection<AbstractSortableColumnWithMinMax<LeaderboardRowDTO, ?>> getAllVisibleChildren() {
List<AbstractSortableColumnWithMinMax<LeaderboardRowDTO, ?>> transitiveChildren = new ArrayList<>();
if (isExpanded()) {
for (AbstractSortableColumnWithMinMax<LeaderboardRowDTO, ?> childColumn : getDirectChildren(filterByPermissions)) {
for (AbstractSortableColumnWithMinMax<LeaderboardRowDTO, ?> childColumn : getDirectChildren()) {
transitiveChildren.add(childColumn);
if (childColumn instanceof ExpandableSortableColumn<?>) {
@SuppressWarnings("unchecked")
ExpandableSortableColumn<C> expandableChild = (ExpandableSortableColumn<C>) childColumn;
transitiveChildren.addAll(expandableChild.getAllVisibleChildren(/* filterByPermissions */ true));
transitiveChildren.addAll(expandableChild.getAllVisibleChildren());
}
}
}
@@ -206,7 +201,7 @@ public abstract class ExpandableSortableColumn<C> extends LeaderboardSortableCol
if (isExpanded()) { // but only if currently expanded
// don't filter by permissions; if we need to collapse columns after the user lost permissions or was logged out,
// columns currently still shown wouldn't be returned from getAllVisibleChildren otherwise
for (AbstractSortableColumnWithMinMax<LeaderboardRowDTO, ?> column : getAllVisibleChildren(/* filterByPermissions */ false)) {
for (AbstractSortableColumnWithMinMax<LeaderboardRowDTO, ?> column : getAllVisibleChildren()) {
getLeaderboardPanel().removeColumn(column); // removes only the children currently displayed
}
// important: toggle expanded state after asking for all visible children
@@ -227,7 +222,7 @@ public abstract class ExpandableSortableColumn<C> extends LeaderboardSortableCol
if (insertIndex != -1) {
insertIndex++;
// for expanding we filter by permissions in order to only show what the user is allowed to see
for (AbstractSortableColumnWithMinMax<LeaderboardRowDTO, ?> column : getAllVisibleChildren(/* filterByPermissions */ true)) {
for (AbstractSortableColumnWithMinMax<LeaderboardRowDTO, ?> column : getAllVisibleChildren()) {
column.updateMinMax();
if (table.getColumnIndex(column) < 0) {
getLeaderboardPanel().insertColumn(insertIndex++, column);
@@ -1507,9 +1507,9 @@ public abstract class LeaderboardPanel<LS extends LeaderboardSettings> extends A
}
@Override
protected Iterable<AbstractSortableColumnWithMinMax<LeaderboardRowDTO, ?>> getDirectChildren(boolean filterByPermissions) {
protected Iterable<AbstractSortableColumnWithMinMax<LeaderboardRowDTO, ?>> getDirectChildren() {
List<AbstractSortableColumnWithMinMax<LeaderboardRowDTO, ?>> result = new ArrayList<>();
for (AbstractSortableColumnWithMinMax<LeaderboardRowDTO, ?> column : super.getDirectChildren(filterByPermissions)) {
for (AbstractSortableColumnWithMinMax<LeaderboardRowDTO, ?> column : super.getDirectChildren()) {
result.add(column);
}
if (isExpanded() && getLeaderboard().canBoatsOfCompetitorsChangePerRace && selectedRaceDetails.contains(DetailType.RACE_DISPLAY_BOATS)) {
@@ -113,10 +113,7 @@ public abstract class PremiumCheckBox extends PremiumUiElement implements HasVal
@Override
public Boolean getValue() {
// TODO bug5774 Default value???
// hasPermission() &&
final Boolean result;
GWT.log("get secured value from " + checkBox.getTitle() + ": " + checkBox.getValue() + "(" + checkBox.isEnabled() + "), default value: " + defaultValue);
if (hasPermission()) {
result = checkBox.getValue();
} else {
@@ -64,7 +64,6 @@ public class SecuredEnumSetSetting<T extends Enum<T> & SecuredEnum> extends Abst
} else {
// handle default values
if (StreamSupport.stream(getDefaultValues().spliterator(), false).anyMatch(t -> t == singleValue)) {
GWT.log("Change not permitted but is set already by default value: " + singleValue.name());
permittedCollection.add(singleValue);
}
}