implemented event-based page-refresh for wiki pages
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
description = "Umbrella : Wiki"
|
||||
|
||||
dependencies{
|
||||
implementation(project(":bus"))
|
||||
implementation(project(":core"))
|
||||
}
|
||||
@@ -11,6 +11,7 @@ import static de.srsoftware.umbrella.core.exceptions.UmbrellaException.*;
|
||||
import static de.srsoftware.umbrella.core.model.Permission.EDIT;
|
||||
import static de.srsoftware.umbrella.core.model.Permission.READ_ONLY;
|
||||
import static de.srsoftware.umbrella.wiki.Constants.*;
|
||||
import static de.srsoftware.umbrella.messagebus.MessageBus.messageBus;
|
||||
|
||||
import com.sun.net.httpserver.HttpExchange;
|
||||
import de.srsoftware.configuration.Configuration;
|
||||
@@ -20,6 +21,8 @@ import de.srsoftware.umbrella.core.BaseHandler;
|
||||
import de.srsoftware.umbrella.core.api.WikiService;
|
||||
import de.srsoftware.umbrella.core.exceptions.UmbrellaException;
|
||||
import de.srsoftware.umbrella.core.model.*;
|
||||
import de.srsoftware.umbrella.messagebus.events.WikiEvent;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Optional;
|
||||
@@ -190,10 +193,13 @@ public class WikiModule extends BaseHandler implements WikiService {
|
||||
private boolean patchPage(Path path, UmbrellaUser user, HttpExchange ex) throws IOException {
|
||||
var id = path.pop();
|
||||
var page = loadPage(id, null);
|
||||
var old = page.toMap();
|
||||
var member = page.members().get(user.id());
|
||||
if (member == null || member.permission() != EDIT) throw forbidden("You are not allowed to edit {0}!",id);
|
||||
var json = json(ex);
|
||||
return sendContent(ex,wikiDb.save(page.patch(json, userService())));
|
||||
page = wikiDb.save(page.patch(json, userService()));
|
||||
messageBus().dispatch(new WikiEvent(user,page,old));
|
||||
return sendContent(ex,page);
|
||||
}
|
||||
|
||||
private boolean postNewPage(String title, UmbrellaUser user, HttpExchange ex) throws IOException {
|
||||
|
||||
Reference in New Issue
Block a user