From b06cdd442d36f790088916de807dc4b2d72bdf57 Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Thu, 12 Mar 2026 20:41:53 +0200 Subject: [PATCH] fix(calendar): does not respect protected note of parent --- apps/client/src/services/note_create.ts | 30 +++++++++++-------- .../src/widgets/collections/calendar/api.ts | 10 ++++--- 2 files changed, 23 insertions(+), 17 deletions(-) diff --git a/apps/client/src/services/note_create.ts b/apps/client/src/services/note_create.ts index 00ae717d21..c4441e8692 100644 --- a/apps/client/src/services/note_create.ts +++ b/apps/client/src/services/note_create.ts @@ -1,15 +1,17 @@ +import type { CKTextEditor } from "@triliumnext/ckeditor5"; +import { AttributeRow } from "@triliumnext/commons"; + import appContext from "../components/app_context.js"; +import type FBranch from "../entities/fbranch.js"; +import type FNote from "../entities/fnote.js"; +import type { ChooseNoteTypeResponse } from "../widgets/dialogs/note_type_chooser.js"; +import froca from "./froca.js"; +import { t } from "./i18n.js"; import protectedSessionHolder from "./protected_session_holder.js"; import server from "./server.js"; -import ws from "./ws.js"; -import froca from "./froca.js"; -import treeService from "./tree.js"; import toastService from "./toast.js"; -import { t } from "./i18n.js"; -import type FNote from "../entities/fnote.js"; -import type FBranch from "../entities/fbranch.js"; -import type { ChooseNoteTypeResponse } from "../widgets/dialogs/note_type_chooser.js"; -import type { CKTextEditor } from "@triliumnext/ckeditor5"; +import treeService from "./tree.js"; +import ws from "./ws.js"; export interface CreateNoteOpts { isProtected?: boolean; @@ -24,6 +26,8 @@ export interface CreateNoteOpts { target?: string; targetBranchId?: string; textEditor?: CKTextEditor; + /** Attributes to be set on the note. These are set atomically on note creation, so entity changes are not sent for attributes defined here. */ + attributes?: Omit[]; } interface Response { @@ -37,7 +41,7 @@ interface DuplicateResponse { note: FNote; } -async function createNote(parentNotePath: string | undefined, options: CreateNoteOpts = {}) { +async function createNote(parentNotePath: string | undefined, options: CreateNoteOpts = {}, componentId?: string) { options = Object.assign( { activate: true, @@ -77,8 +81,9 @@ async function createNote(parentNotePath: string | undefined, options: CreateNot isProtected: options.isProtected, type: options.type, mime: options.mime, - templateNoteId: options.templateNoteId - }); + templateNoteId: options.templateNoteId, + attributes: options.attributes + }, componentId); if (options.saveSelection) { // we remove the selection only after it was saved to server to make sure we don't lose anything @@ -140,9 +145,8 @@ function parseSelectedHtml(selectedHtml: string) { const content = selectedHtml.replace(dom[0].outerHTML, ""); return [title, content]; - } else { - return [null, selectedHtml]; } + return [null, selectedHtml]; } async function duplicateSubtree(noteId: string, parentNotePath: string) { diff --git a/apps/client/src/widgets/collections/calendar/api.ts b/apps/client/src/widgets/collections/calendar/api.ts index 79df65e4c1..b74f5047b6 100644 --- a/apps/client/src/widgets/collections/calendar/api.ts +++ b/apps/client/src/widgets/collections/calendar/api.ts @@ -1,8 +1,8 @@ -import { AttributeRow, CreateChildrenResponse } from "@triliumnext/commons"; +import { AttributeRow } from "@triliumnext/commons"; import FNote from "../../../entities/fnote"; import { setAttribute, setLabel } from "../../../services/attributes"; -import server from "../../../services/server"; +import note_create from "../../../services/note_create"; interface NewEventOpts { title: string; @@ -51,11 +51,13 @@ export async function newEvent(parentNote: FNote, { title, startDate, endDate, s } // Create the note. - await server.post(`notes/${parentNote.noteId}/children?target=into`, { + await note_create.createNote(parentNote.noteId, { title, + isProtected: parentNote.isProtected, content: "", type: "text", - attributes + attributes, + activate: false }, componentId); }