|
|
|
@ -17,11 +17,9 @@ import java.io.IOException; |
|
|
|
import java.util.Optional; |
|
|
|
import java.util.Optional; |
|
|
|
|
|
|
|
|
|
|
|
import static de.srsoftware.umbrella.core.ConnectionProvider.connect; |
|
|
|
import static de.srsoftware.umbrella.core.ConnectionProvider.connect; |
|
|
|
|
|
|
|
import static de.srsoftware.umbrella.core.Constants.VERSION; |
|
|
|
import static de.srsoftware.umbrella.core.Paths.PAGE; |
|
|
|
import static de.srsoftware.umbrella.core.Paths.PAGE; |
|
|
|
import static de.srsoftware.umbrella.core.Paths.VIEW; |
|
|
|
import static de.srsoftware.umbrella.core.exceptions.UmbrellaException.*; |
|
|
|
import static de.srsoftware.umbrella.core.Util.mapValues; |
|
|
|
|
|
|
|
import static de.srsoftware.umbrella.core.exceptions.UmbrellaException.forbidden; |
|
|
|
|
|
|
|
import static de.srsoftware.umbrella.core.exceptions.UmbrellaException.missingFieldException; |
|
|
|
|
|
|
|
import static de.srsoftware.umbrella.core.model.Permission.EDIT; |
|
|
|
import static de.srsoftware.umbrella.core.model.Permission.EDIT; |
|
|
|
import static de.srsoftware.umbrella.wiki.Constants.*; |
|
|
|
import static de.srsoftware.umbrella.wiki.Constants.*; |
|
|
|
|
|
|
|
|
|
|
|
@ -73,7 +71,17 @@ public class WikiModule extends BaseHandler implements WikiService { |
|
|
|
|
|
|
|
|
|
|
|
private boolean getPage(Path path, UmbrellaUser user, HttpExchange ex) throws IOException { |
|
|
|
private boolean getPage(Path path, UmbrellaUser user, HttpExchange ex) throws IOException { |
|
|
|
var id = path.pop(); |
|
|
|
var id = path.pop(); |
|
|
|
var page = loadPage(id); |
|
|
|
Integer version = null; |
|
|
|
|
|
|
|
if (!path.empty()){ |
|
|
|
|
|
|
|
var head = path.pop(); |
|
|
|
|
|
|
|
if (!VERSION.equals(head)) return doGet(path,ex); |
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
version = Integer.parseInt(path.pop()); |
|
|
|
|
|
|
|
} catch (NumberFormatException e) { |
|
|
|
|
|
|
|
throw invalidFieldException(VERSION,"int number"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
var page = loadPage(id,version); |
|
|
|
var permission = page.members().get(user.id()); |
|
|
|
var permission = page.members().get(user.id()); |
|
|
|
if (permission == null) throw forbidden("You are not allowed to access \"{0}\"!",id); |
|
|
|
if (permission == null) throw forbidden("You are not allowed to access \"{0}\"!",id); |
|
|
|
return sendContent(ex, page); |
|
|
|
return sendContent(ex, page); |
|
|
|
@ -97,14 +105,14 @@ public class WikiModule extends BaseHandler implements WikiService { |
|
|
|
return page; |
|
|
|
return page; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private WikiPage loadPage(String id){ |
|
|
|
private WikiPage loadPage(String id, Integer version){ |
|
|
|
if (id == null) throw missingFieldException(PAGE_ID); |
|
|
|
if (id == null) throw missingFieldException(PAGE_ID); |
|
|
|
return loadMembers(wikiDb.load(id)); |
|
|
|
return loadMembers(wikiDb.load(id, version)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private boolean patchPage(Path path, UmbrellaUser user, HttpExchange ex) throws IOException { |
|
|
|
private boolean patchPage(Path path, UmbrellaUser user, HttpExchange ex) throws IOException { |
|
|
|
var id = path.pop(); |
|
|
|
var id = path.pop(); |
|
|
|
var page = loadPage(id); |
|
|
|
var page = loadPage(id, null); |
|
|
|
var member = page.members().get(user.id()); |
|
|
|
var member = page.members().get(user.id()); |
|
|
|
if (member == null || member.permission() != EDIT) throw forbidden("You are not allowed to edit {0}!",id); |
|
|
|
if (member == null || member.permission() != EDIT) throw forbidden("You are not allowed to edit {0}!",id); |
|
|
|
var json = json(ex); |
|
|
|
var json = json(ex); |
|
|
|
|