mirror of
https://github.com/wekan/wekan.git
synced 2026-11-20 21:45:01 -05:00
"Activities for archived card displayed as undefined on board settings." Move a
card around to make some activities, archive it, open the board sidebar - and the
sentences that named that card name nothing. The reporter said what they wanted
instead: "{{ card title }} [archived]".
The feed asked `activity.card()` and rendered its title. An archived card is not
published to the client, so that lookup returns nothing and each sentence was
built around a hole: a card that still exists, still has a title, and whose
activities are right there on the page went nameless in its own history.
The activity already knew the title in most cases - createCard, moveCard and
moveCardBoard have stored `cardTitle` for years. So the answer is not to publish
archived cards to every sidebar, which would send data to clients that do not need
it; it is to read what the activity recorded. models/lib/activityCardLink.js
decides, in order: the card's CURRENT title when the card is here (a card renamed
since should read as it reads now), marked when that card says it is archived; the
title the activity recorded when the card is not here; and null when neither
exists, which the feed renders as "this card" rather than as a gap in the middle
of a sentence.
The link survives all of it. A card URL is /b/<boardId>/<slug>/<cardId>, and an
activity carries both ids, so the anchor is built without the card document
(models/lib/cardUrl.js). No card document also means no slug, and the fallback
'board' is a segment the route ignores - it does not invent "/b/undefined/...",
which is the bug that helper was written for (#6427).
A missing card is NOT called archived, and that is deliberate. It nearly always is
- a deleted card takes its activities with it (Cards.cardRemover) - but with lazy
card loading a card can simply be outside the window this client was sent, and
"archived" would then be a statement the feed cannot support. The mark is used
only where the card is here and says so itself.
The two activities that were NOT storing a title are the two about archiving:
archivedCard and restoredCard now record `cardTitle` like the others. They are
exactly the ones guaranteed to be about a card the client can no longer look up,
which is why this bug was reported about archiving and not about anything else.
Activities written before this have no title, and those are the ones that read
"this card".
Both strings are translated (`archived`, `this-card`, which already exist in every
language file), and a title out of the database is still sanitised before it
reaches the page.
tests/activityCardLink.test.cjs covers the reported case and the ones around it:
the live title winning over the recorded one, the board slug when the board
document is at hand, an activity with no cardId naming the card without inventing
a link, junk titles ('', ' ', null, numbers, objects) never becoming titles, and
a missing card never being called archived. Plus both ends of the wiring: the
archive activity recording the title, and no call site passing only the card.
Verified by running the suite and the whole node suite (384 suites, 0 failed). Not
verified in a browser: this sandbox has none.
Thanks to rptl and xet7 !
Fixes #3144.
88 lines
3.9 KiB
JavaScript
88 lines
3.9 KiB
JavaScript
'use strict';
|
|
|
|
// What an activity in the board feed says about the card it happened to.
|
|
//
|
|
// wekan/wekan#3144: "Activities for archived card displayed as undefined on board
|
|
// settings". Move a card around to make some activities, archive it, and open the
|
|
// board sidebar: the sentences that named that card no longer name anything.
|
|
// "Instead undefined, suggest to display '{{ card title }} [archived]'."
|
|
//
|
|
// The feed asks `activity.card()` and renders its title. An archived card is not
|
|
// published to the client, so that lookup returns nothing and the sentence is
|
|
// built around a hole - which is how a card that still exists, with a title, and
|
|
// whose activities are right there, ends up nameless in its own history.
|
|
//
|
|
// An activity already knows the title in most cases: createCard, moveCard and
|
|
// moveCardBoard have stored `cardTitle` for years. So the answer is not to publish
|
|
// archived cards to every board sidebar - it is to read what the activity itself
|
|
// recorded, and to record it on the activities that were not storing it.
|
|
//
|
|
// WHAT IT DECIDES, in order:
|
|
// * the card is here -> its CURRENT title, because a card that has been
|
|
// renamed since should read as it reads now
|
|
// * the card is here and archived -> that title, marked, which is what the
|
|
// reporter asked for
|
|
// * the card is gone from this client but the activity recorded a title
|
|
// -> that title, unmarked
|
|
// * neither -> null, and the caller says "this card" rather
|
|
// than an empty gap
|
|
//
|
|
// The link survives all four: a card URL is `/b/<boardId>/<slug>/<cardId>`, and an
|
|
// activity carries the boardId and the cardId, so it can be built without the card
|
|
// document (models/lib/cardUrl.js).
|
|
//
|
|
// WHY A MISSING CARD IS NOT MARKED ARCHIVED. It usually is - the activities of a
|
|
// DELETED card are removed with the card (Cards.cardRemover), so an activity
|
|
// pointing at a card this client cannot see is nearly always an archived one. But
|
|
// "nearly always" is not always: with lazy card loading a card can simply be
|
|
// outside the window this client has been sent. Marking that one "archived" would
|
|
// be a statement the feed cannot support, so the mark is used only where the card
|
|
// IS here and says so itself.
|
|
//
|
|
// Pure and dependency-free: the client renders from it, and
|
|
// tests/activityCardLink.test.cjs exercises it on its own.
|
|
|
|
const { buildCardRelativeUrl } = require('./cardUrl');
|
|
|
|
// The title an activity recorded when it happened. Several activity types store
|
|
// it under `cardTitle`; `title` is what a few older ones used.
|
|
function recordedTitle(activity) {
|
|
if (!activity) return null;
|
|
for (const field of ['cardTitle', 'title']) {
|
|
const value = activity[field];
|
|
if (typeof value === 'string' && value.trim()) return value;
|
|
}
|
|
return null;
|
|
}
|
|
|
|
// { title, url, archived, fromActivity } - or null when there is nothing to name.
|
|
// activity the activity document
|
|
// card the card document, when this client has it
|
|
// board the board document, for the human-readable slug (optional)
|
|
function activityCardLinkData(activity, card, board) {
|
|
const liveTitle = card && typeof card.title === 'string' && card.title.trim()
|
|
? card.title
|
|
: null;
|
|
const stored = recordedTitle(activity);
|
|
const title = liveTitle || stored;
|
|
if (!title) return null;
|
|
|
|
// The card document is the better source for the URL (it may have moved), but
|
|
// an activity knows enough to build one on its own.
|
|
const target = card && card._id
|
|
? card
|
|
: (activity && activity.cardId
|
|
? { _id: activity.cardId, boardId: activity.boardId }
|
|
: null);
|
|
const url = target ? buildCardRelativeUrl(target, board) : undefined;
|
|
|
|
return {
|
|
title,
|
|
url: url || null,
|
|
archived: !!(card && card.archived),
|
|
fromActivity: !liveTitle,
|
|
};
|
|
}
|
|
|
|
module.exports = { activityCardLinkData, recordedTitle };
|