Skip to content

Commit

Permalink
CLDR-16272 limit some reports during limited submission (#2641)
Browse files Browse the repository at this point in the history
* CLDR-16272 disallow some reports in limited

- add a limited set of available reports in SubmissionLocales
- only show available reports in the sidebar
- don't count unavailable reports against completion in Dashboard

Note: This doesn't prohibit navigation to a disallowed report, nor voting on such report

* CLDR-16272 disallow API to reports in limited

- throw 403 Forbidden if user tries to navigate to or vote on un-available reports
  • Loading branch information
srl295 authored Jan 4, 2023
1 parent df4dbf0 commit 9a034c2
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.unicode.cldr.util.VoterReportStatus.ReportId;
import org.unicode.cldr.util.VoterReportStatus.ReportStatus;
import org.unicode.cldr.util.VoterProgress;
import org.unicode.cldr.util.VoterReportStatus;

import com.ibm.icu.impl.Relation;
import com.ibm.icu.impl.Row;
Expand Down Expand Up @@ -96,6 +97,7 @@ public void addReports(int userId, String localeId) {
final CLDRLocale locale = CLDRLocale.getInstance(localeId);
ReportStatus reportStatus = ReportsDB.getInstance().getReportStatus(userId, locale);
EnumSet<ReportId> incomplete = EnumSet.complementOf(reportStatus.completed);
incomplete.retainAll(VoterReportStatus.ReportId.getReportsAvailable()); // remove reports not actually available
if (!incomplete.isEmpty()) {
ReviewNotificationGroup rng = new ReviewNotificationGroup("Reports", "", "");
incomplete.forEach(r -> rng.add(r.name()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,7 @@ private void processRequest(HttpServletRequest request, HttpServletResponse resp
report.put("url", m.urlStub());
reports.put(report);
}
for (final ReportId m : ReportId.values()) {
for (final ReportId m : ReportId.getReportsAvailable()) {
JSONObject report = new JSONObject();
report.put("url", "r_" + m.name());
reports.put(report);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ public Response getReportLocaleStatus(
for (final CLDRLocale loc : locales) {
LocaleReportVettingResult rr = new LocaleReportVettingResult();
rr.locale = loc.toString();
for (final ReportId report : ReportId.values()) {
for (final ReportId report : ReportId.getReportsAvailable()) {
Map<ReportAcceptability, Set<Integer>> statistics = db.updateResolver(loc, report, allUsers, res);
rr.reports.add(new ReportVettingResult(report, res, statistics));
statistics.values().forEach(s -> rr.addVoters(s));
Expand Down Expand Up @@ -274,6 +274,9 @@ public Response updateReport(
if (mySession.user == null || mySession.user.id != user) {
return Response.status(Status.FORBIDDEN).build();
}
if (!report.isAvailable()) {
return Response.status(Status.FORBIDDEN).build();
}
ReportsDB.getInstance()
.markReportComplete(user, CLDRLocale.getInstance(locale),
report, update.completed, update.acceptable);
Expand All @@ -291,7 +294,7 @@ public Response updateReport(
schema = @Schema(type = SchemaType.ARRAY, implementation = String.class))
)
public Response listReports() {
return Response.ok().entity(ReportId.values()).build();
return Response.ok().entity(ReportId.getReportsAvailable().toArray()).build();
}
@Schema(description = "update to user’s report status")
public static final class ReportUpdate {
Expand Down Expand Up @@ -329,6 +332,9 @@ public Response getReportOutput(
// No such locale
return Response.status(Status.NOT_FOUND).build();
}
if (!report.isAvailable()) {
return Response.status(Status.FORBIDDEN).build();
}
final String result;
try {
result = writeReport(report, loc);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.unicode.cldr.test;

import java.util.Collections;
import java.util.EnumSet;
import java.util.HashSet;
import java.util.Set;
import java.util.concurrent.ExecutionException;
Expand All @@ -12,6 +14,8 @@
import org.unicode.cldr.util.RegexUtilities;
import org.unicode.cldr.util.StandardCodes;
import org.unicode.cldr.util.SupplementalDataInfo;
import org.unicode.cldr.util.VoterReportStatus;
import org.unicode.cldr.util.VoterReportStatus.ReportId;

import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
Expand Down Expand Up @@ -61,6 +65,13 @@ public final class SubmissionLocales {
.addAll(HIGH_LEVEL_LOCALES)
.build();

/**
* Subset of reports open for this release
*/
private static final Set<ReportId> LIMITED_SUBMISSION_REPORTS = Collections.unmodifiableSet(EnumSet.of(
VoterReportStatus.ReportId.personnames
));


/**
* Subset of CLDR_LOCALES, minus special which are only those which
Expand Down Expand Up @@ -226,4 +237,8 @@ public static boolean pathAllowedInLimitedSubmission(String path) {
}
return result;
}

public static Set<ReportId> getReportsAvailableInLimited() {
return LIMITED_SUBMISSION_REPORTS;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
import java.util.Map;
import java.util.Set;

import org.unicode.cldr.test.CheckCLDR;
import org.unicode.cldr.test.SubmissionLocales;


/**
* This interface is for objects which can expose information on which reports have been completed.
Expand All @@ -23,7 +26,23 @@ public enum ReportId {
datetime, // non-Chart
zones, // non-Chart
compact, // non-Chart, aka 'numbers'
personnames // Chart
personnames; // Chart

/**
* True if this report is available in this vetting period
* @return
*/
public boolean isAvailable() {
return (!CheckCLDR.LIMITED_SUBMISSION) || (SubmissionLocales.getReportsAvailableInLimited().contains(this));
}

public static Set<ReportId> getReportsAvailable() {
if (!CheckCLDR.LIMITED_SUBMISSION) {
return EnumSet.allOf(ReportId.class);
} else {
return SubmissionLocales.getReportsAvailableInLimited();
}
}
};

public enum ReportAcceptability {
Expand Down

0 comments on commit 9a034c2

Please sign in to comment.