Browse Source

Merge branch 'main' into lang_de

lang_de
Stephan Richter 6 months ago
parent
commit
8f614d610a
  1. 45
      src/main/java/de/srsoftware/widerhall/data/MailingList.java
  2. 5
      src/main/java/de/srsoftware/widerhall/data/User.java
  3. 8
      src/main/java/de/srsoftware/widerhall/web/Rest.java
  4. 3
      src/main/resources/Application.de.translation
  5. 27
      static/templates/js.st

45
src/main/java/de/srsoftware/widerhall/data/MailingList.java

@ -22,6 +22,7 @@ import java.util.stream.Stream; @@ -22,6 +22,7 @@ import java.util.stream.Stream;
import static de.srsoftware.widerhall.Constants.*;
import static de.srsoftware.widerhall.Util.t;
import static de.srsoftware.widerhall.data.ListMember.*;
import static de.srsoftware.widerhall.data.User.PERMISSION_ADMIN;
/**
@ -268,7 +269,7 @@ public class MailingList implements MessageHandler, ProblemListener { @@ -268,7 +269,7 @@ public class MailingList implements MessageHandler, ProblemListener {
if (user == null) return false;
try {
var member = ListMember.load(this,user);
return member.hasState(ListMember.STATE_OWNER|ListMember.STATE_SUBSCRIBER); // owners may subscribe their own mailing lists
return member.hasState(STATE_OWNER|STATE_SUBSCRIBER); // owners may subscribe their own mailing lists
} catch (SQLException e) {
LOG.warn("Was not able to load ListMember:",e);
return false;
@ -283,6 +284,16 @@ public class MailingList implements MessageHandler, ProblemListener { @@ -283,6 +284,16 @@ public class MailingList implements MessageHandler, ProblemListener {
return hasState(STATE_OPEN_FOR_GUESTS|STATE_OPEN_FOR_SUBSCRIBERS);
}
public boolean isOwnedBy(User user) {
if (user == null) return false;
try {
if (ListMember.load(this,user).isOwner()) return true;
} catch (SQLException e) {
LOG.debug("Error loading list member for ({}, {})",user.email(),email());
}
return false;
}
public static List<MailingList> listActive() {
try {
var list = new ArrayList<MailingList>();
@ -505,10 +516,6 @@ public class MailingList implements MessageHandler, ProblemListener { @@ -505,10 +516,6 @@ public class MailingList implements MessageHandler, ProblemListener {
return list;
}
public Stream<ListMember> owners() throws SQLException {
return members().filter(ListMember::isOwner);
}
public MailingList replyToList(boolean on) throws SQLException {
return setFlag(STATE_REPLY_TO_LIST,on);
}
@ -678,7 +685,7 @@ public class MailingList implements MessageHandler, ProblemListener { @@ -678,7 +685,7 @@ public class MailingList implements MessageHandler, ProblemListener {
* @throws MessagingException
*/
public void requestSubscription(User user, boolean skipConfirmation, ST template) throws SQLException, MessagingException {
var state = skipConfirmation ? ListMember.STATE_SUBSCRIBER : ListMember.STATE_AWAITING_CONFIRMATION;
var state = skipConfirmation ? STATE_SUBSCRIBER : STATE_AWAITING_CONFIRMATION;
var member = ListMember.create(this,user,state);
if (skipConfirmation) return;
try {
@ -742,6 +749,32 @@ public class MailingList implements MessageHandler, ProblemListener { @@ -742,6 +749,32 @@ public class MailingList implements MessageHandler, ProblemListener {
}
}
public String transfer(User owner, String newOwnerMail) {
User newOwner;
try {
newOwner = User.load(newOwnerMail);
} catch (SQLException e) {
return t("Failed to load user for address {}",newOwnerMail);
}
ListMember member;
try {
member = ListMember.load(this,newOwner);
} catch (SQLException e) {
return t("{} is not a member of {}",newOwner);
}
try {
member.setState(STATE_OWNER);
} catch (SQLException e) {
return t("Failed to transfer list ownership to {}",newOwner);
}
try {
ListMember.load(this,owner).setState(STATE_MODERATOR);
} catch (SQLException e) {
return t("Failed to withdraw ownership from {}",owner);
}
return null;
}
public void update(String name, String email, String imapHost, Integer imapPort, String imapUser, String imapPass, String inbox, String smtpHost, Integer smtpPort, String smtpUser, String smtpPass) throws SQLException {
imap.stop();
Database.open()

5
src/main/java/de/srsoftware/widerhall/data/User.java

@ -326,4 +326,9 @@ public class User { @@ -326,4 +326,9 @@ public class User {
public String token() {
return token;
}
@Override
public String toString() {
return name == null ? email : name;
}
}

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

@ -18,6 +18,7 @@ import java.sql.SQLException; @@ -18,6 +18,7 @@ import java.sql.SQLException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import static de.srsoftware.widerhall.Constants.*;
import static de.srsoftware.widerhall.Util.t;
@ -40,6 +41,7 @@ public class Rest extends HttpServlet { @@ -40,6 +41,7 @@ public class Rest extends HttpServlet {
private static final String LIST_TEST = "list/test";
private static final String LIST_SUBSCRIBABLE = "list/subscribable";
private static final String MAIL_DROP = "mail/drop";
private static final String TRANSFER = "list/transfer";
private static final String USER_ADD_PERMISSION = "user/addpermission";
private static final String USER_DROP_PERMISSION = "user/droppermission";
private static final String USER_LIST = "user/list";
@ -267,6 +269,11 @@ public class Rest extends HttpServlet { @@ -267,6 +269,11 @@ public class Rest extends HttpServlet {
var messageId = req.getParameter(MESSAGE_ID);
json.putAll(dropMail(messageId,user));
break;
case TRANSFER:
if (list.isOwnedBy(user)){
Optional.ofNullable(list.transfer(user,userEmail)).ifPresent(err -> json.put(ERROR,err));
} else json.put(ERROR,t("As you don't own this list, you may not transfer its ownership!"));
break;
case USER_ADD_PERMISSION:
if (user.hashPermission(User.PERMISSION_ADMIN)){
json.putAll(addPermission(userEmail,permissions));
@ -286,6 +293,7 @@ public class Rest extends HttpServlet { @@ -286,6 +293,7 @@ public class Rest extends HttpServlet {
}
try {
resp.setContentType("application/json");
if (json.containsKey(ERROR)) resp.setStatus(404);
resp.getWriter().println(json.toJSONString());
return null;
} catch (IOException e) {

3
src/main/resources/Application.de.translation

@ -8,6 +8,7 @@ @@ -8,6 +8,7 @@
'{}' is not a valid email address! : '{}' ist keine gültige Mailadresse!
{} is now a moderator of {} : {} ist nun ein Moderator der Liste {}
archive : Archiv
As you don't own this list, you may not transfer its ownership! : Sie können das Eigentum an der Liste nicht übertragen, da Sie nicht Eigentümer sind!
awaiting confirmation : erwartet Bestätigung
Confirmation of list membership failed! : Bestätigung des Listen-Abonnements fehlgeschlagen!
Confirmed list subscription! : Listen-Mitgliedschaft bestätigt!
@ -36,12 +37,14 @@ Failed to send email to {} : Senden der Email an {} fehlgeschlagen! @@ -36,12 +37,14 @@ Failed to send email to {} : Senden der Email an {} fehlgeschlagen!
Failed to send request confirmation email\: {} : Senden der Bestätigungs-Email fehlgeschlagen: {}
Failed to send reset email\: : Senden der Passwort-Änderungs-Mail fehlgeschlagen:
Failed to send test email to {} : Senden der Test-Email an {} fehlgeschlagen!
Failed to transfer list ownership to {} : Übereignen der Liste an {} fehlgeschlagen
Failed to (un)hide mailing list\: : Veröffentlichen/Verstekcen der Mailing-Liste fehlgeschlagen:
Failed to un-subscribe {} from {} : Abbestellen von {} / {} fehlgeschlagen!
Failed to unsubscribe! : Abbestellen der Mailin-Liste fehlgeschlagen!
Failed to update list '{}' : Aktualisieren der Liste '{}' fehlgeschlagen!
Failed to update MailingList! : Aktualisierung der Mailing-Liste fehlgeschlagen!
Failed to update password in database! : Aktualisierung des Passworts in der Datenbank fehlgeschlagen!
Failed to withdraw ownership from {} : Ablösen des Eigentums von {} fehlgeschlagen
Fill all fields, please! : Bitte alle Felder ausfüllen!
File {} does not exist! : Datei {} existiert nicht!
Find the forwarded message in the attachment(s)!\n : Die weitergeleitete Nachricht findest du im Anhang dieser E-Mail!\n

27
static/templates/js.st

@ -212,6 +212,11 @@ function showListResult(result){ @@ -212,6 +212,11 @@ function showListResult(result){
function showMembers(data){
var list_mail = data.list.email.prefix+'@'+data.list.email.domain;
console.log("data",data);
var owner = false;
for (let member of data.members){
if (member.email == data.user.email && member.state.includes("owner")) owner = member.email;
}
for (let i in data.members){
let member = data.members[i];
let row = $('<tr/>');
@ -219,11 +224,17 @@ function showMembers(data){ @@ -219,11 +224,17 @@ function showMembers(data){
$('<td/>').text(member.email).appendTo(row);
$('<td/>').text(member.state).appendTo(row);
let col = $('<td/>');
console.log("data",data);
if (member.state.includes("Moderator")) {
if (!member.state.includes("Besitzer")) $('<button/>',{onclick:'dropMod("'+member.email+'","'+list_mail+'")'}).text("- Moderator").appendTo(col);
} else $('<button/>',{onclick:'addMod("'+member.email+'","'+list_mail+'")'}).text("+ Moderator").appendTo(col);
if (!member.state.includes("Besitzer")) $('<button/>',{onclick:'dropMember("'+member.email+'","'+list_mail+'")'}).text("entfernen").appendTo(col);
if (member.state.includes("moderator")) {
if (member.email != owner){
$('<button/>',{onclick:'dropMod("'+member.email+'","'+list_mail+'")'}).text("- Moderator").appendTo(col);
if (data.user.email == owner) $('<button/>',{onclick:'transfer("'+member.email+'","'+list_mail+'")'}).text("Eigentum übertragen").appendTo(col);
}
} else {
$('<button/>',{onclick:'addMod("'+member.email+'","'+list_mail+'")'}).text("+ Moderator").appendTo(col);
}
if (!member.state.includes("owner")) {
$('<button/>',{onclick:'dropMember("'+member.email+'","'+list_mail+'")'}).text("entfernen").appendTo(col);
}
col.appendTo(row);
row.appendTo('#memberlist');
@ -274,6 +285,12 @@ function testList(listEmail){ @@ -274,6 +285,12 @@ function testList(listEmail){
$.post('/api/list/test',{list:listEmail},showListResult,'json');
}
function transfer(newOwner,listEmail){
if (confirm("Really transfer "+listEmail+" to "+newOwner+"?")){
$.post('/api/list/transfer',{email:newOwner,list:listEmail},reload,'json');
}
}
function unsubscribeFrom(listEmail){
window.location.href='unsubscribe?list='+listEmail;
}

Loading…
Cancel
Save