mirror of
https://github.com/wekan/wekan.git
synced 2026-11-20 15:45:01 -05:00
Behind a reverse proxy the DDP connection can drop and come back while a card's link is still loading (a WebSocket upgrade the proxy refuses, SockJS falling back). Every subscription re-runs on the way back, one answers before the resumed login with nothing, and the card leaves Minimongo for a moment. #3114's close-on-removal took that moment for a deletion: it closed the card and went to the board's address. The window now waits while the subscription, the connection or the login is settling, and when the card looks gone with everything settled, asks the server (cards.openCardAvailable, the 'card' publication's own rule, now one function in server/lib/openCardAccess.js) and closes only on its no, if Minimongo still agrees. A card really deleted, archived or moved elsewhere still closes. Not reproduced here: no proxy in this environment; the browser test drops and restores the connection. Thanks to brlin-tw and xet7 ! Fixes #6808.
22 lines
1.1 KiB
JavaScript
22 lines
1.1 KiB
JavaScript
import { ReactiveCache } from '/imports/reactiveCache';
|
|
import { findWhere } from '/imports/lib/collectionHelpers';
|
|
|
|
// Whether `userId` may read the card `cardId`, and which board it is on - the
|
|
// rule of the 'card' publication (server/publications/cards.js), here once so
|
|
// that the publication and the opened card's #6808 check cannot disagree: the
|
|
// card exists and has a board, the board is visible to the user, and an
|
|
// assigned-only member reads only the cards assigned to them.
|
|
export async function readableCard(userId, cardId) {
|
|
const card = await ReactiveCache.getCard({ _id: cardId });
|
|
if (!card || !card.boardId) return null;
|
|
const board = await ReactiveCache.getBoard({ _id: card.boardId });
|
|
if (!board || !board.isVisibleBy({ _id: userId })) return null;
|
|
if (userId && board.members) {
|
|
const member = findWhere(board.members, { userId, isActive: true });
|
|
if (member && (member.isNormalAssignedOnly || member.isCommentAssignedOnly || member.isReadAssignedOnly)) {
|
|
if (!card.assignees || !card.assignees.includes(userId)) return null;
|
|
}
|
|
}
|
|
return card;
|
|
}
|