@@ -47,17 +47,17 @@ public class Rest extends HttpServlet {
|
||||
private static final String SUCCESS = "success";
|
||||
|
||||
private Map addPermission(String userEmail, String permissions) {
|
||||
if (userEmail == null || userEmail.isBlank()) return Map.of(ERROR,"missing user email address!");
|
||||
if (userEmail == null || userEmail.isBlank()) return Map.of(ERROR,t("missing user email address!"));
|
||||
try {
|
||||
int perm = Integer.parseInt(permissions);
|
||||
var user = User.loadAll(List.of(userEmail)).stream().findAny().orElse(null);
|
||||
if (user == null) return Map.of(ERROR,t("Failed to load user for address {}",userEmail));
|
||||
if (user == null) return Map.of(ERROR,t("Failed to load user for address {}!",userEmail));
|
||||
user.addPermission(perm);
|
||||
} catch (NumberFormatException nfe){
|
||||
return Map.of(ERROR,"no valid permissions provided!");
|
||||
} catch (SQLException e) {
|
||||
LOG.debug("Failed to load user for address {}",userEmail,e);
|
||||
return Map.of(ERROR,t("Failed to load user for address {}",userEmail));
|
||||
LOG.debug("Failed to load user for address {}!",userEmail,e);
|
||||
return Map.of(ERROR,t("Failed to load user for address {}!",userEmail));
|
||||
}
|
||||
return Map.of(SUCCESS,"Updated user permissions");
|
||||
}
|
||||
@@ -141,13 +141,13 @@ public class Rest extends HttpServlet {
|
||||
try {
|
||||
int perm = Integer.parseInt(permissions);
|
||||
var user = User.loadAll(List.of(userEmail)).stream().findAny().orElse(null);
|
||||
if (user == null) return Map.of(ERROR,t("Failed to load user for address {}",userEmail));
|
||||
if (user == null) return Map.of(ERROR,t("Failed to load user for address {}!",userEmail));
|
||||
user.dropPermission(perm);
|
||||
} catch (NumberFormatException nfe){
|
||||
return Map.of(ERROR,"no valid permissions provided!");
|
||||
} catch (SQLException e) {
|
||||
LOG.debug("Failed to load user for address {}",userEmail,e);
|
||||
return Map.of(ERROR,t("Failed to load user for address {}",userEmail));
|
||||
LOG.debug("Failed to load user for address {}!",userEmail,e);
|
||||
return Map.of(ERROR,t("Failed to load user for address {}!",userEmail));
|
||||
}
|
||||
return Map.of(SUCCESS,t("Updated user permissions"));
|
||||
}
|
||||
@@ -157,10 +157,10 @@ public class Rest extends HttpServlet {
|
||||
if (!list.mayBeAlteredBy(user)) Map.of(ERROR,t("You are not allowed to edit '{}'",list.email()));
|
||||
try {
|
||||
list.enable(enable);
|
||||
return Map.of(SUCCESS,t("Mailing list '{}' was {}!",list.email(),enable ? "enabled" : "disabled"));
|
||||
return Map.of(SUCCESS,t("Mailing list '{}' was {}!",list.email(),t(enable ? "enabled" : "disabled")));
|
||||
} catch (SQLException e) {
|
||||
LOG.error("Failed to enable/disable mailing list: ",e);
|
||||
return Map.of(ERROR,t("Failed to update list '{}'",list.email()));
|
||||
LOG.error("Failed to enable/disable mailing list:",e);
|
||||
return Map.of(ERROR,t("Failed to update list '{}'!",list.email()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -181,7 +181,7 @@ public class Rest extends HttpServlet {
|
||||
json.put("users", (user.hashPermission(User.PERMISSION_ADMIN) ? User.loadAll() : List.of(user)).stream().map(User::safeMap).toList());
|
||||
} catch (SQLException e) {
|
||||
LOG.debug("Failed to load user list:",e);
|
||||
json.put(ERROR,"failed to load user list");
|
||||
json.put(ERROR,t("failed to load user list"));
|
||||
}
|
||||
break;
|
||||
case LIST_MODERATED:
|
||||
@@ -203,7 +203,7 @@ public class Rest extends HttpServlet {
|
||||
json.put("lists", MailingList.subscribable().stream().map(MailingList::minimalMap).toList());
|
||||
break;
|
||||
default:
|
||||
json.put(ERROR,"Not logged in!");
|
||||
json.put(ERROR,t("Not logged in!"));
|
||||
}
|
||||
}
|
||||
try {
|
||||
@@ -270,19 +270,19 @@ public class Rest extends HttpServlet {
|
||||
case USER_ADD_PERMISSION:
|
||||
if (user.hashPermission(User.PERMISSION_ADMIN)){
|
||||
json.putAll(addPermission(userEmail,permissions));
|
||||
} else json.put(ERROR,"You are not allowed to alter user permissions!");
|
||||
} else json.put(ERROR,t("You are not allowed to alter user permissions!"));
|
||||
break;
|
||||
case USER_DROP_PERMISSION:
|
||||
if (user.hashPermission(User.PERMISSION_ADMIN)){
|
||||
json.putAll(dropPermission(userEmail,permissions));
|
||||
} else json.put(ERROR,"You are not allowed to alter user permissions!");
|
||||
} else json.put(ERROR,t("You are not allowed to alter user permissions!"));
|
||||
break;
|
||||
default:
|
||||
json.put(ERROR,t("No handler for path '{}'!",path));
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
json.put(ERROR,"Not logged in!");
|
||||
json.put(ERROR,t("Not logged in!"));
|
||||
}
|
||||
try {
|
||||
resp.setContentType("application/json");
|
||||
@@ -298,9 +298,9 @@ public class Rest extends HttpServlet {
|
||||
if (!list.mayBeAlteredBy(user)) Map.of(ERROR,t("You are not allowed to edit '{}'",list.email()));
|
||||
try {
|
||||
list.hide(hide);
|
||||
return Map.of(SUCCESS,t("Mailing list '{}' was {}!",list.email(),hide ? "hidden" : "made public"));
|
||||
return Map.of(SUCCESS,t("Mailing list '{}' was {}!",list.email(),t(hide ? "hidden" : "made public")));
|
||||
} catch (SQLException e) {
|
||||
LOG.error("Failed to (un)hide mailing list: ",e);
|
||||
LOG.error("Failed to (un)hide mailing list:",e);
|
||||
return Map.of(ERROR,t("Failed to update list '{}'",list.email()));
|
||||
}
|
||||
}
|
||||
@@ -313,7 +313,7 @@ public class Rest extends HttpServlet {
|
||||
LOG.warn("Failed to load list member for {}/{}",user.email(),list.email(),e);
|
||||
return Map.of(ERROR,t("Failed to load list member for {}/{}",user.email(),list.email()));
|
||||
}
|
||||
if (moderator == null) return Map.of(ERROR,t("{} is not a member of {}",user.email(),list.email()));
|
||||
if (moderator == null) return Map.of(ERROR,t("{} is not a member of {}!",user.email(),list.email()));
|
||||
|
||||
var error = moderator.addNewModerator(userEmail);
|
||||
|
||||
@@ -321,7 +321,7 @@ public class Rest extends HttpServlet {
|
||||
}
|
||||
|
||||
private Map listDetail(MailingList list, User user) {
|
||||
if (list == null) return Map.of(ERROR,"no list email provided!");
|
||||
if (list == null) return Map.of(ERROR,t("no list email provided!"));
|
||||
var map = new HashMap<>();
|
||||
if (list.hasState(MailingList.STATE_FORWARD_FROM)) map.put(KEY_FORWARD_FROM,true);
|
||||
if (list.hasState(MailingList.STATE_FORWARD_ATTACHED)) map.put(KEY_FORWARD_ATTACHED,true);
|
||||
@@ -366,8 +366,8 @@ public class Rest extends HttpServlet {
|
||||
}
|
||||
|
||||
private Map<String, Object> listMembers(MailingList list, User user) {
|
||||
if (list == null) return Map.of(ERROR,"no list email provided!");
|
||||
if (!list.membersMayBeListedBy(user)) Map.of(ERROR,t("You are not allowed to list members of '{}'",list.email()));
|
||||
if (list == null) return Map.of(ERROR,t("no list email provided!"));
|
||||
if (!list.membersMayBeListedBy(user)) Map.of(ERROR,t("You are not allowed to list members of '{}'!",list.email()));
|
||||
try {
|
||||
var members = list.members()
|
||||
.sorted((m1,m2)->m1.user().name().compareTo(m2.user().name()))
|
||||
@@ -376,19 +376,19 @@ public class Rest extends HttpServlet {
|
||||
return Map.of(MEMBERS,members,LIST,list.minimalMap());
|
||||
} catch (SQLException e) {
|
||||
LOG.error("Failed to load member list: ",e);
|
||||
return Map.of(ERROR,t("Failed to load member list '{}'",list.email()));
|
||||
return Map.of(ERROR,t("Failed to load member list '{}'!",list.email()));
|
||||
}
|
||||
}
|
||||
|
||||
private Map testList(MailingList list, User user) {
|
||||
if (list == null) return Map.of(ERROR,"no list email provided!");
|
||||
if (!list.mayBeTestedBy(user)) Map.of(ERROR,t("You are not allowed to test '{}'",list.email()));
|
||||
if (list == null) return Map.of(ERROR,t("no list email provided!"));
|
||||
if (!list.mayBeTestedBy(user)) Map.of(ERROR,t("You are not allowed to test '{}'!",list.email()));
|
||||
try {
|
||||
list.test(user);
|
||||
return Map.of(SUCCESS,t("Sent test email to {}",user.email()));
|
||||
} catch (Exception e) {
|
||||
LOG.warn("Failed to send test email",e);
|
||||
return Map.of(ERROR,t("Failed to send test email to {}",user.email()));
|
||||
return Map.of(ERROR,t("Failed to send test email to {}!",user.email()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ public abstract class TemplateServlet extends HttpServlet {
|
||||
resp.getWriter().println(template.render());
|
||||
return null;
|
||||
} catch (IOException e) {
|
||||
return t("Failed to load template '{}'",path);
|
||||
return t("Failed to load template '{}'!",path);
|
||||
}
|
||||
}
|
||||
return t("No template for path '{}'!",path);
|
||||
|
||||
@@ -160,7 +160,7 @@ public class Web extends TemplateServlet {
|
||||
|
||||
return loadTemplate(INDEX,Map.of(USER,listMember.user().safeMap(),NOTES,"Confirmed list subscription!"),resp);
|
||||
}
|
||||
return t("Unknown user or token");
|
||||
return t("Unknown user or token!");
|
||||
} catch (Exception e) {
|
||||
LOG.debug("Failed to confirm list membership:",e);
|
||||
return t("Confirmation of list membership failed!");
|
||||
@@ -260,7 +260,7 @@ public class Web extends TemplateServlet {
|
||||
return loadTemplate(ADMIN,data,resp);
|
||||
} catch (SQLException e) {
|
||||
LOG.warn("Editing list {} by {} failed",list.email(),user.email(),e);
|
||||
return t("Editing list {} by {} failed",list.email(),user.email());
|
||||
return t("Editing list {} by {} failed!",list.email(),user.email());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -294,7 +294,7 @@ public class Web extends TemplateServlet {
|
||||
return post(req,resp);
|
||||
case RELOAD:
|
||||
loadTemplates();
|
||||
data.put(NOTES,t("Templates have been reloaded"));
|
||||
data.put(NOTES,t("Templates have been reloaded!"));
|
||||
path = INDEX;
|
||||
case CSS:
|
||||
case INDEX:
|
||||
@@ -402,7 +402,7 @@ public class Web extends TemplateServlet {
|
||||
|
||||
if (!error && !list.mayBeAlteredBy(user)) {
|
||||
error = true;
|
||||
data.put(ERROR,t("You are not alter settings of this list!"));
|
||||
data.put(ERROR,t("You are not allowed to alter settings of this list!"));
|
||||
}
|
||||
|
||||
if (!error){
|
||||
@@ -463,9 +463,9 @@ public class Web extends TemplateServlet {
|
||||
if (email == null || email.isBlank() ||
|
||||
name == null || name.isBlank() ||
|
||||
pass == null || pass.isBlank() ||
|
||||
pass_repeat == null || pass_repeat.isBlank()) return loadTemplate(REGISTER,Map.of(ERROR,"Fill all fields, please!",NAME,name,EMAIL,email),resp);
|
||||
if (!pass.equals(pass_repeat)) return loadTemplate(REGISTER,Map.of(ERROR,"Passwords do not match!",NAME,name,EMAIL,email),resp);
|
||||
if (Util.simplePassword(pass)) return loadTemplate(REGISTER,Map.of(ERROR,"Password to short or to simple!",NAME,name,EMAIL,email),resp);
|
||||
pass_repeat == null || pass_repeat.isBlank()) return loadTemplate(REGISTER,Map.of(ERROR,t"Fill all fields, please!"),NAME,name,EMAIL,email),resp);
|
||||
if (!pass.equals(pass_repeat)) return loadTemplate(REGISTER,Map.of(ERROR,t("Passwords do not match!"),NAME,name,EMAIL,email),resp);
|
||||
if (Util.simplePassword(pass)) return loadTemplate(REGISTER,Map.of(ERROR,t("Password to short or to simple!"),NAME,name,EMAIL,email),resp);
|
||||
|
||||
var firstUser = false;
|
||||
try {
|
||||
@@ -565,12 +565,12 @@ public class Web extends TemplateServlet {
|
||||
data.put(EMAIL,email);
|
||||
if (user != null) data.put(USER,user.safeMap());
|
||||
if (list == null){
|
||||
data.put(ERROR,"No list provided by form data!");
|
||||
data.put(ERROR,t("No list provided by form data!"));
|
||||
return loadTemplate(UNSUBSCRIBE,data,resp);
|
||||
} else data.put(LIST,list.email());
|
||||
if (user == null) {
|
||||
if (email == null || email.isBlank()) {
|
||||
data.put(ERROR, "Email is required for list un-subscription!");
|
||||
data.put(ERROR, t("Email is required for list un-subscription!"));
|
||||
return loadTemplate(UNSUBSCRIBE, data, resp);
|
||||
}
|
||||
var pass = req.getParameter(PASSWORD);
|
||||
@@ -581,7 +581,7 @@ public class Web extends TemplateServlet {
|
||||
req.getSession().setAttribute(USER,user);
|
||||
data.put(USER,user.safeMap());
|
||||
} catch (InvalidKeyException | SQLException e) {
|
||||
data.put(ERROR,"Invalid email/password combination!");
|
||||
data.put(ERROR,t("Invalid email/password combination!"));
|
||||
return loadTemplate(UNSUBSCRIBE,data,resp);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user