new permissions:
* list members may be nominated as moderators by admin
* admin may allow moderators to nominate more moderators
* admin may set allowed senders to one of the following:
* owners and mods
* all subscribers
* everyone
* moderators are now able to remove members from list
This commit is contained in:
@@ -25,13 +25,16 @@ import static de.srsoftware.widerhall.data.MailingList.*;
|
||||
|
||||
public class Rest extends HttpServlet {
|
||||
private static final Logger LOG = LoggerFactory.getLogger(Rest.class);
|
||||
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_EDITABLE = "list/editable";
|
||||
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";
|
||||
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_MODERATED = "list/moderated";
|
||||
private static final String LIST_SHOW = "list/show";
|
||||
private static final String LIST_TEST = "list/test";
|
||||
private static final String LIST_SUBSCRIBABLE = "list/subscribable";
|
||||
@@ -119,6 +122,9 @@ public class Rest extends HttpServlet {
|
||||
if (user != null){
|
||||
json.put(USER,user.safeMap());
|
||||
switch (path) {
|
||||
case LIST_ARCHIVE:
|
||||
json.put("archive",archive(req));
|
||||
break;
|
||||
case USER_LIST:
|
||||
try {
|
||||
json.put("users", (user.hashPermission(User.PERMISSION_ADMIN) ? User.loadAll() : List.of(user)).stream().map(User::safeMap).toList());
|
||||
@@ -127,8 +133,8 @@ public class Rest extends HttpServlet {
|
||||
json.put(ERROR,"failed to load user list");
|
||||
}
|
||||
break;
|
||||
case LIST_EDITABLE:
|
||||
json.put("lists", MailingList.editableBy(user).stream().map(MailingList::safeMap).toList());
|
||||
case LIST_MODERATED:
|
||||
json.put("lists", MailingList.moderatedBy(user).stream().map(MailingList::safeMap).toList());
|
||||
break;
|
||||
case LIST_SUBSCRIBABLE:
|
||||
json.put("lists", MailingList.subscribable(user).stream().map(MailingList::minimalMap).toList());
|
||||
@@ -173,12 +179,21 @@ public class Rest extends HttpServlet {
|
||||
var userEmail = req.getParameter(EMAIL);
|
||||
var permissions = req.getParameter(PERMISSIONS);
|
||||
switch (path) {
|
||||
case LIST_ADD_MOD:
|
||||
json.putAll(listAddMod(list,userEmail,user));
|
||||
break;
|
||||
case LIST_DETAIL:
|
||||
json.putAll(listDetail(list,user));
|
||||
break;
|
||||
case LIST_DISABLE:
|
||||
json.putAll(enableList(list,user,false));
|
||||
break;
|
||||
case LIST_DROP_MEMBER:
|
||||
json.putAll(listDropMember(list,userEmail,user));
|
||||
break;
|
||||
case LIST_DROP_MOD:
|
||||
json.putAll(listDropMod(list,userEmail,user));
|
||||
break;
|
||||
case LIST_ENABLE:
|
||||
json.putAll(enableList(list,user,true));
|
||||
break;
|
||||
@@ -232,6 +247,21 @@ public class Rest extends HttpServlet {
|
||||
}
|
||||
}
|
||||
|
||||
private Map listAddMod(MailingList list, String userEmail, User user) {
|
||||
ListMember moderator = null;
|
||||
try {
|
||||
moderator = ListMember.load(list,user);
|
||||
} catch (SQLException e) {
|
||||
LOG.warn("Failed to load list member for {}/{}",user.email(),list.email(),e);
|
||||
return Map.of(ERROR,t("Failed to load list member for {}/{}",user.email(),list.email()));
|
||||
}
|
||||
if (moderator == null) return Map.of(ERROR,t("{} is not a member of {}",user.email(),list.email()));
|
||||
|
||||
var error = moderator.addNewModerator(userEmail);
|
||||
|
||||
return error == null ? Map.of(SUCCESS,t("{} is now a moderator of {}",userEmail,list.email())) : Map.of(ERROR,error);
|
||||
}
|
||||
|
||||
private Map listDetail(MailingList list, User user) {
|
||||
if (list == null) return Map.of(ERROR,"no list email provided!");
|
||||
var map = new HashMap<>();
|
||||
@@ -242,9 +272,40 @@ public class Rest extends HttpServlet {
|
||||
if (list.isOpenForGuests()) map.put(KEY_OPEN_FOR_GUESTS,true);
|
||||
if (list.isOpenForSubscribers()) map.put(KEY_OPEN_FOR_SUBSCRIBERS,true);
|
||||
if (list.hasState(MailingList.STATE_PUBLIC_ARCHIVE)) map.put(KEY_ARCHIVE,true);
|
||||
if (list.hasState(STATE_MODS_CAN_EDIT_MODS)) map.put(KEY_MODS_CAN_EDIT_MODS,true);
|
||||
return map;
|
||||
}
|
||||
|
||||
private Map listDropMember(MailingList list, String userEmail, User user) {
|
||||
ListMember moderator = null;
|
||||
try {
|
||||
moderator = ListMember.load(list,user);
|
||||
} catch (SQLException e) {
|
||||
LOG.warn("Failed to load list member for {}/{}",user.email(),list.email(),e);
|
||||
return Map.of(ERROR,t("Failed to load list member for {}/{}",user.email(),list.email()));
|
||||
}
|
||||
if (moderator == null) return Map.of(ERROR,t("{} is not a member of {}",user.email(),list.email()));
|
||||
|
||||
var error = moderator.dropMember(userEmail);
|
||||
|
||||
return error == null ? Map.of(SUCCESS,t("{} is now a moderator of {}",userEmail,list.email())) : Map.of(ERROR,error);
|
||||
}
|
||||
|
||||
private Map listDropMod(MailingList list, String userEmail, User user) {
|
||||
ListMember moderator = null;
|
||||
try {
|
||||
moderator = ListMember.load(list,user);
|
||||
} catch (SQLException e) {
|
||||
LOG.warn("Failed to load list member for {}/{}",user.email(),list.email(),e);
|
||||
return Map.of(ERROR,t("Failed to load list member for {}/{}",user.email(),list.email()));
|
||||
}
|
||||
if (moderator == null) return Map.of(ERROR,t("{} is not a member of {}",user.email(),list.email()));
|
||||
|
||||
var error = moderator.dropModerator(userEmail);
|
||||
|
||||
return error == null ? Map.of(SUCCESS,t("{} is now a moderator of {}",userEmail,list.email())) : Map.of(ERROR,error);
|
||||
}
|
||||
|
||||
private Map<String, Object> listMembers(MailingList list, User user) {
|
||||
if (list == null) return Map.of(ERROR,"no list email provided!");
|
||||
if (!list.membersMayBeListedBy(user)) Map.of(ERROR,t("You are not allowed to list members of '{}'",list.email()));
|
||||
@@ -253,7 +314,7 @@ public class Rest extends HttpServlet {
|
||||
.stream()
|
||||
.map(ListMember::safeMap)
|
||||
.toList();
|
||||
return Map.of(MEMBERS,members);
|
||||
return Map.of(MEMBERS,members,LIST,list.minimalMap());
|
||||
} catch (SQLException e) {
|
||||
LOG.error("Failed to load member list: ",e);
|
||||
return Map.of(ERROR,t("Failed to load member list '{}'",list.email()));
|
||||
|
||||
Reference in New Issue
Block a user