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:
2022-04-22 12:35:16 +02:00
parent 7bf492e469
commit b9b3196ae6
9 changed files with 305 additions and 36 deletions

View File

@@ -35,6 +35,7 @@ public class MailingList implements MessageHandler {
public static final String KEY_OPEN_FOR_GUESTS = "open_for_guests";
public static final String KEY_OPEN_FOR_SUBSCRIBERS = "open_for_subscribers";
public static final String KEY_ARCHIVE = "archive";
public static final String KEY_MODS_CAN_EDIT_MODS = "edit_mods";
private static final Logger LOG = LoggerFactory.getLogger(MailingList.class);
private static final String IMAP_HOST = "imap_host";
private static final String IMAP_PORT = "imap_port";
@@ -55,7 +56,7 @@ public class MailingList implements MessageHandler {
public static final int STATE_OPEN_FOR_GUESTS = 64; // allow anyone to send via this list?
public static final int STATE_PUBLIC_ARCHIVE = 128; // save received messages in archive?
public static final int STATE_OPEN_FOR_SUBSCRIBERS = 256; // allow mods to send via this list?
public static final int STATE_MODS_CAN_CREATE_MODS = 512; // allow mods to make subscribers to mods?
public static final int STATE_MODS_CAN_EDIT_MODS = 512; // allow mods to make subscribers to mods?
private static final int VISIBLE = 1;
private static final int HIDDEN = 0;
private static final int DEFAULT_STATE = STATE_PENDING|STATE_HIDE_RECEIVERS|STATE_PUBLIC_ARCHIVE;
@@ -137,17 +138,6 @@ public class MailingList implements MessageHandler {
Database.open().query(sql).compile().run();
}
/**
* load the set of mailing lists a given user is allowed to edit
* @param user
* @return
*/
public static Set<MailingList> editableBy(User user) {
var list = new HashSet<MailingList>();
for (String key : ListMember.listsOwnedBy(user)) list.add(load(key));
return list;
}
public String email() {
return email;
}
@@ -295,10 +285,32 @@ public class MailingList implements MessageHandler {
return ml;
}
/**
* Load a ML object by it's identifying email address.
* This is a cached method: if the ML has been loaded before, the already-loaded object will be returned.
* @param listEmails
* @return
*/
public static Set<MailingList> loadAll(Collection<String> listEmails) {
if (listEmails == null) return null;
if (listEmails.isEmpty()) return Set.of();
var list = new HashSet<MailingList>();
try {
var rs = Database.open()
.select(TABLE_NAME)
.where(EMAIL,listEmails)
.compile().exec();
while (rs.next()) list.add(MailingList.from(rs));
} catch (SQLException e) {
LOG.debug("Failed to load MailingLists: ",e);
}
return list;
}
public boolean mayBeAlteredBy(User user) {
if (user.hashPermission(PERMISSION_ADMIN)) return true;
try {
if (ListMember.load(this,user).isOwner()) return true;
if (ListMember.load(this,user).isModerator()) return true;
} catch (SQLException e) {
LOG.debug("Error loading list member for ({}, {})",user.email(),email());
}
@@ -343,6 +355,28 @@ public class MailingList implements MessageHandler {
return map;
}
/**
* load the set of mailing lists a given user is allowed to edit
* @param user
* @return
*/
public static List<MailingList> moderatedBy(User user) {
return ListMember.listsOf(user)
.stream()
.filter(listMember -> listMember.isModerator())
.map(ListMember::list)
.toList();
}
public boolean modsMayEditMods(){
return hasState(STATE_MODS_CAN_EDIT_MODS);
}
public MailingList modsMayNominateMods(boolean allowed) throws SQLException {
return setFlag(STATE_MODS_CAN_EDIT_MODS,allowed);
}
public String name(){
return name;
}
@@ -482,7 +516,7 @@ public class MailingList implements MessageHandler {
private void sendConfirmationRequest(User user, String token) throws MessagingException, UnsupportedEncodingException {
var subject = t("Please confirm your list subscription");
var config = Configuration.instance();
var url = new StringBuilder(config.baseUrl()).append("/confirm?token=").append(token);
var url = new StringBuilder(config.baseUrl()).append("/web/confirm?token=").append(token);
var text = t("Please go to {} in order to complete your list subscription!",url);
smtp.send(email(),name(),user.email(),subject,text);
}