diff --git a/pom.xml b/pom.xml
index b33f10e..eb15dfe 100644
--- a/pom.xml
+++ b/pom.xml
@@ -6,7 +6,7 @@
org.example
Widerhall
- 0.2.19
+ 0.2.20
diff --git a/src/main/java/de/srsoftware/widerhall/web/Rest.java b/src/main/java/de/srsoftware/widerhall/web/Rest.java
index ad70b5b..b8df3f6 100644
--- a/src/main/java/de/srsoftware/widerhall/web/Rest.java
+++ b/src/main/java/de/srsoftware/widerhall/web/Rest.java
@@ -14,6 +14,7 @@ import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
+import java.lang.reflect.Member;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.List;
@@ -28,6 +29,7 @@ public class Rest extends HttpServlet {
private static final String LIST_ADD_MOD = "list/add_mod";
private static final String LIST_ARCHIVE = "list/archive";
private static final String LIST_DISABLE = "list/disable";
+ private static final String LIST_DROP = "list/drop";
private static final String LIST_DROP_MEMBER = "list/drop_member";
private static final String LIST_DROP_MOD = "list/drop_mod";
private static final String LIST_DETAIL = "list/detail";
@@ -79,6 +81,28 @@ public class Rest extends HttpServlet {
if (error != null) resp.sendError(400,error);
}
+ public Map dropList(MailingList list, User user){
+ boolean allowed = user.hashPermission(User.PERMISSION_ADMIN);
+ try {
+ if (!allowed) {
+ var member = ListMember.load(list, user);
+ if (member != null) allowed = member.isOwner();
+ }
+ } catch (SQLException e) {
+ LOG.warn("Was not able to load listmember for {}/{}",list.email(),user.email(),e);
+ }
+ if (!allowed) return Map.of(ERROR,"You are not allowed to remove this list!");
+ try {
+ list.hide(true).enable(false).openForGuests(false).openForSubscribers(false);
+ for (ListMember member : list.members()) { // drop all list members except for owner
+ if (!member.isOwner()) member.unsubscribe();
+ }
+ } catch (SQLException e) {
+ LOG.debug("Disabling and hiding of {} failed",list.email(),e);
+ }
+ return Map.of(SUCCESS,t("List {} disabled, closed for subscribers and hidden. Members have been removed.",list.email()));
+ }
+
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
String error = handlePost(req, resp);
@@ -188,6 +212,9 @@ public class Rest extends HttpServlet {
case LIST_DISABLE:
json.putAll(enableList(list,user,false));
break;
+ case LIST_DROP:
+ json.putAll(dropList(list,user));
+ break;
case LIST_DROP_MEMBER:
json.putAll(listDropMember(list,userEmail,user));
break;
diff --git a/static/templates/js.st b/static/templates/js.st
index 9589d6a..6965538 100644
--- a/static/templates/js.st
+++ b/static/templates/js.st
@@ -13,7 +13,7 @@ function disableList(listEmail){
}
function dropList(listEmail){
- console.log('dopList('+listEmail+')');
+ $.post('/api/list/drop',{list:listEmail},showListResult,'json');
}
function dropMember(userEmail,listEmail){