|
|
|
@ -39,6 +39,7 @@ public class Rest extends HttpServlet {
@@ -39,6 +39,7 @@ public class Rest extends HttpServlet {
|
|
|
|
|
private static final String LIST_SHOW = "list/show"; |
|
|
|
|
private static final String LIST_TEST = "list/test"; |
|
|
|
|
private static final String LIST_SUBSCRIBABLE = "list/subscribable"; |
|
|
|
|
private static final String MAIL_DROP = "mail/drop"; |
|
|
|
|
private static final String USER_ADD_PERMISSION = "user/addpermission"; |
|
|
|
|
private static final String USER_DROP_PERMISSION = "user/droppermission"; |
|
|
|
|
private static final String USER_LIST = "user/list"; |
|
|
|
@ -61,15 +62,16 @@ public class Rest extends HttpServlet {
@@ -61,15 +62,16 @@ public class Rest extends HttpServlet {
|
|
|
|
|
return Map.of(SUCCESS,"Updated user permissions"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private Map<String, Object> archive(HttpServletRequest req) { |
|
|
|
|
private Map<String, Object> archive(HttpServletRequest req, User user) { |
|
|
|
|
var list = Util.getMailingList(req); |
|
|
|
|
if (list != null){ |
|
|
|
|
boolean userIsMod = list.mayBeAlteredBy(user); |
|
|
|
|
try { |
|
|
|
|
var month = req.getParameter(MONTH); |
|
|
|
|
if (month == null || month.isBlank()) { |
|
|
|
|
return Map.of(LIST,list.email(),"summary",Post.summarize(list)); |
|
|
|
|
return Map.of(LIST,list.email(),MODERATOR,userIsMod,"summary",Post.summarize(list)); |
|
|
|
|
} else { |
|
|
|
|
return Map.of(LIST,list.email(),"posts",Post.find(list,month).stream().map(Post::safeMap).toList()); |
|
|
|
|
return Map.of(LIST,list.email(),MODERATOR,userIsMod,"posts",Post.find(list,month).stream().map(Post::safeMap).toList()); |
|
|
|
|
} |
|
|
|
|
} catch (SQLException e) { |
|
|
|
|
e.printStackTrace(); |
|
|
|
@ -118,6 +120,21 @@ public class Rest extends HttpServlet {
@@ -118,6 +120,21 @@ public class Rest extends HttpServlet {
|
|
|
|
|
if (error != null) resp.sendError(400,error); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private Map dropMail(String messageId,User user){ |
|
|
|
|
try { |
|
|
|
|
var message = Post.load(messageId); |
|
|
|
|
if (message == null) return Map.of(ERROR,t("Cannot remove: unknown message id")); |
|
|
|
|
var allowed = message.list().mayBeAlteredBy(user); |
|
|
|
|
if (allowed){ |
|
|
|
|
message.remove(); |
|
|
|
|
return Map.of(SUCCESS,t("Message deleted")); |
|
|
|
|
} |
|
|
|
|
return Map.of(ERROR,t("You are not allowed to remove messages from this list!")); |
|
|
|
|
} catch (SQLException e) { |
|
|
|
|
throw new RuntimeException(e); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private Map dropPermission(String userEmail, String permissions) { |
|
|
|
|
if (userEmail == null || userEmail.isBlank()) return Map.of(ERROR,"missing user email address!"); |
|
|
|
|
try { |
|
|
|
@ -131,7 +148,7 @@ public class Rest extends HttpServlet {
@@ -131,7 +148,7 @@ public class Rest extends HttpServlet {
|
|
|
|
|
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"); |
|
|
|
|
return Map.of(SUCCESS,t("Updated user permissions")); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private Map enableList(MailingList list, User user, boolean enable) { |
|
|
|
@ -156,7 +173,7 @@ public class Rest extends HttpServlet {
@@ -156,7 +173,7 @@ public class Rest extends HttpServlet {
|
|
|
|
|
json.put(USER,user.safeMap()); |
|
|
|
|
switch (path) { |
|
|
|
|
case LIST_ARCHIVE: |
|
|
|
|
json.put("archive",archive(req)); |
|
|
|
|
json.put("archive",archive(req,user)); |
|
|
|
|
break; |
|
|
|
|
case USER_LIST: |
|
|
|
|
try { |
|
|
|
@ -179,7 +196,7 @@ public class Rest extends HttpServlet {
@@ -179,7 +196,7 @@ public class Rest extends HttpServlet {
|
|
|
|
|
} else { |
|
|
|
|
switch (path) { |
|
|
|
|
case LIST_ARCHIVE: |
|
|
|
|
json.put("archive",archive(req)); |
|
|
|
|
json.put("archive",archive(req, user)); |
|
|
|
|
break; |
|
|
|
|
case LIST_SUBSCRIBABLE: |
|
|
|
|
json.put("lists", MailingList.subscribable().stream().map(MailingList::minimalMap).toList()); |
|
|
|
@ -245,6 +262,10 @@ public class Rest extends HttpServlet {
@@ -245,6 +262,10 @@ public class Rest extends HttpServlet {
|
|
|
|
|
case LIST_TEST: |
|
|
|
|
json.putAll(testList(list,user)); |
|
|
|
|
break; |
|
|
|
|
case MAIL_DROP: |
|
|
|
|
var messageId = req.getParameter(MESSAGE_ID); |
|
|
|
|
json.putAll(dropMail(messageId,user)); |
|
|
|
|
break; |
|
|
|
|
case USER_ADD_PERMISSION: |
|
|
|
|
if (user.hashPermission(User.PERMISSION_ADMIN)){ |
|
|
|
|
json.putAll(addPermission(userEmail,permissions)); |
|
|
|
|