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
2 changes: 1 addition & 1 deletion tools/cldr-apps/js/src/esm/cldrGenerateVxml.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ function canGenerateVxml() {
function viewMounted(setData) {
callbackToSetData = setData;
const perm = cldrStatus.getPermissions();
canGenerate = Boolean(perm?.userIsAdmin);
canGenerate = Boolean(perm?.userCanGenerateVxml);
}

function start() {
Expand Down
4 changes: 3 additions & 1 deletion tools/cldr-apps/js/src/views/GenerateVxml.vue
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,9 @@ defineExpose({
</script>

<template>
<div v-if="!hasPermission">Please log in as Admin to use this feature.</div>
<div v-if="!hasPermission">
Please log in as a user with sufficient permissions.
Copy link
Member Author

@btangmu btangmu Feb 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this will practically never happen, since the menu doesn't present the option if the user lacks permission

it could happen if the user saved a bookmark for this page, and then forgot to log in

</div>
<div v-else>
<p v-if="status != STATUS.INIT">Generation Status: {{ status }}</p>
<p class="buttons">
Expand Down
26 changes: 15 additions & 11 deletions tools/cldr-apps/js/src/views/MainMenu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
<ul>
<template v-if="loggedIn">
<li v-if="isAdmin"><a href="#admin///">Admin Panel</a></li>
<li v-if="isAdmin"><a href="#generate_vxml///">Generate VXML</a></li>
<li v-if="canGenerateVxml">
<a href="#generate_vxml///">Generate VXML</a>
</li>
<!-- My Account only has border-top (section-header) if Admin Panel is shown -->
<li v-if="isAdmin" class="section-header">My Account</li>
<li v-else>My Account</li>
Expand Down Expand Up @@ -144,6 +146,7 @@ export default {
data() {
return {
accountLocked: false,
canGenerateVxml: false,
canImportOldVotes: false,
canListUsers: false,
canMonitorVetting: false,
Expand All @@ -168,20 +171,21 @@ export default {
methods: {
initializeData() {
const perm = cldrStatus.getPermissions();
this.accountLocked = perm && perm.userIsLocked;
this.canImportOldVotes = perm && perm.userCanImportOldVotes;
this.canListUsers = !!perm?.userCanListUsers;
this.canMonitorVetting = !!perm?.userCanUseVettingParticipation;
this.canMonitorForum = perm && perm.userCanMonitorForum;
this.accountLocked = Boolean(perm?.userIsLocked);
this.canGenerateVxml = Boolean(perm?.userCanGenerateVxml);
this.canImportOldVotes = Boolean(perm?.userCanImportOldVotes);
this.canListUsers = Boolean(perm?.userCanListUsers);
this.canMonitorVetting = Boolean(perm?.userCanUseVettingParticipation);
this.canMonitorForum = Boolean(perm?.userCanMonitorForum);
// this.canSeeStatistics will be false until there is a new implementation
this.canUseVettingSummary = perm && perm.userCanUseVettingSummary;
this.isAdmin = perm && perm.userIsAdmin;
this.canUseVettingSummary = Boolean(perm?.userCanUseVettingSummary);
this.isAdmin = Boolean(perm?.userIsAdmin);
this.canSeeUnofficialEmail =
cldrStatus.getIsUnofficial() && !!perm?.userIsManager;
this.isTC = perm && perm.userIsTC;
cldrStatus.getIsUnofficial() && Boolean(perm?.userIsManager);
this.isTC = Boolean(perm?.userIsTC);

const user = cldrStatus.getSurveyUser();
this.loggedIn = !!user;
this.loggedIn = Boolean(user);
this.userId = user ? user.id : 0;

this.org = cldrStatus.getOrganizationName();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -505,11 +505,11 @@ private boolean inAudience(String audience) {
if (Announcements.AUDIENCE_EVERYONE.equals(audience)) {
return true;
} else if (Announcements.AUDIENCE_VETTERS.equals(audience)) {
return userLevel.isVetter();
return userLevel.isVetterOrStronger();
} else if (Announcements.AUDIENCE_MANAGERS.equals(audience)) {
return userLevel.isManagerOrStronger();
} else if (Announcements.AUDIENCE_TC.equals(audience)) {
return userLevel.isTC();
return userLevel.isTCOrStronger();
} else {
logger.severe("Unrecognized audience: " + audience);
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ private boolean isValidSurveyToolVote(UserRegistry.User user, String xpath) {
if (ph.getSurveyToolStatus() == PathHeader.SurveyToolStatus.DEPRECATED) return false;
if (ph.getSurveyToolStatus() == PathHeader.SurveyToolStatus.HIDE
|| ph.getSurveyToolStatus() == PathHeader.SurveyToolStatus.READ_ONLY) {
if (!UserRegistry.userIsTC(user)) return false;
if (!UserRegistry.userIsTCOrStronger(user)) return false;
}

if (sm.getSupplementalDataInfo().getCoverageValue(xpath, locale.getBaseName())
Expand Down Expand Up @@ -918,7 +918,7 @@ private void makeSureInPathsForFile(String xpath, User user, String value)
throws InvalidXPathException {
if (!getPathsForFile().contains(xpath)) {
if (value == null
&& UserRegistry.userIsTC(user)
&& UserRegistry.userIsTCOrStronger(user)
&& XPathTable.getAlt(xpath) != null) {
synchronized (this) {
Set<String> set = new HashSet<>(pathsForFile);
Expand Down Expand Up @@ -1026,7 +1026,7 @@ private void saveVoteToDb(
}
ps.executeUpdate();

if (wasFlagged && UserRegistry.userIsTC(user)) {
if (wasFlagged && UserRegistry.userIsTCOrStronger(user)) {
clearFlag(conn, locale, xpathId);
didClearFlag = true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ private void processRequest(
} else if (what.equals(WHAT_FLAGGED)) {
SurveyJSONWrapper r = newJSONStatus(request, sm);
mySession = CookieSession.retrieve(sess);
new SurveyFlaggedItems(UserRegistry.userIsTC(mySession.user)).getJson(r);
new SurveyFlaggedItems(UserRegistry.userIsTCOrStronger(mySession.user)).getJson(r);
send(r, out);
} else if (what.equals(WHAT_STATS_BYDAYUSERLOC)) {
String votesAfterString = SurveyMain.getVotesAfterString();
Expand Down Expand Up @@ -610,7 +610,7 @@ private void processRequest(
*/
if (mySession.user != null
&& mySession.user.canImportOldVotes()
&& !UserRegistry.userIsTC(mySession.user)
&& !UserRegistry.userIsTCOrStronger(mySession.user)
&& !alreadyAutoImportedVotes(mySession.user.id, "ask")) {
r.put("canAutoImport", "true");
}
Expand Down Expand Up @@ -707,7 +707,7 @@ private void processRequest(
if (them != null
&& ((them.id == mySession.user.id)
|| // it's me
UserRegistry.userIsTC(mySession.user)
UserRegistry.userIsTCOrStronger(mySession.user)
|| (UserRegistry.userIsExactlyManager(
mySession.user)
&& (them.getOrganization()
Expand Down Expand Up @@ -877,7 +877,7 @@ private Integer getIntParameter(HttpServletRequest request, final String fieldNa
* @throws SurveyException
*/
public void assertIsTC(CookieSession mySession) throws SurveyException {
if (!UserRegistry.userIsTC(mySession.user)) {
if (!UserRegistry.userIsTCOrStronger(mySession.user)) {
throw new SurveyException(ErrorCode.E_NO_PERMISSION);
}
}
Expand Down Expand Up @@ -1568,7 +1568,7 @@ private long viewOldVotes(
// sort by pathheader
Arrays.sort(rows, Comparator.comparing(o -> ((PathHeader) o.get("pathHeader"))));

boolean useWinningVotes = UserRegistry.userIsTC(user);
boolean useWinningVotes = UserRegistry.userIsTCOrStronger(user);

/* Some variables are only used if oldvotes != null; otherwise leave them null. */
JSONArray contested = null; // contested = losing
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ private void gatherUsersInterestedInLocale(
&& !u.email.isEmpty()
&& !(UserRegistry.userIsLocked(u)
|| UserRegistry.userIsExactlyAnonymous(u))) {
if (UserRegistry.userIsVetter(u)) {
if (UserRegistry.userIsVetterOrStronger(u)) {
cc_emails.add(u.id);
} else {
bcc_emails.add(u.id);
Expand Down Expand Up @@ -301,7 +301,7 @@ private void gatherUsersInterestedInThread(
return; // don't notify the poster of their own action
}
UserRegistry.User rootPoster = sm.reg.getInfo(rootPosterId);
if (UserRegistry.userIsTC(rootPoster)) {
if (UserRegistry.userIsTCOrStronger(rootPoster)) {
cc_emails.add(rootPosterId);
}
}
Expand All @@ -316,7 +316,7 @@ private void gatherUsersInterestedInThread(
*/
private boolean userCanUsePostType(PostInfo postInfo) {
User user = postInfo.getUser();
boolean isTC = UserRegistry.userIsTC(user);
boolean isTC = UserRegistry.userIsTCOrStronger(user);
if (!isTC && SurveyMain.isPhaseReadonly()) {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public UserList(
org = null; // all
}
}
canShowLocked = UserRegistry.userIsExactlyManager(me) || UserRegistry.userIsTC(me);
canShowLocked = UserRegistry.userIsManagerOrStronger(me);
showLocked = canShowLocked && ctx.prefBool(PREF_SHOWLOCKED);
isValid = isJustMe || UserRegistry.userCanListUsers(me);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ public String toString() {
}

public String toHtml(User forUser) {
if (forUser == null || !userIsTC(forUser)) {
if (forUser == null || !userIsTCOrStronger(forUser)) {
return "(" + org + "#" + id + ")";
} else {
return "<a href='mailto:"
Expand All @@ -316,7 +316,7 @@ public String toHtml() {
}

public String toString(User forUser) {
if (forUser == null || !userIsTC(forUser)) {
if (forUser == null || !userIsTCOrStronger(forUser)) {
return "(" + org + "#" + id + ")";
} else {
return email
Expand Down Expand Up @@ -496,6 +496,10 @@ public String toJSONString() throws JSONException {
.toString();
}

public boolean canGenerateVxml() {
return userIsTCOrStronger(this);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is the only place the rule is determined

}

public boolean canImportOldVotes() {
return canImportOldVotes(CLDRConfig.getInstance().getPhase());
}
Expand All @@ -513,6 +517,7 @@ public int getVoteCount() {
/** This one is hidden because it uses JSONObject and can't be serialized */
JSONObject getPermissionsJson() throws JSONException {
return new JSONObject()
.put("userCanGenerateVxml", canGenerateVxml())
.put("userCanImportOldVotes", canImportOldVotes())
.put("userCanUseVettingSummary", userCanUseVettingSummary(this))
.put("userCanCreateSummarySnapshot", userCanCreateSummarySnapshot(this))
Expand All @@ -521,8 +526,10 @@ JSONObject getPermissionsJson() throws JSONException {
.put("userCanUseVettingParticipation", userCanUseVettingParticipation(this))
.put("userIsAdmin", userIsAdmin(this))
.put("userIsManager", getLevel().canManageSomeUsers())
.put("userIsTC", userIsTC(this))
.put("userIsVetter", userIsVetter(this) && !userIsTC(this))
.put("userIsTC", userIsTCOrStronger(this))
// Caution: userIsVetter really means user is Vetter or Manager, but not TC or
// Admin. It should be renamed to avoid confusion.
Comment on lines +530 to +531
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Caution: userIsVetter really means user is Vetter or Manager, but not TC or
// Admin. It should be renamed to avoid confusion.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the comment should stay until the json item is renamed or otherwise refactored

.put("userIsVetter", userIsVetterOrStronger(this) && !userIsTCOrStronger(this))
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tech debt; I only added a comment for now

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

didn't you already rename it? so the comment is out of date?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I renamed the method to userIsVetterOrStronger, but the json item is still userIsVetter

The json item needs a name like userIsVetterOrStrongerButNotTCOrStronger or userIsExactlyVetterOrManager -- such a change is beyond the scope of this ticket though

.put("userIsLocked", userIsLocked(this));
}

Expand Down Expand Up @@ -1758,8 +1765,8 @@ public static boolean userIsAdmin(User u) {
return (u != null) && u.getLevel().isAdmin();
}

public static boolean userIsTC(User u) {
return (u != null) && u.getLevel().isTC();
public static boolean userIsTCOrStronger(User u) {
return (u != null) && u.getLevel().isTCOrStronger();
}

public static boolean userIsExactlyManager(User u) {
Expand All @@ -1770,12 +1777,12 @@ public static boolean userIsManagerOrStronger(User u) {
return (u != null) && u.getLevel().isManagerOrStronger();
}

public static boolean userIsVetter(User u) {
return (u != null) && u.getLevel().isVetter();
public static boolean userIsVetterOrStronger(User u) {
return (u != null) && u.getLevel().isVetterOrStronger();
}

public static boolean userIsGuest(User u) {
return (u != null) && u.getLevel().isGuest();
public static boolean userIsGuestOrStronger(User u) {
return (u != null) && u.getLevel().isGuestOrStronger();
}

public static boolean userIsLocked(User u) {
Expand Down Expand Up @@ -1945,9 +1952,9 @@ public static boolean userCanAccessForum(User u, CLDRLocale locale) {
private static Object userCanAccessForumWhy(User u, CLDRLocale locale) {
if (u == null) return ModifyDenial.DENY_NULL_USER; // no user, no dice
if (!u.claSigned) return ModifyDenial.DENY_CLA_NOT_SIGNED;
if (!userIsGuest(u)) return ModifyDenial.DENY_NO_RIGHTS; // at least guest level
if (!userIsGuestOrStronger(u)) return ModifyDenial.DENY_NO_RIGHTS; // at least guest level
if (userIsAdmin(u)) return null; // Admin can modify all
if (userIsTC(u)) return null; // TC can modify all
if (userIsTCOrStronger(u)) return null; // TC can modify all
if (SpecialLocales.getType(locale) == SpecialLocales.Type.scratch) {
// All users can modify the sandbox
return null;
Expand Down Expand Up @@ -1986,7 +1993,7 @@ public static ModifyDenial countUserVoteForLocaleWhy(User u, CLDRLocale locale)
if (STFactory.isReadOnlyLocale(locale)) return ModifyDenial.DENY_LOCALE_READONLY;

// user must have guest level perms
if (!userIsGuest(u)) return ModifyDenial.DENY_NO_RIGHTS; // at least guest level
if (!userIsGuestOrStronger(u)) return ModifyDenial.DENY_NO_RIGHTS; // at least guest level

// locales that are aliases can't be modified.
if (sm.isLocaleAliased(locale) != null) {
Expand Down Expand Up @@ -2015,7 +2022,7 @@ public static ModifyDenial userCanModifyLocaleWhy(User u, CLDRLocale locale) {
// We add more restrictions

// Admin and TC users can always modify, even in closed state.
if (userIsAdmin(u) || userIsTC(u)) return null;
if (userIsTCOrStronger(u)) return null;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Department of Redundancy Department


// Otherwise, if closed, deny
if (SurveyMain.isPhaseVettingClosed(locale)) return ModifyDenial.DENY_PHASE_CLOSED;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1440,7 +1440,7 @@ public void setSession() {
logger.fine("Session Now=" + session + ", user=" + user);

// allow in administrator or TC.
if (!UserRegistry.userIsTC(user)) {
if (!UserRegistry.userIsTCOrStronger(user)) {
if ((user != null) && (session == null)) { // user trying to log in-
if (CookieSession.tooManyUsers()) {
System.err.println(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public Response getAnnouncements(
if (session == null) {
return Auth.noSessionResponse();
}
if (!UserRegistry.userIsGuest(session.user)) { // userIsGuest means "is guest or stronger"
if (!UserRegistry.userIsGuestOrStronger(session.user)) {
return Response.status(403, "Forbidden").build();
}
session.userDidAction();
Expand Down Expand Up @@ -223,7 +223,7 @@ public Response submitAnnouncement(
// Only TC or Admin can specify orgs other than ORGS_MINE
if (!UserRegistry.userIsManagerOrStronger(session.user)
|| (!ORGS_MINE.equals(request.orgs)
&& !UserRegistry.userIsTC(session.user))) { // userIsTC means TC or stronger
&& !UserRegistry.userIsTCOrStronger(session.user))) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One can only add a comment like this so many times before the need to rename the function becomes irresistible

return Response.status(403, "Forbidden").build();
}
final AnnouncementSubmissionResponse response = new AnnouncementSubmissionResponse();
Expand Down Expand Up @@ -331,7 +331,7 @@ public Response checkRead(
if (session == null) {
return Auth.noSessionResponse();
}
if (!UserRegistry.userIsGuest(session.user)) { // means guest or stronger
if (!UserRegistry.userIsGuestOrStronger(session.user)) {
return Response.status(403, "Forbidden").build();
}
final CheckReadResponse response = new CheckReadResponse();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public Response generateVxml(
if (cs == null) {
return Auth.noSessionResponse();
}
if (!UserRegistry.userIsAdmin(cs.user)) {
if (!UserRegistry.userIsTCOrStronger(cs.user)) {
return Response.status(Response.Status.FORBIDDEN).build();
}
if (SurveyMain.isBusted()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ private static Response handleGetRows(ArgsForGet args) {
try {
/** if true, hide emails. TODO: CLDR-16829 remove this parameter */
final boolean redacted =
((mySession.user == null) || (!mySession.user.getLevel().isGuest()));
((mySession.user == null) || (!mySession.user.getLevel().isGuestOrStronger()));
final RowResponse r = getRowsResponse(args, sm, locale, mySession, redacted);
return Response.ok(r).build();
} catch (Throwable t) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public Response putByHex(
if (session == null) {
return Auth.noSessionResponse();
}
if (!UserRegistry.userIsTC(session.user)) {
if (!UserRegistry.userIsTCOrStronger(session.user)) {
return Response.status(403, "Forbidden").build();
}
session.userDidAction();
Expand Down
Loading
Loading