Browse Source

Merge branch 'main' into lang_de

lang_de
Stephan Richter 3 years ago
parent
commit
fc984007bc
  1. 27
      src/main/java/de/srsoftware/widerhall/web/Rest.java
  2. 2
      static/templates/js.st

27
src/main/java/de/srsoftware/widerhall/web/Rest.java

@ -14,6 +14,7 @@ import javax.servlet.http.HttpServlet; @@ -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 { @@ -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 { @@ -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 { @@ -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;

2
static/templates/js.st

@ -13,7 +13,7 @@ function disableList(listEmail){ @@ -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){

Loading…
Cancel
Save