working on editing of list properties
This commit is contained in:
@@ -5,6 +5,7 @@ public class Constants {
|
|||||||
public static final String BASE = "base";
|
public static final String BASE = "base";
|
||||||
public static final String BASE_URL = "base_url";
|
public static final String BASE_URL = "base_url";
|
||||||
public static final String DB = "database";
|
public static final String DB = "database";
|
||||||
|
public static final String DOMAIN = "domain";
|
||||||
public static final String EMAIL = "email";
|
public static final String EMAIL = "email";
|
||||||
public static final String ERROR = "error";
|
public static final String ERROR = "error";
|
||||||
public static final String HOST = "host";
|
public static final String HOST = "host";
|
||||||
@@ -17,6 +18,7 @@ public class Constants {
|
|||||||
public static final String NOTES = "notes";
|
public static final String NOTES = "notes";
|
||||||
public static final String PASSWORD = "password";
|
public static final String PASSWORD = "password";
|
||||||
public static final Object PORT = "port";
|
public static final Object PORT = "port";
|
||||||
|
public static final String PREFIX = "prefix";
|
||||||
public static final String PROTOCOL = "mail.store.protocol";
|
public static final String PROTOCOL = "mail.store.protocol";
|
||||||
public static final String STATE = "state";
|
public static final String STATE = "state";
|
||||||
public static final String USER = "user";
|
public static final String USER = "user";
|
||||||
|
|||||||
@@ -66,6 +66,12 @@ public class MailingList {
|
|||||||
Database.open().query(sql.toString()).run();
|
Database.open().query(sql.toString()).run();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void enable(String listEmail, boolean enable) throws SQLException {
|
||||||
|
// https://stackoverflow.com/questions/16440831/bitwise-xor-in-sqlite-bitwise-not-not-working-as-i-expect
|
||||||
|
String expression = enable ? "state = state | "+ENABLED : "state = (~(state & "+ENABLED+"))&(state|"+ENABLED+")";
|
||||||
|
Database.open().query("UPDATE " + TABLE_NAME + " SET "+expression).where(EMAIL, listEmail).run();
|
||||||
|
}
|
||||||
|
|
||||||
public static void hide(String listEmail, boolean hide) throws SQLException {
|
public static void hide(String listEmail, boolean hide) throws SQLException {
|
||||||
// https://stackoverflow.com/questions/16440831/bitwise-xor-in-sqlite-bitwise-not-not-working-as-i-expect
|
// https://stackoverflow.com/questions/16440831/bitwise-xor-in-sqlite-bitwise-not-not-working-as-i-expect
|
||||||
String expression = hide ? "state = (~(state & "+PUBLIC+"))&(state|"+PUBLIC+")" : ("state = state | "+PUBLIC);
|
String expression = hide ? "state = (~(state & "+PUBLIC+"))&(state|"+PUBLIC+")" : ("state = state | "+PUBLIC);
|
||||||
@@ -119,7 +125,8 @@ public class MailingList {
|
|||||||
|
|
||||||
public Map<String, Object> safeMap() {
|
public Map<String, Object> safeMap() {
|
||||||
var map = new HashMap<String,Object>();
|
var map = new HashMap<String,Object>();
|
||||||
map.put(EMAIL,email);
|
String[] parts = email.split("@", 2);
|
||||||
|
map.put(EMAIL,Map.of(PREFIX,parts[0],DOMAIN,parts[1]));
|
||||||
map.put(NAME, name);
|
map.put(NAME, name);
|
||||||
if (imapHost != null) map.put(IMAP_HOST, imapHost);
|
if (imapHost != null) map.put(IMAP_HOST, imapHost);
|
||||||
if (imapPort != 0) map.put(IMAP_PORT, imapPort);
|
if (imapPort != 0) map.put(IMAP_PORT, imapPort);
|
||||||
|
|||||||
@@ -22,6 +22,8 @@ import static de.srsoftware.widerhall.Util.t;
|
|||||||
public class Rest extends HttpServlet {
|
public class Rest extends HttpServlet {
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(Rest.class);
|
private static final Logger LOG = LoggerFactory.getLogger(Rest.class);
|
||||||
private static final String LIST_LIST = "list/list";
|
private static final String LIST_LIST = "list/list";
|
||||||
|
private static final String LIST_DISABLE = "list/disable";
|
||||||
|
private static final String LIST_ENABLE = "list/enable";
|
||||||
private static final String LIST_HIDE = "list/hide";
|
private static final String LIST_HIDE = "list/hide";
|
||||||
private static final String LIST_SHOW = "list/show";
|
private static final String LIST_SHOW = "list/show";
|
||||||
private static final String USER_LIST = "user/list";
|
private static final String USER_LIST = "user/list";
|
||||||
@@ -79,14 +81,25 @@ public class Rest extends HttpServlet {
|
|||||||
JSONObject json = new JSONObject();
|
JSONObject json = new JSONObject();
|
||||||
var path = req.getPathInfo();
|
var path = req.getPathInfo();
|
||||||
path = path == null ? INDEX : path.substring(1);
|
path = path == null ? INDEX : path.substring(1);
|
||||||
|
|
||||||
if (o instanceof User user){
|
if (o instanceof User user){
|
||||||
json.put(USER,user.safeMap());
|
json.put(USER,user.safeMap());
|
||||||
switch (path) {
|
|
||||||
|
var listEmail = req.getParameter(LIST);
|
||||||
|
if (listEmail == null || listEmail.isBlank()) {
|
||||||
|
json.putAll(Map.of(ERROR,"no list email provided!"));
|
||||||
|
} else switch (path) {
|
||||||
|
case LIST_DISABLE:
|
||||||
|
json.putAll(enableList(listEmail,user,false));
|
||||||
|
break;
|
||||||
|
case LIST_ENABLE:
|
||||||
|
json.putAll(enableList(listEmail,user,true));
|
||||||
|
break;
|
||||||
case LIST_HIDE:
|
case LIST_HIDE:
|
||||||
json.putAll(hideList(req,user,true));
|
json.putAll(hideList(listEmail,user,true));
|
||||||
break;
|
break;
|
||||||
case LIST_SHOW:
|
case LIST_SHOW:
|
||||||
json.putAll(hideList(req,user,false));
|
json.putAll(hideList(listEmail,user,false));
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
json.put(ERROR,t("No handler for path '{}'!",path));
|
json.put(ERROR,t("No handler for path '{}'!",path));
|
||||||
@@ -104,9 +117,22 @@ public class Rest extends HttpServlet {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Map<String, String> hideList(HttpServletRequest req, User user, boolean hide) {
|
private Map enableList(String listEmail, User user, boolean enable) {
|
||||||
var listEmail = req.getParameter(LIST);
|
if (user.is(ADMIN) || ListMember.listsOwnedBy(user).contains(listEmail)){
|
||||||
if (listEmail == null || listEmail.isBlank()) return Map.of(ERROR,"no list email provided!");
|
try {
|
||||||
|
MailingList.enable(listEmail,enable);
|
||||||
|
return Map.of("success",t("Mailing list '{}' was {}!",listEmail,enable ? "enabled" : "disabled"));
|
||||||
|
} catch (SQLException e) {
|
||||||
|
LOG.error("Failed to enable/disable mailing list: ",e);
|
||||||
|
return Map.of("error",t("Failed to update list '{}'",listEmail));
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
return Map.of("error",t("You are not allowed to edit '{}'",listEmail));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private Map<String, String> hideList(String listEmail, User user, boolean hide) {
|
||||||
if (user.is(ADMIN) || ListMember.listsOwnedBy(user).contains(listEmail)){
|
if (user.is(ADMIN) || ListMember.listsOwnedBy(user).contains(listEmail)){
|
||||||
try {
|
try {
|
||||||
MailingList.hide(listEmail,hide);
|
MailingList.hide(listEmail,hide);
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
«userinfo()»
|
«userinfo()»
|
||||||
<h1>Widerhall Administration</h1>
|
<h1>Widerhall Administration</h1>
|
||||||
«messages()»
|
«messages()»
|
||||||
«userlist()»
|
|
||||||
«listadminlist()»
|
«listadminlist()»
|
||||||
|
«userlist()»
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
@@ -24,6 +24,9 @@ h1 {
|
|||||||
background: yellow;
|
background: yellow;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.right{
|
||||||
|
text-align: right
|
||||||
|
}
|
||||||
.user{
|
.user{
|
||||||
background: lime;
|
background: lime;
|
||||||
float: right;
|
float: right;
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
function disableList(listEmail){
|
function disableList(listEmail){
|
||||||
console.log('disableList('+listEmail+')');
|
$.post('/api/list/disable',{list:listEmail},showListResult,'json');
|
||||||
}
|
}
|
||||||
|
|
||||||
function dropList(listEmail){
|
function dropList(listEmail){
|
||||||
@@ -7,11 +7,11 @@ function dropList(listEmail){
|
|||||||
}
|
}
|
||||||
|
|
||||||
function enableList(listEmail){
|
function enableList(listEmail){
|
||||||
console.log('enableList('+listEmail+')');
|
$.post('/api/list/enable',{list:listEmail},showListResult,'json');
|
||||||
}
|
}
|
||||||
|
|
||||||
function hideList(listEmail){
|
function hideList(listEmail){
|
||||||
$.post('/api/list/hide',{list:listEmail},showListResult,'json');
|
$.post('/api/list/hide',{list:listEmail},showListResult,'json');
|
||||||
}
|
}
|
||||||
|
|
||||||
function loadListAdminList(){
|
function loadListAdminList(){
|
||||||
@@ -42,12 +42,13 @@ function showListAdminList(data){
|
|||||||
for (let i in data.lists){
|
for (let i in data.lists){
|
||||||
let list = data.lists[i];
|
let list = data.lists[i];
|
||||||
let row = $('<tr/>');
|
let row = $('<tr/>');
|
||||||
|
let addr = list.email.prefix+'@'+list.email.domain;
|
||||||
|
|
||||||
$('<td/>').text(list.name).appendTo(row);
|
$('<td/>').text(list.name).appendTo(row);
|
||||||
$('<td/>').text(list.email).appendTo(row);
|
$('<td/>').text(addr).appendTo(row);
|
||||||
$('<td/>').text(list.state).appendTo(row);
|
$('<td/>').text(list.state).appendTo(row);
|
||||||
|
|
||||||
let select = $('<select/>',{name:list.email}).change(function () {
|
let select = $('<select/>',{name:addr}).change(function () {
|
||||||
let action = $(this).children("option:selected").val();
|
let action = $(this).children("option:selected").val();
|
||||||
let list = $(this).attr('name');
|
let list = $(this).attr('name');
|
||||||
if (confirm("This will "+action+" '"+list+"'. Are you sure?"))self[action+'List'](list);
|
if (confirm("This will "+action+" '"+list+"'. Are you sure?"))self[action+'List'](list);
|
||||||
@@ -76,10 +77,14 @@ function showListList(data){
|
|||||||
for (let i in data.lists){
|
for (let i in data.lists){
|
||||||
let list = data.lists[i];
|
let list = data.lists[i];
|
||||||
let row = $('<tr/>');
|
let row = $('<tr/>');
|
||||||
|
let subBtn = $('<button/>',{onclick:"subscribeTo('"+list.email.domain+"', '"+list.email.prefix+"');"}).text('subscribe');
|
||||||
|
|
||||||
$('<td/>').text(list.name).appendTo(row);
|
$('<td/>').text(list.name).appendTo(row);
|
||||||
$('<td/>').text(list.email).appendTo(row);
|
$('<td/>',{class:'right'}).text(list.email.prefix).appendTo(row);
|
||||||
|
$('<td/>',{class:'right'}).text('@').appendTo(row);
|
||||||
|
$('<td/>').text(list.email.domain).appendTo(row);
|
||||||
$('<td/>').text(list.state).appendTo(row);
|
$('<td/>').text(list.state).appendTo(row);
|
||||||
|
$('<td/>').html(subBtn).appendTo(row);
|
||||||
|
|
||||||
row.appendTo('#listlist');
|
row.appendTo('#listlist');
|
||||||
}
|
}
|
||||||
@@ -119,7 +124,9 @@ function start(){
|
|||||||
console.log("application started");
|
console.log("application started");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function subscribeTo(domain,prefix){
|
||||||
|
window.location.href='subscribe/'+prefix+'@'+domain;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
$(start); // document.on ready
|
$(start); // document.on ready
|
||||||
@@ -3,7 +3,7 @@
|
|||||||
<table id="listlist">
|
<table id="listlist">
|
||||||
<tr>
|
<tr>
|
||||||
<th>List Name</th>
|
<th>List Name</th>
|
||||||
<th>List Address</th>
|
<th colspan="3">List Address</th>
|
||||||
<th>State</th>
|
<th>State</th>
|
||||||
<th>Actions</th>
|
<th>Actions</th>
|
||||||
</tr>
|
</tr>
|
||||||
|
|||||||
Reference in New Issue
Block a user