implemented listing of list members
This commit is contained in:
@@ -12,9 +12,11 @@ import javax.servlet.http.HttpServlet;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.io.Serializable;
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static de.srsoftware.widerhall.Constants.*;
|
||||
import static de.srsoftware.widerhall.Util.t;
|
||||
@@ -25,8 +27,10 @@ public class Rest extends HttpServlet {
|
||||
private static final String LIST_DISABLE = "list/disable";
|
||||
private static final String LIST_ENABLE = "list/enable";
|
||||
private static final String LIST_HIDE = "list/hide";
|
||||
private static final String LIST_MEMBERS = "list/members";
|
||||
private static final String LIST_SHOW = "list/show";
|
||||
private static final String USER_LIST = "user/list";
|
||||
private static final String MEMBERS = "members";
|
||||
|
||||
@Override
|
||||
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
||||
@@ -98,6 +102,9 @@ public class Rest extends HttpServlet {
|
||||
case LIST_HIDE:
|
||||
json.putAll(hideList(listEmail,user,true));
|
||||
break;
|
||||
case LIST_MEMBERS:
|
||||
json.putAll(listMembers(listEmail,user));
|
||||
break;
|
||||
case LIST_SHOW:
|
||||
json.putAll(hideList(listEmail,user,false));
|
||||
break;
|
||||
@@ -117,6 +124,27 @@ public class Rest extends HttpServlet {
|
||||
}
|
||||
}
|
||||
|
||||
private Map<String, Object> listMembers(String listEmail, User user) {
|
||||
if (user.is(ADMIN) || ListMember.listsOwnedBy(user).contains(listEmail)) {
|
||||
try {
|
||||
var members = ListMember.of(listEmail)
|
||||
.entrySet()
|
||||
.stream()
|
||||
.map(entry -> Map.of(
|
||||
EMAIL,entry.getKey().email(),
|
||||
NAME,entry.getKey().name(),
|
||||
STATE,ListMember.stateText(entry.getValue())
|
||||
))
|
||||
.toList();
|
||||
return Map.of(MEMBERS,members);
|
||||
} catch (SQLException e) {
|
||||
LOG.error("Failed to load member list: ",e);
|
||||
return Map.of("error",t("Failed to load member list '{}'",listEmail));
|
||||
}
|
||||
}
|
||||
return Map.of("error",t("You are not allowed to list members '{}'",listEmail));
|
||||
}
|
||||
|
||||
private Map enableList(String listEmail, User user, boolean enable) {
|
||||
if (user.is(ADMIN) || ListMember.listsOwnedBy(user).contains(listEmail)){
|
||||
try {
|
||||
@@ -126,10 +154,8 @@ public class Rest extends HttpServlet {
|
||||
LOG.error("Failed to enable/disable mailing list: ",e);
|
||||
return Map.of("error",t("Failed to update list '{}'",listEmail));
|
||||
}
|
||||
|
||||
} else {
|
||||
return Map.of("error",t("You are not allowed to edit '{}'",listEmail));
|
||||
}
|
||||
return Map.of("error",t("You are not allowed to edit '{}'",listEmail));
|
||||
}
|
||||
|
||||
private Map<String, String> hideList(String listEmail, User user, boolean hide) {
|
||||
|
||||
@@ -33,6 +33,7 @@ public class Web extends HttpServlet {
|
||||
private static final String REGISTER = "register";
|
||||
private static final String SUBSCRIBE = "subscribe";
|
||||
private static final String RELOAD = "reload";
|
||||
private static final String INSPECT = "inspect";
|
||||
private static final String IMAP_HOST = "imap_host";
|
||||
private static final String IMAP_PORT = "imap_port";
|
||||
private static final String IMAP_USER = "imap_user";
|
||||
@@ -144,7 +145,6 @@ public class Web extends HttpServlet {
|
||||
User user = o instanceof User ? (User) o : null;
|
||||
var data = new HashMap<String,Object>();
|
||||
if (user != null) data.put(USER,user.safeMap());
|
||||
|
||||
var path = req.getPathInfo();
|
||||
path = (path == null || path.equals("/")) ? INDEX : path.substring(1);
|
||||
String notes = null;
|
||||
@@ -183,6 +183,8 @@ public class Web extends HttpServlet {
|
||||
}
|
||||
|
||||
if (user != null){
|
||||
var list = req.getParameter(LIST);
|
||||
if (list != null) data.put(LIST,req.getParameter(LIST));
|
||||
data.put(NOTES,notes);
|
||||
return loadTemplate(path,data,resp);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user