preparing for main menu configuration

Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
This commit is contained in:
2026-02-06 10:05:13 +01:00
parent d0866ab73f
commit e48bac4ce2
4 changed files with 63 additions and 2 deletions

View File

@@ -12,6 +12,7 @@ import de.srsoftware.tools.ColorLogger;
import de.srsoftware.umbrella.bookmarks.BookmarkApi;
import de.srsoftware.umbrella.company.CompanyModule;
import de.srsoftware.umbrella.contact.ContactModule;
import de.srsoftware.umbrella.core.SettingsService;
import de.srsoftware.umbrella.core.Util;
import de.srsoftware.umbrella.core.exceptions.UmbrellaException;
import de.srsoftware.umbrella.documents.DocumentApi;
@@ -88,6 +89,7 @@ public class Application {
new WebHandler().bindPath("/").on(server);
new WikiModule(config).bindPath("/api/wiki").on(server);
new FileModule(config).bindPath("/api/files").on(server);
new SettingsService(config).bindPath("/api/settings").on(server);
} catch (Exception e) {
LOG.log(ERROR,"Startup failed",e);
System.exit(-1);

View File

@@ -0,0 +1,51 @@
package de.srsoftware.umbrella.core;
import com.sun.net.httpserver.HttpExchange;
import de.srsoftware.configuration.Configuration;
import de.srsoftware.tools.Path;
import de.srsoftware.tools.SessionToken;
import de.srsoftware.umbrella.core.exceptions.UmbrellaException;
import de.srsoftware.umbrella.core.model.Token;
import de.srsoftware.umbrella.core.model.UmbrellaUser;
import org.json.JSONObject;
import java.io.IOException;
import java.util.Optional;
import static de.srsoftware.umbrella.core.ModuleRegistry.userService;
import static de.srsoftware.umbrella.core.constants.Path.MENU;
public class SettingsService extends BaseHandler {
private final Configuration config;
public SettingsService(Configuration config) {
this.config = config;
}
@Override
public boolean doGet(Path path, HttpExchange ex) throws IOException {
addCors(ex);
try {
Optional<Token> token = SessionToken.from(ex).map(Token::of);
var user = userService().loadUser(token);
if (user.isEmpty()) return unauthorized(ex);
var head = path.pop();
return switch (head) {
case MENU -> getMenuSettings(user.get(), ex);
case null, default -> super.doGet(path, ex);
};
} catch (UmbrellaException e) {
return send(ex, e);
}
}
private boolean getMenuSettings(UmbrellaUser user, HttpExchange ex) throws IOException {
Optional<JSONObject> modules = config.get("umbrella.modules");
if (modules.isEmpty()) throw UmbrellaException.missingConfig("umbrella.modules");
var key = modules.get().keySet();
return notFound(ex);
}
}

View File

@@ -22,6 +22,9 @@ public class Path {
public static final String LOGIN = "login";
public static final String LOGOUT = "logout";
public static final String MENU = "menu";
public static final String PAGE = "page";
public static final String PASSWORD = "password";
public static final String PROJECT = "project";

View File

@@ -2,6 +2,8 @@
import { onMount } from 'svelte';
import { useTinyRouter } from 'svelte-tiny-router';
import { api, get } from '../urls.svelte.js';
import { logout, user } from '../user.svelte.js';
import { t } from '../translations.svelte.js';
@@ -13,8 +15,11 @@ const modules = $state([]);
let expand = $state(false);
async function fetchModules(){
const url = `${location.protocol}//${location.host.replace('5173','8080')}/legacy/user/modules`;
const resp = await fetch(url,{credentials:'include'});
let url = api('settings/menu');
const res = await get(url);
url = `${location.protocol}//${location.host.replace('5173','8080')}/legacy/user/modules`;
const resp = await get(url);
if (resp.ok){
const arr = await resp.json();
for (let entry of arr) {