fix: harden v2 custom widgets and Workshop (#6480)

This commit is contained in:
Thomas authored and GitHub committed 2026-07-31 13:28:53 +02:00
1 parent e8a2c87c2d
commit 557ebe0a2f
138 files changed
+5151 -1976

No files matched your search

+11 -2
View File
@@ -1,6 +1,15 @@
import type { HomarrDocumentationPath } from "./homarr-docs-sitemap";
const documentationBaseUrl = "https://homarr.dev";
const defaultDocumentationBaseUrl = "https://homarr.dev";
const getDocumentationBaseUrl = () => {
const browserValue =
typeof document === "undefined"
? undefined
: document.querySelector<HTMLMetaElement>('meta[name="homarr-website-url"]')?.content;
const serverValue = typeof process === "undefined" ? undefined : process.env.HOMARR_WEBSITE_URL;
return (browserValue || serverValue || defaultDocumentationBaseUrl).replace(/\/+$/u, "");
};
// Please use the method so the path can be checked!
export const createDocumentationLink = (
@@ -8,7 +17,7 @@ export const createDocumentationLink = (
hashTag?: `#${string}`,
queryParams?: Record<string, string>,
) => {
const url = `${documentationBaseUrl}${path}`;
const url = `${getDocumentationBaseUrl()}${path}`;
const params = queryParams ? `?${new URLSearchParams(queryParams)}` : "";
return `${url}${params}${hashTag ?? ""}`;
};
-3
View File
@@ -42,7 +42,6 @@ export const groupPermissions = {
integration: ["create", "use-all", "interact-all", "full-all"],
"search-engine": ["create", "modify-all", "full-all"],
media: ["upload", "view-all", "full-all"],
"custom-widget": ["manage", "secret-write"],
other: ["view-logs"],
admin: true,
} as const;
@@ -68,8 +67,6 @@ const groupPermissionParents = {
"integration-full-all",
"search-engine-full-all",
"media-full-all",
"custom-widget-manage",
"custom-widget-secret-write",
"other-view-logs",
],
} satisfies Partial<Record<GroupPermissionKey, GroupPermissionKey[]>>;
@@ -30,6 +30,21 @@ describe("createDocumentationLink should generate correct URLs", () => {
});
describe("createDocumentationLink parameter validation", () => {
test("uses the server-rendered website URL at runtime", () => {
const meta = document.createElement("meta");
meta.name = "homarr-website-url";
meta.content = "https://docs.example.com/base/";
document.head.append(meta);
try {
expect(createDocumentationLink("/docs/getting-started")).toBe(
"https://docs.example.com/base/docs/getting-started",
);
} finally {
meta.remove();
}
});
test("should work with only path parameter", () => {
const result = createDocumentationLink("/docs/getting-started");
expect(result).toBe("https://homarr.dev/docs/getting-started");