Merge branch 'main' into lang_de
This commit is contained in:
@@ -3,6 +3,7 @@ package de.srsoftware.widerhall.web;
|
||||
import de.srsoftware.widerhall.Util;
|
||||
import de.srsoftware.widerhall.data.ListMember;
|
||||
import de.srsoftware.widerhall.data.MailingList;
|
||||
import de.srsoftware.widerhall.data.Post;
|
||||
import de.srsoftware.widerhall.data.User;
|
||||
import org.json.simple.JSONObject;
|
||||
import org.slf4j.Logger;
|
||||
@@ -27,6 +28,7 @@ import static de.srsoftware.widerhall.Util.t;
|
||||
|
||||
public class Rest extends HttpServlet {
|
||||
private static final Logger LOG = LoggerFactory.getLogger(Rest.class);
|
||||
private static final String LIST_ARCHIVE = "list/archive";
|
||||
private static final String LIST_DISABLE = "list/disable";
|
||||
private static final String LIST_EDITABLE = "list/editable";
|
||||
private static final String LIST_DETAIL = "list/detail";
|
||||
@@ -127,6 +129,9 @@ public class Rest extends HttpServlet {
|
||||
}
|
||||
} else {
|
||||
switch (path) {
|
||||
case LIST_ARCHIVE:
|
||||
json.put("archive",archive(req));
|
||||
break;
|
||||
case LIST_SUBSCRIBABLE:
|
||||
json.put("lists", MailingList.subscribable().stream().map(MailingList::minimalMap).toList());
|
||||
break;
|
||||
@@ -143,6 +148,19 @@ public class Rest extends HttpServlet {
|
||||
}
|
||||
}
|
||||
|
||||
private Map<Long, Object> archive(HttpServletRequest req) {
|
||||
var list = Util.getMailingList(req);
|
||||
if (list != null){
|
||||
try {
|
||||
return Post.find(list).stream().collect(Collectors.toMap(Post::timestamp,Post::safeMap));
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
LOG.debug("list: {}",list.email());
|
||||
return Map.of();
|
||||
}
|
||||
|
||||
public String handlePost(HttpServletRequest req, HttpServletResponse resp){
|
||||
|
||||
var user = Util.getUser(req);
|
||||
@@ -220,6 +238,10 @@ public class Rest extends HttpServlet {
|
||||
var map = new HashMap<>();
|
||||
if (list.hasState(MailingList.STATE_FORWARD_FROM)) map.put("forward_from",true);
|
||||
if (list.hasState(MailingList.STATE_FORWARD_ATTACHED)) map.put("forward_attached",true);
|
||||
if (list.hasState(MailingList.STATE_HIDE_RECEIVERS)) map.put("hide_receivers",true);
|
||||
if (list.hasState(MailingList.STATE_REPLY_TO_LIST)) map.put("reply_to_list",true);
|
||||
if (list.hasState(MailingList.STATE_OPEN)) map.put("open",true);
|
||||
if (list.hasState(MailingList.STATE_PUBLIC_ARCHIVE)) map.put("archive",true);
|
||||
return map;
|
||||
}
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ import javax.servlet.http.HttpServlet;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -40,6 +41,7 @@ public abstract class TemplateServlet extends HttpServlet {
|
||||
var template = templates.getInstanceOf(path);
|
||||
if (template != null){
|
||||
try {
|
||||
resp.setCharacterEncoding("UTF-8");
|
||||
template.add("data",data);
|
||||
resp.getWriter().println(template.render());
|
||||
return null;
|
||||
|
||||
@@ -3,6 +3,7 @@ package de.srsoftware.widerhall.web;
|
||||
import de.srsoftware.widerhall.Util;
|
||||
import de.srsoftware.widerhall.data.ListMember;
|
||||
import de.srsoftware.widerhall.data.MailingList;
|
||||
import de.srsoftware.widerhall.data.Post;
|
||||
import de.srsoftware.widerhall.data.User;
|
||||
import org.json.simple.JSONObject;
|
||||
import org.slf4j.Logger;
|
||||
@@ -12,6 +13,7 @@ import javax.mail.MessagingException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.security.InvalidKeyException;
|
||||
import java.sql.SQLException;
|
||||
import java.util.HashMap;
|
||||
@@ -26,9 +28,11 @@ public class Web extends TemplateServlet {
|
||||
private static final String CONFIRM = "confirm";
|
||||
private static final Logger LOG = LoggerFactory.getLogger(Web.class);
|
||||
private static final String ADMIN = "admin";
|
||||
private static final String ARCHIVE = "archive";
|
||||
private static final String INSPECT = "inspect";
|
||||
private static final String LOGIN = "login";
|
||||
private static final String LOGOUT = "logout";
|
||||
private static final String POST = "post";
|
||||
private static final String REGISTER = "register";
|
||||
private static final String RELOAD = "reload";
|
||||
private static final String SUBSCRIBE = "subscribe";
|
||||
@@ -130,6 +134,12 @@ public class Web extends TemplateServlet {
|
||||
}
|
||||
}
|
||||
|
||||
private String archive(HttpServletRequest req, HttpServletResponse resp) {
|
||||
var domain = req.getParameter(DOMAIN);
|
||||
var prefix = req.getParameter(PREFIX);
|
||||
return loadTemplate(ARCHIVE,Map.of(DOMAIN,domain,PREFIX,prefix),resp);
|
||||
}
|
||||
|
||||
private String confirm(HttpServletRequest req, HttpServletResponse resp) {
|
||||
try {
|
||||
var token = req.getParameter(TOKEN);
|
||||
@@ -181,8 +191,12 @@ public class Web extends TemplateServlet {
|
||||
var list = MailingList.load(listEmail);
|
||||
if (list != null) data.put(LIST,list.minimalMap());
|
||||
switch (path){
|
||||
case ARCHIVE:
|
||||
return archive(req,resp);
|
||||
case CONFIRM:
|
||||
return confirm(req,resp);
|
||||
case POST:
|
||||
return post(req,resp);
|
||||
case RELOAD:
|
||||
loadTemplates();
|
||||
data.put(NOTES,t("Vorlagen wurden neu geladen"));
|
||||
@@ -223,8 +237,6 @@ public class Web extends TemplateServlet {
|
||||
return redirectTo(LOGIN,resp);
|
||||
}
|
||||
|
||||
|
||||
|
||||
private String handleLogin(HttpServletRequest req, HttpServletResponse resp) {
|
||||
var email = req.getParameter("email");
|
||||
var pass = req.getParameter("pass");
|
||||
@@ -288,21 +300,38 @@ public class Web extends TemplateServlet {
|
||||
}
|
||||
|
||||
if (!error){
|
||||
var dummy = req.getParameterMap();
|
||||
try {
|
||||
list.forwardFrom(Util.getCheckbox(req, "forward_from"));
|
||||
list.forwardAttached(Util.getCheckbox(req, "forward_attached"));
|
||||
list.forwardFrom(Util.getCheckbox(req, "forward_from"))
|
||||
.forwardAttached(Util.getCheckbox(req, "forward_attached"))
|
||||
.hideReceivers(Util.getCheckbox(req, "hide_receivers"))
|
||||
.replyToList(Util.getCheckbox(req, "reply_to_list"))
|
||||
.open(Util.getCheckbox(req,"open"))
|
||||
.archive(Util.getCheckbox(req,"archive"));
|
||||
data.put(NOTES,t("Mailing-Liste aktualisiert!"));
|
||||
} catch (SQLException e){
|
||||
LOG.warn("Aktualisierung der Mailing-Liste fehlgeschlagen:",e);
|
||||
data.put(ERROR,t("Aktualisierung der Mailing-Liste fehlgeschlagen!"));
|
||||
}
|
||||
LOG.debug("params: {}",dummy);
|
||||
}
|
||||
|
||||
return loadTemplate(INSPECT,data,resp);
|
||||
}
|
||||
|
||||
private String post(HttpServletRequest req, HttpServletResponse resp) {
|
||||
var id = req.getParameter(ID);
|
||||
if (id == null) return t("Could not find email with id!");
|
||||
try {
|
||||
var post = Post.load(id);
|
||||
var map = new HashMap<String,Object>();
|
||||
map.putAll(post.safeMap());
|
||||
String content = Files.readString(post.file().toPath());
|
||||
map.put("text",Util.dropEmail(content));
|
||||
return loadTemplate("post",map,resp);
|
||||
} catch (SQLException | IOException e) {
|
||||
LOG.debug("Failed to load post from file!",e);
|
||||
return t("Failed to load post from file!");
|
||||
}
|
||||
}
|
||||
|
||||
private String redirectTo(String page, HttpServletResponse resp) {
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user