Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
fix(templates): stop instances inheriting #workspaceTemplate
Elian Doran047ca3228ab2
diff --git a/apps/client/src/entities/fnote.spec.ts b/apps/client/src/entities/fnote.spec.tsindex e741885719..4d64aad5e0 100644--- a/apps/client/src/entities/fnote.spec.ts+++ b/apps/client/src/entities/fnote.spec.ts@@ -389,7 +389,7 @@ describe("FNote attributes & inheritance", () => {it("__getCachedAttributes inherits from parents and templates, and breaks cycles", () => {// fresh notes that are NOT pre-cached by easy-froca for the parent/template relationship- const template = buildNote({ id: "tmplNote", title: "template", "#fromTemplate(inheritable)": "yes", "#template": "marker" });+ const template = buildNote({ id: "tmplNote", title: "template", "#fromTemplate(inheritable)": "yes", "#template": "marker", "#workspaceTemplate": "" });const parent = buildNote({ id: "parentInh", title: "parent", "#fromParent(inheritable)": "p" });const instance = buildNote({ id: "instanceNote", title: "instance", "~template": "tmplNote" });// wire parent@@ -412,8 +412,10 @@ describe("FNote attributes & inheritance", () => {const names = instance.getAttributes().map((a) => a.name);expect(names).toContain("fromParent");expect(names).toContain("fromTemplate");- // the "template" marker label must not be inherited- expect(instance.getAttributes("label").some((a) => a.name === "template")).toBe(false);+ // the marker labels must not be inherited+ const labelNames = instance.getAttributes("label").map((a) => a.name);+ expect(labelNames).not.toContain("template");+ expect(labelNames).not.toContain("workspaceTemplate");});it("__getCachedAttributes ignores a template relation pointing at the note itself", () => {diff --git a/apps/client/src/entities/fnote.ts b/apps/client/src/entities/fnote.tsindex 0e01d37226..1c4fa51de9 100644--- a/apps/client/src/entities/fnote.ts+++ b/apps/client/src/entities/fnote.ts@@ -397,7 +397,7 @@ export default class FNote {templateNote.__getCachedAttributes(newPath)// template attr is used as a marker for templates, but it's not meant to be inherited- .filter((attr) => !(attr.type === "label" && (attr.name === "template" || attr.name === "workspacetemplate")))+ .filter((attr) => !(attr.type === "label" && (attr.name === "template" || attr.name === "workspaceTemplate"))));}}diff --git a/packages/trilium-core/src/becca/entities/bnote.ts b/packages/trilium-core/src/becca/entities/bnote.tsindex c9f4cfe27e..df5d9f50e3 100644--- a/packages/trilium-core/src/becca/entities/bnote.ts+++ b/packages/trilium-core/src/becca/entities/bnote.ts@@ -423,7 +423,7 @@ class BNote extends AbstractBeccaEntity<BNote> {...templateNote.__getAttributes(newPath)// template attr is used as a marker for templates, but it's not meant to be inherited- .filter((attr) => !(attr.type === "label" && (attr.name === "template" || attr.name === "workspacetemplate")))+ .filter((attr) => !(attr.type === "label" && (attr.name === "template" || attr.name === "workspaceTemplate"))));}}diff --git a/packages/trilium-core/src/becca/entities/bnote_attributes.spec.ts b/packages/trilium-core/src/becca/entities/bnote_attributes.spec.tsindex f947e4748a..44937213e5 100644--- a/packages/trilium-core/src/becca/entities/bnote_attributes.spec.ts+++ b/packages/trilium-core/src/becca/entities/bnote_attributes.spec.ts@@ -89,6 +89,7 @@ describe("BNote attribute methods (real DB)", () => {getContext().init(() => {template.note.addLabel("fromTemplate", "tval");template.note.addLabel("template"); // marker, must NOT be inherited+ template.note.addLabel("workspaceTemplate"); // marker, must NOT be inherited});const consumer = createNote("root");@@ -97,8 +98,9 @@ describe("BNote attribute methods (real DB)", () => {const templated = consumer.note.getAttributes("label", "fromTemplate");expect(templated).toHaveLength(1);expect(templated[0].value).toBe("tval");- // The 'template' marker label must be filtered out.+ // The marker labels must be filtered out.expect(consumer.note.getAttributes("label", "template")).toHaveLength(0);+ expect(consumer.note.getAttributes("label", "workspaceTemplate")).toHaveLength(0);});it("returns empty inheritable attributes for a note with no inheritable owned attrs", () => {