Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CLDR-16838 Login bug; preliminary refactoring, clean-up; phase BETA not deprecated #3386

Merged
merged 1 commit into from
Nov 8, 2023
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
46 changes: 17 additions & 29 deletions tools/cldr-apps/src/main/java/org/unicode/cldr/web/AdminPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,7 @@

public class AdminPanel {
public void getJson(
SurveyJSONWrapper r,
HttpServletRequest request,
HttpServletResponse response,
SurveyMain sm)
SurveyJSONWrapper r, HttpServletRequest request, HttpServletResponse response)
throws JSONException, IOException {
/*
* Assume caller has already confirmed UserRegistry.userIsAdmin
Expand All @@ -43,7 +40,7 @@ public void getJson(
} else if (action.equals("settings_set")) {
setSettings(r, request);
} else if (action.equals("create_login")) {
createAndLogin(r, request, response, sm);
createAndLogin(r, request, response);
} else {
r.put("err", "Unknown action: " + action);
}
Expand Down Expand Up @@ -99,10 +96,10 @@ private void unlinkUser(SurveyJSONWrapper r, HttpServletRequest request) throws
private void showThreads(SurveyJSONWrapper r) throws JSONException {
JSONObject threads = new JSONObject();
ThreadMXBean threadBean = ManagementFactory.getThreadMXBean();
long deadlockedThreads[] = threadBean.findDeadlockedThreads();
long[] deadlockedThreads = threadBean.findDeadlockedThreads();
if (deadlockedThreads != null) {
JSONArray dead = new JSONArray();
ThreadInfo deadThreadInfo[] = threadBean.getThreadInfo(deadlockedThreads, true, true);
ThreadInfo[] deadThreadInfo = threadBean.getThreadInfo(deadlockedThreads, true, true);
for (ThreadInfo deadThread : deadThreadInfo) {
dead.put(
new JSONObject()
Expand Down Expand Up @@ -132,9 +129,9 @@ private void showExceptions(SurveyJSONWrapper r, HttpServletRequest request)
JSONObject exceptions = new JSONObject();
ChunkyReader cr = SurveyLog.getChunkyReader();
exceptions.put("lastTime", cr.getLastTime());
ChunkyReader.Entry e = null;
ChunkyReader.Entry e;
if (request.getParameter("before") != null) {
Long before = Long.parseLong(request.getParameter("before"));
long before = Long.parseLong(request.getParameter("before"));
e = cr.getEntryBelow(before);
} else {
e = cr.getLastEntry();
Expand Down Expand Up @@ -178,17 +175,11 @@ private void setSettings(SurveyJSONWrapper r, HttpServletRequest request) throws
* @param r
* @param request
* @param response
* @param sm
* <p>Earlier version was in createAndLogin.jsp
* @throws JSONException
*/
private void createAndLogin(
SurveyJSONWrapper r,
HttpServletRequest request,
HttpServletResponse response,
SurveyMain sm)
SurveyJSONWrapper r, HttpServletRequest request, HttpServletResponse response)
throws JSONException {
if (SurveyMain.isSetup == false) {
if (!SurveyMain.isSetup) {
r.put("isSetup", false);
return;
}
Expand All @@ -197,7 +188,7 @@ private void createAndLogin(
WebContext.clearCookie(request, response, SurveyMain.QUERY_PASSWORD);
WebContext.clearCookie(request, response, SurveyMain.COOKIE_SAVELOGIN);

String orgs[] = UserRegistry.getOrgList();
String[] orgs = UserRegistry.getOrgList();
String myorg = orgs[(int) Math.rint(Math.random() * (orgs.length - 1))];
JSONObject levels = new JSONObject();
for (final VoteResolver.Level l : VoteResolver.Level.values()) { // like 999
Expand All @@ -216,7 +207,7 @@ private void createAndLogin(
r.put("defaultLevel", UserRegistry.TC);
}

static final String allNames[] = {
static final String[] allNames = {
// http://en.wikipedia.org/wiki/List_of_most_popular_given_names (Greenland)
"Ivaana", "Pipaluk", "Nivi", "Paninnguaq", "Ivalu", "Naasunnguaq", "Julie", "Ane",
"Isabella", "Kimmernaq",
Expand All @@ -226,15 +217,13 @@ private void createAndLogin(

private String randomName() {
// generate random name
StringBuilder genname = new StringBuilder();

genname.append(choose(allNames));
genname.append(' ');
genname.append((char) ('A' + new Random().nextInt(26)));
genname.append('.');
genname.append(' ');
genname.append(
choose(
return choose(allNames)
+ ' '
+ (char) ('A' + new Random().nextInt(26))
+ '.'
+ ' '
+ choose(
"Vetter",
"Linguist",
"User",
Expand All @@ -244,8 +233,7 @@ private String randomName() {
"Person",
"Account",
"Login",
"CLDR"));
return genname.toString();
"CLDR");
}

private String choose(String... option) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ public void handleError(DataRow p, CheckStatus status, String choice_v) {
ctx.print("<tt class='codebox'>" + p.getDisplayName() + "</tt>: ");
ctx.print("&nbsp;&nbsp; Value: <b>" + choice_v + "</b> ");
String cls = SurveyMain.shortClassName(status.getCause());
ctx.printHelpLink("/" + cls, "<!-- help with -->" + cls, true);
ctx.printHelpLink("/" + cls, "<!-- help with -->" + cls);
if (status.getType().equals(CheckStatus.errorType)) {
ctx.print(ctx.iconHtml("stop", cls));
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ private void processRequest(
mySession.userDidAction();
SurveyJSONWrapper r = newJSONStatus(request, sm);
r.put("what", what);
new AdminPanel().getJson(r, request, response, sm);
new AdminPanel().getJson(r, request, response);
send(r, out);
} else {
sendError(
Expand Down
Loading
Loading