implemented dropping of mailing lists
This commit is contained in:
2
pom.xml
2
pom.xml
@@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
<groupId>org.example</groupId>
|
<groupId>org.example</groupId>
|
||||||
<artifactId>Widerhall</artifactId>
|
<artifactId>Widerhall</artifactId>
|
||||||
<version>0.2.19</version>
|
<version>0.2.20</version>
|
||||||
<build>
|
<build>
|
||||||
<plugins>
|
<plugins>
|
||||||
<plugin>
|
<plugin>
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import javax.servlet.http.HttpServlet;
|
|||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.lang.reflect.Member;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
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_ADD_MOD = "list/add_mod";
|
||||||
private static final String LIST_ARCHIVE = "list/archive";
|
private static final String LIST_ARCHIVE = "list/archive";
|
||||||
private static final String LIST_DISABLE = "list/disable";
|
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_MEMBER = "list/drop_member";
|
||||||
private static final String LIST_DROP_MOD = "list/drop_mod";
|
private static final String LIST_DROP_MOD = "list/drop_mod";
|
||||||
private static final String LIST_DETAIL = "list/detail";
|
private static final String LIST_DETAIL = "list/detail";
|
||||||
@@ -79,6 +81,28 @@ public class Rest extends HttpServlet {
|
|||||||
if (error != null) resp.sendError(400,error);
|
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
|
@Override
|
||||||
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
||||||
String error = handlePost(req, resp);
|
String error = handlePost(req, resp);
|
||||||
@@ -188,6 +212,9 @@ public class Rest extends HttpServlet {
|
|||||||
case LIST_DISABLE:
|
case LIST_DISABLE:
|
||||||
json.putAll(enableList(list,user,false));
|
json.putAll(enableList(list,user,false));
|
||||||
break;
|
break;
|
||||||
|
case LIST_DROP:
|
||||||
|
json.putAll(dropList(list,user));
|
||||||
|
break;
|
||||||
case LIST_DROP_MEMBER:
|
case LIST_DROP_MEMBER:
|
||||||
json.putAll(listDropMember(list,userEmail,user));
|
json.putAll(listDropMember(list,userEmail,user));
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ function disableList(listEmail){
|
|||||||
}
|
}
|
||||||
|
|
||||||
function dropList(listEmail){
|
function dropList(listEmail){
|
||||||
console.log('dopList('+listEmail+')');
|
$.post('/api/list/drop',{list:listEmail},showListResult,'json');
|
||||||
}
|
}
|
||||||
|
|
||||||
function dropMember(userEmail,listEmail){
|
function dropMember(userEmail,listEmail){
|
||||||
|
|||||||
Reference in New Issue
Block a user