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
prevent attribute inheritance cycle via template, closes #1077
zadam1502b9ce6660
diff --git a/src/public/app/entities/note_short.js b/src/public/app/entities/note_short.jsindex 2b1dbf6103..f68547eb7c 100644--- a/src/public/app/entities/note_short.js+++ b/src/public/app/entities/note_short.js@@ -170,6 +170,16 @@ class NoteShort {* @returns {Attribute[]} all note's attributes, including inherited ones*/getAttributes(type, name) {+ return this.__filterAttrs(this.__getCachedAttributes([]), type, name);+ }++ __getCachedAttributes(path) {+ // notes/clones cannot form tree cycles, it is possible to create attribute inheritance cycle via templates+ // when template instance is a parent of template itself+ if (path.includes(this.noteId)) {+ return [];+ }+if (!(this.noteId in noteAttributeCache)) {const ownedAttributes = this.getOwnedAttributes();@@ -177,11 +187,13 @@ class NoteShort {ownedAttributes];+ const newPath = [...path, this.noteId];+for (const templateAttr of ownedAttributes.filter(oa => oa.type === 'relation' && oa.name === 'template')) {const templateNote = this.treeCache.notes[templateAttr.value];- if (templateNote) {- attrArrs.push(templateNote.getAttributes());+ if (templateNote && templateNote.noteId !== this.noteId) {+ attrArrs.push(templateNote.__getCachedAttributes(newPath));}}@@ -189,7 +201,7 @@ class NoteShort {for (const parentNote of this.getParentNotes()) {// these virtual parent-child relationships are also loaded into frontend tree cacheif (parentNote.type !== 'search') {- attrArrs.push(parentNote.getInheritableAttributes());+ attrArrs.push(parentNote.__getInheritableAttributes(newPath));}}}@@ -197,7 +209,7 @@ class NoteShort {noteAttributeCache.attributes[this.noteId] = attrArrs.flat();}- return this.__filterAttrs(noteAttributeCache.attributes[this.noteId], type, name);+ return noteAttributeCache.attributes[this.noteId];}__filterAttrs(attributes, type, name) {@@ -212,8 +224,8 @@ class NoteShort {}}- getInheritableAttributes() {- const attrs = this.getAttributes();+ __getInheritableAttributes(path) {+ const attrs = this.__getCachedAttributes(path);return attrs.filter(attr => attr.isInheritable);}@@ -460,4 +472,4 @@ class NoteShort {}}-export default NoteShort;\ No newline at end of file+export default NoteShort;diff --git a/src/public/app/widgets/collapsible_widgets/note_info.js b/src/public/app/widgets/collapsible_widgets/note_info.jsindex e0cb8aaac4..12a613fd85 100644--- a/src/public/app/widgets/collapsible_widgets/note_info.js+++ b/src/public/app/widgets/collapsible_widgets/note_info.js@@ -4,7 +4,6 @@ const TPL = `<table class="note-info-widget-table"><style>.note-info-widget-table {- table-layout: fixed;width: 100%;}@@ -22,22 +21,23 @@ const TPL = `<tr><th>Note ID:</th>- <td colspan="3" class="note-info-note-id"></td>+ <td class="note-info-note-id"></td></tr><tr><th>Created:</th>- <td colspan="3" class="note-info-date-created"></td>+ <td class="note-info-date-created"></td></tr><tr><th>Modified:</th>- <td colspan="3" class="note-info-date-modified"></td>+ <td class="note-info-date-modified"></td></tr><tr><th>Type:</th>- <td class="note-info-type"></td>-- <th>MIME:</th>- <td class="note-info-mime"></td>+ <td>+ <span class="note-info-type"></span>++ <span class="note-info-mime"></span>+ </td></tr></table>`;@@ -69,9 +69,12 @@ export default class NoteInfoWidget extends CollapsibleWidget {this.$type.text(note.type);- this.$mime- .text(note.mime)- .attr("title", note.mime);+ if (note.mime) {+ this.$mime.text('(' + note.mime + ')');+ }+ else {+ this.$mime.empty();+ }}entitiesReloadedEvent({loadResults}) {diff --git a/src/services/backup.js b/src/services/backup.jsindex 15f24e6487..422406bd7e 100644--- a/src/services/backup.js+++ b/src/services/backup.js@@ -96,9 +96,9 @@ async function anonymize() {await db.run("UPDATE api_tokens SET token = 'API token value'");await db.run("UPDATE notes SET title = 'title'");- await db.run("UPDATE note_contents SET content = 'text'");+ await db.run("UPDATE note_contents SET content = 'text' WHERE content IS NOT NULL");await db.run("UPDATE note_revisions SET title = 'title'");- await db.run("UPDATE note_revision_contents SET content = 'title'");+ await db.run("UPDATE note_revision_contents SET content = 'title' WHERE content IS NOT NULL");await db.run("UPDATE attributes SET name = 'name', value = 'value' WHERE type = 'label'");await db.run("UPDATE attributes SET name = 'name' WHERE type = 'relation' AND name != 'template'");await db.run("UPDATE branches SET prefix = 'prefix' WHERE prefix IS NOT NULL");