Files
wekan/server/lib/subtaskAncestors.js
T
Lauri Ojansivu 973c2ad901 Fix #3453 #3199; linked-card custom field crash; pin #3843.
- #3453: publish the FULL subtask ancestor chain, not only direct
  parents - the cross-board full-path label vanished after refresh.
- #3748 (defect half): skip unresolvable custom-field definitions on
  linked cards - phantom empty rows and a template TypeError on every
  card details render. The mirroring itself is by design: linked cards
  are pointers; label/custom-field ids are board-scoped; name-based
  inheritance is the copy feature, not the link feature.
- #3199: group each archived card with its own Restore/Delete links and
  add a clear separator below the group (RTL-safe, theme-neutral).
- #3843: comment-editor uploads and the attachments popup now share one
  null-safe meta builder, and tests pin that comment attachments list in
  the card's Attachments section.

Closes #3748: mirroring is by design (see above); the only actionable
defect is fixed in this commit.
Closes #3378: already fixed - notification_cleanup moved off SyncedCron
to a guarded Meteor.setInterval singleton, and quave:synced-cron 2.4.0
handles the E11000 history collision that percolate 1.5.x missed.
Closes #3276: already fixed by d3625db75 - the spent-time badge helpers
now read the live Cards document reactively, so the overtime color flips
immediately; verified behaviorally against the real component.
Closes #3843: behavior verified present and now regression-locked.

Thanks to MPeti1, peterbecich, fxkr, jghaanstra and xet7.
2026-07-17 03:21:02 +03:00

65 lines
2.8 KiB
JavaScript

'use strict';
// #3453 "Full path display of subtasks cards disappears after a refresh of the
// subtask board".
//
// When a board's "Subtasks settings" present subtasks with
// 'prefix-with-full-path', the minicard renders `parentString(' > ')`, which
// walks the subtask's WHOLE ancestor chain client-side via
// ReactiveCache.getCard (models/cards.js parentList()/parentString()). After a
// hard refresh (F5) of the subtask board, minimongo only contains what the
// `board` publication ships. The publication's "Parent cards (for subtasks)"
// child used to publish only the DIRECT parents of the board's cards, so any
// grandparent living on another board was missing and the displayed path was
// truncated (or, before the parent-cards child existed at all, vanished
// entirely — the original #3453 report).
//
// collectAncestorIds() computes the FULL ancestor id set, level by level, so
// the publication can ship every card document the full-path prefix needs. It
// is pure and dependency-injected (no Meteor/Mongo imports): the caller
// supplies an async batch lookup, which keeps the traversal unit-testable with
// plain Node and keeps the server code to one query per ancestor level.
//
// Cycle safety: a card must never become its own ancestor (#3328), but corrupt
// or legacy data may still contain loops — the `seen` set guarantees the walk
// terminates and returns each ancestor id exactly once.
/**
* Collect the ids of ALL ancestors reachable from the given direct-parent ids.
*
* @param {Array<string>} seedParentIds Direct parent ids of the cards on the
* board (falsy entries and duplicates are ignored).
* @param {function(Array<string>): Promise<Array<{_id: string, parentId?: string}>>} fetchParents
* Async batch lookup: given card ids, resolves the matching card docs
* (at least `_id` and `parentId`). Missing/deleted ids may simply be
* absent from the result.
* @returns {Promise<Array<string>>} every ancestor id, each exactly once.
* Ids whose documents no longer exist are still included (they match
* nothing when published, which is harmless).
*/
async function collectAncestorIds(seedParentIds, fetchParents) {
const seen = new Set();
let frontier = [];
for (const id of Array.isArray(seedParentIds) ? seedParentIds : []) {
if (id && !seen.has(id)) {
seen.add(id);
frontier.push(id);
}
}
while (frontier.length > 0) {
const docs = (await fetchParents(frontier)) || [];
const next = [];
for (const doc of docs) {
const parentId = doc && doc.parentId;
if (parentId && !seen.has(parentId)) {
seen.add(parentId);
next.push(parentId);
}
}
frontier = next;
}
return Array.from(seen);
}
module.exports = { collectAncestorIds };