Merge branch 'module/wiki'

This commit is contained in:
2025-09-19 23:03:47 +02:00
9 changed files with 112 additions and 9 deletions

View File

@@ -101,6 +101,7 @@ public class Constants {
public static final String FULLTEXT = "fulltext";
public static final String GET = "GET";
public static final String GUEST_ALLOWED = "guest_allowed";
public static final String HASH = "hash";

View File

@@ -5,12 +5,17 @@ package de.srsoftware.umbrella.core.model;
import static de.srsoftware.umbrella.core.Constants.*;
import de.srsoftware.tools.Mappable;
import java.util.HashMap;
import java.util.Map;
public record Member(UmbrellaUser user, Permission permission) implements Mappable {
@Override
public Map<String, Object> toMap() {
return Map.of(USER,user.toMap(),PERMISSION,permission.toMap());
var map = new HashMap<String,Object>();
map.put(USER,user == null ? null : user.toMap());
map.put(PERMISSION,permission.toMap());
return map;
}
public boolean mayWrite() {

View File

@@ -22,6 +22,7 @@ public class WikiPage implements Mappable {
private final Map<Long,Member> members = new HashMap<>();
private String content;
private Set<String> dirtyFields = new HashSet<>();
private boolean guestAllowed = false;
public WikiPage(long id, String title, int version, String content) {
this.id = id;
@@ -46,6 +47,15 @@ public class WikiPage implements Mappable {
return Set.copyOf(dirtyFields);
}
public boolean guestAllowed() {
return guestAllowed;
}
public void guestAllowed(boolean guestAllowed) {
this.guestAllowed = guestAllowed;
dirtyFields.add(GUEST_ALLOWED);
}
public long id(){
return id;
}
@@ -72,6 +82,10 @@ public class WikiPage implements Mappable {
if (!(val instanceof String s)) throw invalidFieldException(CONTENT,"String");
content(s);
break;
case GUEST_ALLOWED:
if (!(val instanceof Boolean b)) throw invalidFieldException(GUEST_ALLOWED,"Boolean");
guestAllowed(b);
break;
case MEMBERS:
if (!(val instanceof JSONObject membersJson)) throw invalidFieldException(MEMBERS,"Json");
for (var uid : membersJson.keySet()){
@@ -131,6 +145,7 @@ public class WikiPage implements Mappable {
return Map.of(
ID,id,
CONTENT,Map.of(SOURCE,content,RENDERED,markdown(content)),
GUEST_ALLOWED,guestAllowed,
MEMBERS,memberMap,
TITLE,title,
VERSION,version,