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

@@ -13,6 +13,8 @@ public class Path {
public static final String COMPANY = "company"; public static final String COMPANY = "company";
public static final String CONNECTED = "connected"; public static final String CONNECTED = "connected";
public static final String EVALUATE = "evaluate";
public static final String ITEM = "item"; public static final String ITEM = "item";
public static final String JSON = "json"; public static final String JSON = "json";

View File

@@ -17,6 +17,7 @@
import EditPoll from "./routes/poll/Edit.svelte"; import EditPoll from "./routes/poll/Edit.svelte";
import EditService from "./routes/user/EditService.svelte"; import EditService from "./routes/user/EditService.svelte";
import EditUser from "./routes/user/EditUser.svelte"; import EditUser from "./routes/user/EditUser.svelte";
import EvalPoll from "./routes/poll/Evaluate.svelte";
import FileIndex from "./routes/files/Index.svelte"; import FileIndex from "./routes/files/Index.svelte";
import Footer from "./Components/Footer.svelte"; import Footer from "./Components/Footer.svelte";
import Kanban from "./routes/project/Kanban.svelte"; import Kanban from "./routes/project/Kanban.svelte";
@@ -99,6 +100,7 @@
<Route path="/notes" component={Notes} /> <Route path="/notes" component={Notes} />
<Route path="/poll" component={PollList} /> <Route path="/poll" component={PollList} />
<Route path="/poll/:id/edit" component={EditPoll} /> <Route path="/poll/:id/edit" component={EditPoll} />
<Route path="/poll/:id/evaluate" component={EvalPoll} />
<Route path="/project" component={ProjectList} /> <Route path="/project" component={ProjectList} />
<Route path="/project/add" component={ProjectAdd} /> <Route path="/project/add" component={ProjectAdd} />
<Route path="/project/:project_id/add_task" component={AddTask} /> <Route path="/project/:project_id/add_task" component={AddTask} />

View File

@@ -0,0 +1,19 @@
<script>
import { onMount } from 'svelte';
import { api, get } from '../../urls.svelte';
let { id } = $props();
async function load(){
let url = api('poll/evaluate/'+id);
let res = await get(url);
if (res.ok){
poll = await res.json();
yikes();
} else error(res);
}
onMount(load);
</script>
Evaluate

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