Files
wekan/server/notifications/watch.js
T
Lauri Ojansivu 8ec78bb14c Archived cards stay archived, and a silent watch button says why.
Three email reports, 2026-08-13.

"PREVIOUSLY ARCHIVED CARDS (SOME SEVERAL YEARS OLD) HAVE REAPPEARED. THESE
CARDS HAVE INCORRECTLY BEEN PLACED IN THE TOP SWIMLANE."

The schema upgrade's swimlane rescue treated "this card's swimlane is archived"
as breakage and moved the card to the board's first VISIBLE swimlane. But
archiving a swimlane is how a whole swimlane is put away: its cards stay where
they are, archived: false, hidden because the swimlane is hidden. So every card
anybody had ever archived that way was hoisted back into view, years later, in
the top swimlane.

A card is orphaned when its swimlane does not EXIST, or belongs to another
board - #1959, which is still rescued. loadVisibleSwimlanes now also returns
existsById, and both the check and the write use it.

#1971, the issue the sweep cited, is about cards ADDED in List view landing in
an archived swimlane, and that is fixed where cards are created:
getDefaultSwimline() picks a non-archived swimlane. It never needed a sweep
over data somebody archived on purpose. The two guards that pinned the sweep
now pin the opposite, with the reason in them.

"SILENT DOES NOT RESPOND. IF WE TRY TO CHANGE IT DOES NOT CHANGE. NOTHING
HAPPENS." (the board's Change watch popup)

Driven against a running WeKan, the popup works for a board MEMBER - level
written, check mark moved, popup closed - and does nothing at all for anybody
who reaches the board another way:

  login as non-member admin: ok
  watch -> ERROR error-board-notAMember

A board is shared four ways: membership, an organisation, a team, and (#5850)
an email domain. Only the first puts anybody in `members`, and the watch method
asked hasMember(). Everyone sharing through an org, a team or a domain could
open the board, see the button, and be refused the moment they used it. It now
asks whether the user may SEE the board, through the same
boardVisibilitySelectors the publications use, so a watch can never be granted
where the board is not visible - and a revoked share (isActive: false) still is
not.

The other half is why nobody could tell: the popup closed on success and did
NOTHING otherwise, so a refusal was indistinguishable from a dead button. It
reports the reason now - the watch feature being off in the Admin Panel, or the
board not being visible - and en.i18n.json gains error-watch-disabled, which
was thrown but never translated. The click also reads its level with String(),
since Blaze can hand back a boxed String that `typeof x === 'string'` refuses.

Thanks to xet7 !
2026-08-13 15:51:25 +03:00

88 lines
3.8 KiB
JavaScript

import { Meteor } from 'meteor/meteor';
import { check, Match } from 'meteor/check';
import { ReactiveCache } from '/imports/reactiveCache';
import { getFeatureFlags } from '/models/lib/featureFlags';
import Boards from '/models/boards';
const { boardVisibilitySelectors } = require('/models/lib/boardVisibilitySelectors');
// True when this user may see this board: public, a member, or an ACTIVE
// organisation / team / email-domain share. Built from the same selectors the
// board publication uses, so the two cannot drift apart.
async function canSeeBoard(userId, board) {
if (!board) return false;
if (board.permission === 'public') return true;
if (!userId) return false;
if (typeof board.hasMember === 'function' && board.hasMember(userId)) return true;
const user = await ReactiveCache.getUser(userId);
if (!user) return false;
const listOf = value => (typeof value === 'string' && value.length ? value.split(',') : []);
const orgIds = typeof user.orgIdsUserBelongs === 'function' ? listOf(user.orgIdsUserBelongs()) : [];
const teamIds = typeof user.teamIdsUserBelongs === 'function' ? listOf(user.teamIdsUserBelongs()) : [];
const emailDomains = typeof user.emailDomains === 'function' ? user.emailDomains() : [];
const visible = await Boards.findOneAsync({
_id: board._id,
$or: boardVisibilitySelectors({ userId, orgIds, teamIds, emailDomains, includePublic: true }),
}, { fields: { _id: 1 } });
return Boolean(visible);
}
Meteor.methods({
async watch(watchableType, id, level) {
check(watchableType, String);
check(id, String);
check(level, Match.OneOf(String, null));
// Admin Panel / Features / Notifications (#5820): the watch feature is
// disabled, so ignore any request to change a watch level.
if (getFeatureFlags().disableWatch) {
throw new Meteor.Error('error-watch-disabled');
}
const userId = this.userId;
let watchableObj = null;
let board = null;
if (watchableType === 'board') {
watchableObj = await ReactiveCache.getBoard(id);
if (!watchableObj) throw new Meteor.Error('error-board-doesNotExist');
board = watchableObj;
} else if (watchableType === 'list') {
watchableObj = await ReactiveCache.getList(id);
if (!watchableObj) throw new Meteor.Error('error-list-doesNotExist');
board = await watchableObj.board();
} else if (watchableType === 'card') {
watchableObj = await ReactiveCache.getCard(id);
if (!watchableObj) throw new Meteor.Error('error-card-doesNotExist');
board = await watchableObj.board();
} else {
throw new Meteor.Error('error-json-schema');
}
// MAY THIS USER SEE THE BOARD - which is not the same question as "is this
// user in board.members", and answering the second one is the bug behind
// "Silent does not respond. If we try to change it does not change. Nothing
// happens."
//
// A board is shared with people four ways: membership, an organisation, a
// team, and (since #5850) an email domain. Only the first puts anybody in
// `members`. Everyone reaching a board through one of the other three could
// open it, see the watch button, choose a level - and have this line throw
// error-board-notAMember, which the popup swallowed (see
// client/components/boards/boardHeader.js). Nothing changed and nothing was
// said, which is exactly how it was reported.
//
// The publications answer the same question with one shared builder
// (models/lib/boardVisibilitySelectors), and so does this: ask the database
// whether this board is among the ones this user may see. It is the same
// rule, so a watch can never be granted where the board itself is not.
if (!(await canSeeBoard(userId, board))) {
throw new Meteor.Error('error-board-notAMember');
}
await watchableObj.setWatcher(userId, level);
return true;
},
});