|
|
|
@ -12,9 +12,11 @@ import javax.servlet.http.HttpServlet;
@@ -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 {
@@ -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 {
@@ -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 {
@@ -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 {
@@ -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) { |
|
|
|
|