preparing for poll evaluation

Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
This commit is contained in:
2026-02-27 08:46:24 +01:00
parent f78de1caae
commit 800ac35997
4 changed files with 42 additions and 9 deletions

View File

@@ -8,7 +8,6 @@ import static de.srsoftware.umbrella.core.constants.Field.ID;
import static de.srsoftware.umbrella.core.constants.Path.*;
import static de.srsoftware.umbrella.core.exceptions.UmbrellaException.*;
import static de.srsoftware.umbrella.poll.Constants.CONFIG_DATABASE;
import static java.lang.System.Logger.Level.WARNING;
import com.sun.net.httpserver.HttpExchange;
import de.srsoftware.configuration.Configuration;
@@ -50,9 +49,10 @@ public class PollModule extends BaseHandler implements PollService {
if (user.isEmpty()) return unauthorized(ex);
var head = path.pop();
return switch (head) {
case LIST -> getPollList(ex,user.get());
case null -> super.doGet(path,ex);
default -> getPoll(ex,user.get(),head);
case EVALUATE -> getPollEvaluation(ex,user.get(), path);
case LIST -> getPollList(ex,user.get());
case null -> super.doGet(path,ex);
default -> getPoll(ex,user.get(),head);
};
} catch (UmbrellaException e){
return send(ex,e);
@@ -94,9 +94,14 @@ public class PollModule extends BaseHandler implements PollService {
}
private boolean getPoll(HttpExchange ex, UmbrellaUser user, String id) throws IOException {
var poll = pollDb.loadPoll(id);
// TODO: check permissions
LOG.log(WARNING,"no permission checks on PollModule.getPoll({0})",id);
return sendContent(ex,loadPoll(user,id));
}
private boolean getPollEvaluation(HttpExchange ex, UmbrellaUser user, Path path) throws IOException {
if (path.empty()) throw missingField(ID);
var poll = loadPoll(user,path.pop());
// TODO: load data required for evaluation
return sendContent(ex,poll);
}
@@ -105,13 +110,18 @@ public class PollModule extends BaseHandler implements PollService {
return sendContent(ex,list);
}
private boolean patchPoll(HttpExchange ex, UmbrellaUser user, String id, Path path) throws IOException {
var poll = pollDb.loadPoll(id);
private Poll loadPoll(UmbrellaUser user, String pollId) {
var poll = pollDb.loadPoll(pollId);
var permitted = user.equals(poll.owner());
if (!permitted) {
var permission = poll.shares().get(user);
if (permission == null || permission < 2) throw forbidden(Text.NOT_ALLOWED_TO_EDIT, Field.OBJECT,Text.POLL);
}
return poll;
}
private boolean patchPoll(HttpExchange ex, UmbrellaUser user, String id, Path path) throws IOException {
var poll = loadPoll(user,id);
var head = path.pop();
return switch (head){
case null -> patchPoll(ex, poll);