|
|
@ -47,17 +47,17 @@ public class Rest extends HttpServlet { |
|
|
|
private static final String SUCCESS = "success"; |
|
|
|
private static final String SUCCESS = "success"; |
|
|
|
|
|
|
|
|
|
|
|
private Map addPermission(String userEmail, String permissions) { |
|
|
|
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 { |
|
|
|
try { |
|
|
|
int perm = Integer.parseInt(permissions); |
|
|
|
int perm = Integer.parseInt(permissions); |
|
|
|
var user = User.loadAll(List.of(userEmail)).stream().findAny().orElse(null); |
|
|
|
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); |
|
|
|
user.addPermission(perm); |
|
|
|
} catch (NumberFormatException nfe){ |
|
|
|
} catch (NumberFormatException nfe){ |
|
|
|
return Map.of(ERROR,"no valid permissions provided!"); |
|
|
|
return Map.of(ERROR,"no valid permissions provided!"); |
|
|
|
} catch (SQLException e) { |
|
|
|
} catch (SQLException e) { |
|
|
|
LOG.debug("Failed to load user for address {}",userEmail,e); |
|
|
|
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(ERROR,t("Failed to load user for address {}!",userEmail)); |
|
|
|
} |
|
|
|
} |
|
|
|
return Map.of(SUCCESS,"Updated user permissions"); |
|
|
|
return Map.of(SUCCESS,"Updated user permissions"); |
|
|
|
} |
|
|
|
} |
|
|
@ -141,13 +141,13 @@ public class Rest extends HttpServlet { |
|
|
|
try { |
|
|
|
try { |
|
|
|
int perm = Integer.parseInt(permissions); |
|
|
|
int perm = Integer.parseInt(permissions); |
|
|
|
var user = User.loadAll(List.of(userEmail)).stream().findAny().orElse(null); |
|
|
|
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); |
|
|
|
user.dropPermission(perm); |
|
|
|
} catch (NumberFormatException nfe){ |
|
|
|
} catch (NumberFormatException nfe){ |
|
|
|
return Map.of(ERROR,"no valid permissions provided!"); |
|
|
|
return Map.of(ERROR,"no valid permissions provided!"); |
|
|
|
} catch (SQLException e) { |
|
|
|
} catch (SQLException e) { |
|
|
|
LOG.debug("Failed to load user for address {}",userEmail,e); |
|
|
|
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(ERROR,t("Failed to load user for address {}!",userEmail)); |
|
|
|
} |
|
|
|
} |
|
|
|
return Map.of(SUCCESS,t("Updated user permissions")); |
|
|
|
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())); |
|
|
|
if (!list.mayBeAlteredBy(user)) Map.of(ERROR,t("You are not allowed to edit '{}'",list.email())); |
|
|
|
try { |
|
|
|
try { |
|
|
|
list.enable(enable); |
|
|
|
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) { |
|
|
|
} catch (SQLException e) { |
|
|
|
LOG.error("Failed to enable/disable mailing list:",e); |
|
|
|
LOG.error("Failed to enable/disable mailing list:",e); |
|
|
|
return Map.of(ERROR,t("Failed to update list '{}'",list.email())); |
|
|
|
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()); |
|
|
|
json.put("users", (user.hashPermission(User.PERMISSION_ADMIN) ? User.loadAll() : List.of(user)).stream().map(User::safeMap).toList()); |
|
|
|
} catch (SQLException e) { |
|
|
|
} catch (SQLException e) { |
|
|
|
LOG.debug("Failed to load user list:",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; |
|
|
|
break; |
|
|
|
case LIST_MODERATED: |
|
|
|
case LIST_MODERATED: |
|
|
@ -203,7 +203,7 @@ public class Rest extends HttpServlet { |
|
|
|
json.put("lists", MailingList.subscribable().stream().map(MailingList::minimalMap).toList()); |
|
|
|
json.put("lists", MailingList.subscribable().stream().map(MailingList::minimalMap).toList()); |
|
|
|
break; |
|
|
|
break; |
|
|
|
default: |
|
|
|
default: |
|
|
|
json.put(ERROR,"Not logged in!"); |
|
|
|
json.put(ERROR,t("Not logged in!")); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
try { |
|
|
|
try { |
|
|
@ -270,19 +270,19 @@ public class Rest extends HttpServlet { |
|
|
|
case USER_ADD_PERMISSION: |
|
|
|
case USER_ADD_PERMISSION: |
|
|
|
if (user.hashPermission(User.PERMISSION_ADMIN)){ |
|
|
|
if (user.hashPermission(User.PERMISSION_ADMIN)){ |
|
|
|
json.putAll(addPermission(userEmail,permissions)); |
|
|
|
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; |
|
|
|
break; |
|
|
|
case USER_DROP_PERMISSION: |
|
|
|
case USER_DROP_PERMISSION: |
|
|
|
if (user.hashPermission(User.PERMISSION_ADMIN)){ |
|
|
|
if (user.hashPermission(User.PERMISSION_ADMIN)){ |
|
|
|
json.putAll(dropPermission(userEmail,permissions)); |
|
|
|
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; |
|
|
|
break; |
|
|
|
default: |
|
|
|
default: |
|
|
|
json.put(ERROR,t("No handler for path '{}'!",path)); |
|
|
|
json.put(ERROR,t("No handler for path '{}'!",path)); |
|
|
|
break; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
json.put(ERROR,"Not logged in!"); |
|
|
|
json.put(ERROR,t("Not logged in!")); |
|
|
|
} |
|
|
|
} |
|
|
|
try { |
|
|
|
try { |
|
|
|
resp.setContentType("application/json"); |
|
|
|
resp.setContentType("application/json"); |
|
|
@ -298,7 +298,7 @@ public class Rest extends HttpServlet { |
|
|
|
if (!list.mayBeAlteredBy(user)) Map.of(ERROR,t("You are not allowed to edit '{}'",list.email())); |
|
|
|
if (!list.mayBeAlteredBy(user)) Map.of(ERROR,t("You are not allowed to edit '{}'",list.email())); |
|
|
|
try { |
|
|
|
try { |
|
|
|
list.hide(hide); |
|
|
|
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) { |
|
|
|
} 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())); |
|
|
|
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); |
|
|
|
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())); |
|
|
|
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); |
|
|
|
var error = moderator.addNewModerator(userEmail); |
|
|
|
|
|
|
|
|
|
|
@ -321,7 +321,7 @@ public class Rest extends HttpServlet { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private Map listDetail(MailingList list, User user) { |
|
|
|
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<>(); |
|
|
|
var map = new HashMap<>(); |
|
|
|
if (list.hasState(MailingList.STATE_FORWARD_FROM)) map.put(KEY_FORWARD_FROM,true); |
|
|
|
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); |
|
|
|
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) { |
|
|
|
private Map<String, Object> listMembers(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!")); |
|
|
|
if (!list.membersMayBeListedBy(user)) Map.of(ERROR,t("You are not allowed to list members of '{}'",list.email())); |
|
|
|
if (!list.membersMayBeListedBy(user)) Map.of(ERROR,t("You are not allowed to list members of '{}'!",list.email())); |
|
|
|
try { |
|
|
|
try { |
|
|
|
var members = list.members() |
|
|
|
var members = list.members() |
|
|
|
.sorted((m1,m2)->m1.user().name().compareTo(m2.user().name())) |
|
|
|
.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()); |
|
|
|
return Map.of(MEMBERS,members,LIST,list.minimalMap()); |
|
|
|
} catch (SQLException e) { |
|
|
|
} catch (SQLException e) { |
|
|
|
LOG.error("Failed to load member list: ",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) { |
|
|
|
private Map testList(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!")); |
|
|
|
if (!list.mayBeTestedBy(user)) Map.of(ERROR,t("You are not allowed to test '{}'",list.email())); |
|
|
|
if (!list.mayBeTestedBy(user)) Map.of(ERROR,t("You are not allowed to test '{}'!",list.email())); |
|
|
|
try { |
|
|
|
try { |
|
|
|
list.test(user); |
|
|
|
list.test(user); |
|
|
|
return Map.of(SUCCESS,t("Sent test email to {}",user.email())); |
|
|
|
return Map.of(SUCCESS,t("Sent test email to {}",user.email())); |
|
|
|
} catch (Exception e) { |
|
|
|
} catch (Exception e) { |
|
|
|
LOG.warn("Failed to send test email",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())); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|