- Alle Vorkommen von process.env.NEXT_PUBLIC_DEBUG_LOG entfernt - Debug-Konfiguration erfolgt jetzt ausschließlich über public/config.json - getDebugLog()-Utility überall verwendet - .env-Dateien werden für Debug-Logging nicht mehr benötigt - Alle betroffenen Komponenten, Services und API
60 lines
1.8 KiB
JavaScript
60 lines
1.8 KiB
JavaScript
/**
|
|
* Holt Benutzerrechte aus TALAS-Webservice oder aus Mocks.
|
|
*
|
|
* @returns {Promise<Array>} Rechte-Array
|
|
* @throws {Error} bei Lade- oder Strukturfehler
|
|
*/
|
|
|
|
import { getDebugLog, getConfig } from "../../utils/configUtils";
|
|
|
|
export const fetchUserRightsService = async () => {
|
|
const useMocks = process.env.NEXT_PUBLIC_USE_MOCKS === "true";
|
|
const config = await getConfig();
|
|
const basePath = config.basePath || "";
|
|
|
|
if (useMocks) {
|
|
const mockBasePath = "/api/mocks/webservice/gisSystemStatic";
|
|
const mockURL = `${window.location.origin}${mockBasePath}`;
|
|
if (getDebugLog()) {
|
|
console.log("🧪 Mock-Modus aktiviert: fetchUserRightsService ", mockURL);
|
|
}
|
|
|
|
const response = await fetch("/api/mocks/webservice/gisSystemStatic "); //gisSystemStatic enthält die Systeme (Systems) und die User Rechte (Rights)
|
|
if (!response.ok) {
|
|
throw new Error("Mockdaten konnten nicht geladen werden");
|
|
}
|
|
|
|
const mockData = await response.json();
|
|
return mockData.Rights || [];
|
|
} else {
|
|
const baseUrl = `${window.location.protocol}//${window.location.hostname}:80${basePath}/ClientData/WebServiceMap.asmx`;
|
|
|
|
const params = new URLSearchParams(window.location.search);
|
|
const idMap = params.get("m");
|
|
const idUser = params.get("u");
|
|
|
|
const url = `${baseUrl}/GisSystemStatic?idMap=${idMap}&idUser=${idUser}`;
|
|
if (getDebugLog()) {
|
|
console.log("🔍 Rechte-Fetch URL:", url);
|
|
}
|
|
|
|
const response = await fetch(url, {
|
|
method: "GET",
|
|
headers: {
|
|
Connection: "close",
|
|
},
|
|
});
|
|
|
|
if (!response.ok) {
|
|
throw new Error("Fehler beim Abrufen der Benutzerrechte");
|
|
}
|
|
|
|
const json = await response.json();
|
|
if (getDebugLog()) {
|
|
console.log("👤 Rechte-Response JSON:", json);
|
|
}
|
|
|
|
return json.Rights || [];
|
|
}
|
|
};
|