mirror of
https://github.com/wekan/wekan.git
synced 2026-11-24 09:59:47 -05:00
A board's visibility can now be "Signed-in users" (permission 'instance'): every signed-in user of this WeKan reads it, nobody signed out does, and only its members edit it, as on a public board. One pure rule, models/lib/boardPermission.js, feeds isVisibleBy and the shared selector builder, so the board and card publications, All Boards, search, exports, attachments, backgrounds, watching, filter presets and rule destinations follow it. Anonymous paths - link previews, public avatars, the no-token export branch and archived lists - stay public-only, and a source suite lists every remaining public-only check so a new one is reviewed. The Public page and GET /api/boards list instance boards for a signed-in caller only; "private boards only" refuses them like public ones; a WeKan export keeps the setting on import. New strings are English, pending Transifex. Fixes #3249, Thanks to relikd and xet7 !
59 lines
2.7 KiB
JavaScript
59 lines
2.7 KiB
JavaScript
'use strict';
|
|
|
|
import boardPermission from './boardPermission.js';
|
|
|
|
const { readableWithoutMembership } = boardPermission;
|
|
|
|
// Pure helpers deciding which boards may be picked as a destination in the
|
|
// IFTTT-Rules "move card to the board" / "link card to the board" selectors.
|
|
// Extracted from client/components/rules/actions/boardActions.js so the choice
|
|
// is unit-testable without Meteor.
|
|
//
|
|
// #5698 (Impossible to select other board in rules): the board dropdown used to
|
|
// filter the (already access-scoped) client cache with `'members.userId': me`,
|
|
// i.e. it only kept boards where the user has a DIRECT member entry. A user who
|
|
// reaches a board through an Organization, Team or email-domain share — but is
|
|
// not listed individually in board.members — got an EMPTY dropdown (not even the
|
|
// current board showed up), while a colleague who was a direct member saw the
|
|
// boards. This mirrors the board-list publication / Boards.userBoards() rule:
|
|
// public OR active member OR active org OR active team OR active domain.
|
|
|
|
function hasActive(list, predicate) {
|
|
return Array.isArray(list) && list.some(entry => entry && predicate(entry));
|
|
}
|
|
|
|
// Does `board` match `ctx`'s visibility? ctx = { userId, orgIds, teamIds,
|
|
// emailDomains } — the last three are plain id arrays (empty when absent).
|
|
function boardVisibleToUserContext(board, ctx) {
|
|
if (!board || !ctx) return false;
|
|
// #3249: public for anybody, 'instance' for a signed-in user.
|
|
if (readableWithoutMembership(board.permission, !!ctx.userId)) return true;
|
|
if (hasActive(board.members, m => m.userId === ctx.userId && !!m.isActive)) {
|
|
return true;
|
|
}
|
|
const inSet = (list, key, ids) =>
|
|
Array.isArray(ids) &&
|
|
hasActive(list, entry => !!entry.isActive && ids.includes(entry[key]));
|
|
if (inSet(board.orgs, 'orgId', ctx.orgIds)) return true;
|
|
if (inSet(board.teams, 'teamId', ctx.teamIds)) return true;
|
|
if (inSet(board.domains, 'domain', ctx.emailDomains)) return true;
|
|
return false;
|
|
}
|
|
|
|
// May this board appear in the rules board selector for `ctx`?
|
|
// Excludes archived boards, non-'board' types (e.g. template containers), the
|
|
// user's own templates board, and internal caret-wrapped helper boards
|
|
// (`^Subtasks^` etc.), then requires the board to be visible to the user.
|
|
function canSelectBoardInRules(board, ctx, templatesBoardId) {
|
|
if (!board || !ctx) return false;
|
|
if (board.archived) return false;
|
|
if (board.type && board.type !== 'board') return false;
|
|
if (typeof board.title === 'string' && /^\^.*\^$/.test(board.title)) {
|
|
return false;
|
|
}
|
|
if (templatesBoardId && board._id === templatesBoardId) return false;
|
|
return boardVisibleToUserContext(board, ctx);
|
|
}
|
|
|
|
export { canSelectBoardInRules, boardVisibleToUserContext };
|