From 737b43c0a12457b516d0878cb9ab715a4e9526bf Mon Sep 17 00:00:00 2001
From: "Steven R. Loomis"
Date: Tue, 2 Jul 2024 16:24:07 -0500
Subject: [PATCH] CLDR-17776 st: disable report page if unavailable
- UI: disable radio group if canVote is false.
- cldrReport: update API to expose canVote
- ReportAPI: expose canVote over REST if the user can vote on the report
---
tools/cldr-apps/js/src/esm/cldrReport.mjs | 8 +++----
.../cldr-apps/js/src/views/ReportResponse.vue | 8 ++++---
.../org/unicode/cldr/web/api/ReportAPI.java | 22 ++++++++++++++-----
3 files changed, 25 insertions(+), 13 deletions(-)
diff --git a/tools/cldr-apps/js/src/esm/cldrReport.mjs b/tools/cldr-apps/js/src/esm/cldrReport.mjs
index b8f3c47c781..27430b760fc 100644
--- a/tools/cldr-apps/js/src/esm/cldrReport.mjs
+++ b/tools/cldr-apps/js/src/esm/cldrReport.mjs
@@ -112,7 +112,7 @@ async function getOneLocaleStatus(locale) {
`getOneLocaleStatus(${locale}) expected an array of one item but got ${obj.locales.length}`
);
}
- return obj.locales[0].reports;
+ return obj.locales[0];
}
/**
@@ -122,9 +122,9 @@ async function getOneLocaleStatus(locale) {
* @returns
*/
async function getOneReportLocaleStatus(locale, onlyReport) {
- const reports = await getOneLocaleStatus(locale);
- const myReport = reports.filter(({ report }) => report === onlyReport)[0];
- return myReport;
+ const { reports, canVote } = await getOneLocaleStatus(locale);
+ const report = reports.filter(({ report }) => report === onlyReport)[0];
+ return { report, canVote };
}
/**
diff --git a/tools/cldr-apps/js/src/views/ReportResponse.vue b/tools/cldr-apps/js/src/views/ReportResponse.vue
index 2ca780ed086..88f7b1bc7ab 100644
--- a/tools/cldr-apps/js/src/views/ReportResponse.vue
+++ b/tools/cldr-apps/js/src/views/ReportResponse.vue
@@ -10,7 +10,7 @@
before continuing.
-
+
I have reviewed the items below, and they are all acceptable
@@ -60,6 +60,7 @@ export default {
],
data() {
return {
+ canVote: false,
completed: false,
acceptable: false,
loaded: false,
@@ -211,9 +212,10 @@ export default {
completed: this.completed,
acceptable: this.acceptable,
});
- this.reportStatus = await reportLocaleStatusResponse; // { status: approved, acceptability: acceptable }
- console.dir(await reportLocaleStatusResponse);
+ const { report, canVote } = await reportLocaleStatusResponse;
+ this.reportStatus = report; // { status: approved, acceptability: acceptable }
this.loaded = true;
+ this.canVote = canVote;
this.error = null;
} catch (e) {
cldrNotify.exception(
diff --git a/tools/cldr-apps/src/main/java/org/unicode/cldr/web/api/ReportAPI.java b/tools/cldr-apps/src/main/java/org/unicode/cldr/web/api/ReportAPI.java
index d91c5d91d07..039a833aa97 100644
--- a/tools/cldr-apps/src/main/java/org/unicode/cldr/web/api/ReportAPI.java
+++ b/tools/cldr-apps/src/main/java/org/unicode/cldr/web/api/ReportAPI.java
@@ -7,7 +7,6 @@
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
-import java.util.logging.Logger;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.HeaderParam;
@@ -40,15 +39,12 @@
import org.unicode.cldr.web.STFactory;
import org.unicode.cldr.web.SubtypeToURLMap;
import org.unicode.cldr.web.SurveyAjax;
-import org.unicode.cldr.web.SurveyLog;
import org.unicode.cldr.web.SurveyMain;
import org.unicode.cldr.web.UserRegistry;
@Path("/voting/reports")
@Tag(name = "voting", description = "APIs for voting and retrieving vote and row data")
public class ReportAPI {
- static final Logger logger = SurveyLog.forClass(ReportAPI.class);
-
@GET
@Path("/users/{user}")
@Produces(MediaType.APPLICATION_JSON)
@@ -195,7 +191,15 @@ public Response getReportLocaleStatus(
// set of all valid userids
final Set allUsers = CookieSession.sm.reg.getVoterToInfo().keySet();
for (final CLDRLocale loc : locales) {
- LocaleReportVettingResult rr = new LocaleReportVettingResult();
+ CheckCLDR.Phase phase = SurveyMain.checkCLDRPhase(loc);
+ CheckCLDR.StatusAction showRowAction =
+ phase.getShowRowAction(
+ null /* not path based */,
+ CheckCLDR.InputMethod.DIRECT,
+ null /* Not path based */,
+ mySession.user);
+ final boolean canModify = UserRegistry.userCanModifyLocale(mySession.user, loc);
+ LocaleReportVettingResult rr = new LocaleReportVettingResult(showRowAction, canModify);
rr.locale = loc.toString();
for (final ReportId report : ReportId.getReportsAvailable()) {
Map votes = new TreeMap<>();
@@ -220,6 +224,9 @@ public LocaleReportVettingResult[] getLocales() {
}
public static class LocaleReportVettingResult {
+ @Schema(description = "True if user is allowed to vote for this report.")
+ public final boolean canVote;
+
public String locale;
private Set reports = new HashSet();
@@ -237,6 +244,10 @@ void addVoters(Set s) {
public int getTotalVoters() {
return allUsers.size();
}
+
+ public LocaleReportVettingResult(CheckCLDR.StatusAction action, boolean canModify) {
+ canVote = canModify && action.canVote();
+ }
}
public static class ReportVettingResult {
@@ -346,7 +357,6 @@ public Response updateReport(
null /* Not path based */,
mySession.user);
- logger.info(() -> "ShowRowAction = " + showRowAction);
if (!showRowAction.canVote()) {
return Response.status(Status.FORBIDDEN).build();
}