Skip to content

Commit

Permalink
CLDR-17776 st: disable report page if unavailable
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
srl295 committed Jul 2, 2024
1 parent c62a1d0 commit 737b43c
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 13 deletions.
8 changes: 4 additions & 4 deletions tools/cldr-apps/js/src/esm/cldrReport.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}

/**
Expand All @@ -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 };
}

/**
Expand Down
8 changes: 5 additions & 3 deletions tools/cldr-apps/js/src/views/ReportResponse.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
before continuing.
</p>

<a-radio-group v-model:value="state" @change="changed">
<a-radio-group v-model:value="state" :disabled="!canVote" @change="changed">
<a-radio :style="radioStyle" value="acceptable">
I have reviewed the items below, and they are all acceptable</a-radio
>
Expand Down Expand Up @@ -60,6 +60,7 @@ export default {
],
data() {
return {
canVote: false,
completed: false,
acceptable: false,
loaded: false,
Expand Down Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -195,7 +191,15 @@ public Response getReportLocaleStatus(
// set of all valid userids
final Set<Integer> 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<Integer, ReportAcceptability> votes = new TreeMap<>();
Expand All @@ -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<ReportVettingResult> reports = new HashSet<ReportVettingResult>();

Expand All @@ -237,6 +244,10 @@ void addVoters(Set<Integer> s) {
public int getTotalVoters() {
return allUsers.size();
}

public LocaleReportVettingResult(CheckCLDR.StatusAction action, boolean canModify) {
canVote = canModify && action.canVote();
}
}

public static class ReportVettingResult {
Expand Down Expand Up @@ -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();
}
Expand Down

0 comments on commit 737b43c

Please sign in to comment.