fixed texts

Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
This commit is contained in:
2024-03-25 18:30:05 +01:00
parent 9e363cc0e8
commit 49ecacc797
8 changed files with 72 additions and 73 deletions

View File

@@ -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()));
}
}
}