mirror of
https://github.com/wekan/wekan.git
synced 2026-11-24 18:10:06 -05:00
A card's own description was the only place to put markdown text, so anything
beyond a single block had to be crammed into it. This adds CardTextNotes: a
small collection of named markdown notes per card, modeled on Checklists (a
denormalized boardId, the same publish/allow/deny shape, the same
GHSA-gv8h-5p3p-6hx7 cross-board-move guard).
Each note renders as a tile with its title and a markdown-rendered preview
(the `viewer` template). "Add text note" and a note's "Edit" open a popup
that reuses the description's own `editor`/`viewer` widgets verbatim - no new
markdown editor was written. "Delete" removes the note, scoped to its own
_id.
Wired into the reactive cache (getCardTextNote/getCardTextNotes, matching the
CardComments pattern), the board/linked-card/lazy-window/single-card
publications, and server/permissions/cardTextNotes.js.
tests/cardTextNotes.test.cjs pins: the model's cardId/boardId scoping, the
allow/deny permission shape, the popup's reuse of `editor`/`viewer` (positive:
+editor is used; negative: exactly one `editor` and one `viewer` template is
declared anywhere under client/components/{cards,main} - the whole tree, not
just the new files, so a competing widget cannot be introduced elsewhere
either), and that add/edit/delete are scoped calls rather than broad
selectors.
Thanks to Lapin0t and xet7 !
Closes #595,
35 lines
1.4 KiB
JavaScript
35 lines
1.4 KiB
JavaScript
import Cards from '/models/cards';
|
|
import CardTextNotes from '/models/cardTextNotes';
|
|
import { denyCrossBoardMoveByCard } from '/server/lib/utils';
|
|
import { tripCanaryDeny } from '/server/lib/canary';
|
|
import { canEditCardOrLinkedCard } from '/server/lib/linkedCardPermission';
|
|
|
|
CardTextNotes.allow({
|
|
async insert(userId, doc) {
|
|
// ReadOnly users cannot create text notes
|
|
return await canEditCardOrLinkedCard(userId, await Cards.findOneAsync(doc.cardId));
|
|
},
|
|
async update(userId, doc) {
|
|
// ReadOnly users cannot edit text notes
|
|
return await canEditCardOrLinkedCard(userId, await Cards.findOneAsync(doc.cardId));
|
|
},
|
|
async remove(userId, doc) {
|
|
// ReadOnly users cannot delete text notes
|
|
return await canEditCardOrLinkedCard(userId, await Cards.findOneAsync(doc.cardId));
|
|
},
|
|
fetch: ['userId', 'cardId'],
|
|
});
|
|
|
|
// Same defense-in-depth as Checklists (GHSA-gv8h-5p3p-6hx7): the allow rule
|
|
// above only checks write access on the text note's SOURCE card/board, so a
|
|
// DDP client could move a text note into a private board it is not a member
|
|
// of by $set-ting a new cardId. Deny any move whose destination board the
|
|
// caller cannot write to.
|
|
CardTextNotes.deny({
|
|
async update(userId, doc, fieldNames, modifier) {
|
|
if (!(await denyCrossBoardMoveByCard(userId, modifier))) return false;
|
|
return tripCanaryDeny('cardTextNote.cross-board-move', { userId });
|
|
},
|
|
fetch: [],
|
|
});
|