mirror of
https://github.com/wekan/wekan.git
synced 2026-11-24 18:10:06 -05:00
A third sibling of My Cards / My Due Cards: every attachment the current user has uploaded, across every board they can see (their own boards, and public ones), in one place. The menu entry sits right after My Due Cards (client/components/users/userHeader.jade), and its own route (/my-attachments, config/router.js) renders a dedicated page (client/components/main/myAttachments.jade/.js) grouped board > swimlane > list > card, reusing the same "open the card in place" popup mechanism myCards.js's .js-minicard handler uses (#3640) so a click never navigates away and loses the reader's place in a list spanning many boards. The new `myAttachments` publication (server/publications/cards.js) filters by BOTH the uploader (this user's own attachments only) and board visibility, using the same boardVisibilitySelectors() the All Boards list and the board publication already use (GHSA-gwc4-fw7p-gw58) rather than a hand-rolled duplicate - so an attachment on a board the user cannot see is never published, even if its userId field somehow matches. The query shape itself lives in a small pure module, models/lib/myAttachmentsQuery.js, so it is unit-tested without a database. Thanks to Jieiku and xet7 ! Closes #3461,
55 lines
2.0 KiB
JavaScript
55 lines
2.0 KiB
JavaScript
// Pure, dependency-free construction of the "My Attachments" (#3461) query:
|
|
// which attachments the CURRENT user may see on their own listing page - only
|
|
// what THEY uploaded (`userId`), and only on a board they can see (a boardId
|
|
// from the visible set the caller already computed with
|
|
// models/lib/boardVisibilitySelectors.js). No Meteor imports, so it is unit
|
|
// tested directly with plain Node (tests/myAttachments.test.cjs).
|
|
//
|
|
// Kept separate from server/publications/cards.js so the SHAPE of the query -
|
|
// "mine, and only on a board I can see" - is checkable without a database,
|
|
// the same way dueCards/myCards' board-visibility filtering is checkable by
|
|
// reading the source in tests/databaseQueryBounds.test.cjs.
|
|
|
|
const DEFAULT_LIMIT = 200;
|
|
const MAX_LIMIT = 500;
|
|
|
|
/**
|
|
* @param {string} userId the current user - the UPLOADER, not just the viewer
|
|
* @param {string[]} visibleBoardIds every board this user may currently see
|
|
* (public boards + boards they belong to; see boardVisibilitySelectors.js)
|
|
* @return {object|null} the Mongo selector, or null when there is nothing to
|
|
* query - no signed-in user, or a user who can see no board at all
|
|
*/
|
|
function myAttachmentsSelector(userId, visibleBoardIds) {
|
|
if (!userId || typeof userId !== 'string') return null;
|
|
const boardIds = Array.isArray(visibleBoardIds)
|
|
? visibleBoardIds.filter(id => typeof id === 'string' && id)
|
|
: [];
|
|
if (boardIds.length === 0) return null;
|
|
|
|
return {
|
|
userId,
|
|
'meta.boardId': { $in: boardIds },
|
|
};
|
|
}
|
|
|
|
/**
|
|
* Clamp caller-supplied paging to a safe range, the same way dueCards does.
|
|
* @param {number} [limit]
|
|
* @param {number} [skip]
|
|
* @return {{limit: number, skip: number}}
|
|
*/
|
|
function myAttachmentsPageOptions(limit, skip) {
|
|
return {
|
|
limit: Math.max(1, Math.min(Math.floor(limit) || DEFAULT_LIMIT, MAX_LIMIT)),
|
|
skip: Math.max(0, Math.floor(skip) || 0),
|
|
};
|
|
}
|
|
|
|
module.exports = {
|
|
DEFAULT_LIMIT,
|
|
MAX_LIMIT,
|
|
myAttachmentsSelector,
|
|
myAttachmentsPageOptions,
|
|
};
|