Files
wekan/tests/instanceEditing.test.cjs
T
Lauri Ojansivu 7595727917 Boards every signed-in user may edit, per-list permissions, board keys and shared labels.
A board can let every signed-in user edit it, when Admin Panel / Settings /
Visibility allows it: a non-member then comments, edits and moves cards like
a Normal member, and their first edit makes them one. Board-wide settings
stay members-only.

Lists can allow or refuse editing and commenting per role (list menu, board
admins): built-in roles, custom roles and, on an open board, everyone signed
in. The server applies it to card, checklist, attachment and comment writes
and to moves into the list; the REST API honours a list's refusal on every
per-list card route. A direct client write of the setting is refused and
shown in Admin Panel / Problems.

Every board has a key, unique in the instance, suggested from its title and
set for existing boards at startup; card numbers show as KEY-7 and searching
for KEY-7 finds the card.

Shared labels in Admin Panel / Labels, for every board or an organization's
or team's boards; a board uses them beside its own, and a rename or colour
change reaches every board that uses it.

New strings translated in all languages. Low confidence: chr, tlh, wal, ay,
ace, nah, gn, iu, zgh, rup, wo, se, ff, tig, vo, bm, kl, bua, nap, mai, to,
ks, qu, bo, fj, haw, om, ss, ts, ve-PP, lld, scn.

Thanks to Meeques, justinr1234, tiFabGrinch, ejlkemper and xet7 !

Fixes #4575,
Fixes #4527,
Fixes #2449,
Fixes #2450,
Fixes #2761,
Fixes #4698.
2026-10-14 09:28:45 +03:00

65 lines
4.0 KiB
JavaScript

'use strict';
// #4575: a board every signed-in user may edit. Only when Admin Panel allows
// it, only on an open board ('instance' or 'public') whose admin turned it on;
// a non-member then may write, comment and move like a Normal member - never
// manage the board - and their first edit makes them one. A member keeps their
// own role, a removed member stays removed, and background automation (rules,
// webhooks, inbound email, list sync) is never given a non-member's rights.
// Run: node tests/instanceEditing.test.cjs
const { test } = require('node:test');
const assert = require('node:assert/strict');
const fs = require('node:fs');
const path = require('node:path');
const ROOT = path.join(__dirname, '..');
const read = rel => fs.readFileSync(path.join(ROOT, rel), 'utf8');
const caps = require('../models/lib/boardRoleCapabilities');
const board = over => ({ permission: 'instance', allowsInstanceEditing: true, members: [{ userId: 'm', isActive: true, isReadOnly: true }], ...over });
test('a non-member edits like a Normal member, and only then', () => {
caps.setInstanceEditingLookup(() => true);
try {
for (const cap of ['write', 'comment', 'moveCard']) assert.equal(caps.memberCan(board(), 'stranger', cap), true, cap);
assert.equal(caps.memberCan(board(), 'stranger', 'manageBoard'), false, 'never the board itself');
assert.equal(caps.memberCan(board({ permission: 'public' }), 'stranger', 'write'), true);
// Negative, each condition alone:
assert.equal(caps.memberCan(board({ permission: 'private' }), 'stranger', 'write'), false, 'a private board');
assert.equal(caps.memberCan(board({ allowsInstanceEditing: false }), 'stranger', 'write'), false, 'the board did not turn it on');
assert.equal(caps.memberCan(board({ archived: true }), 'stranger', 'write'), false, 'an archived board');
assert.equal(caps.memberCan(board(), null, 'write'), false, 'not signed in');
assert.equal(caps.memberCan(board().members, 'stranger', 'write'), false, 'given only the members: no board settings, no grant');
assert.equal(caps.memberCan(board(), 'm', 'write'), false, 'a member keeps their own role (read-only here)');
assert.equal(caps.memberCan(board({ members: [{ userId: 'gone', isActive: false }] }), 'gone', 'write'), false,
'a member a board admin removed stays removed');
} finally {
caps.setInstanceEditingLookup(null);
}
assert.equal(caps.memberCan(board(), 'stranger', 'write'), false, 'Admin Panel did not allow it');
});
test('interactive checks pass the board; background automation passes only members', () => {
for (const [file, re] of [
['server/lib/utils.js', /memberCan\(board, userId, 'write'\)/],
['server/lib/utils.js', /memberCan\(board, userId, 'comment'\)/],
['client/lib/utils.js', /memberCan\(board, userId, capability\)/],
['models/lib/boardMutationGuard.js', /memberCan\(board, userId, 'write'\)/],
]) assert.match(read(file), re, file);
for (const file of ['server/notifications/storedRulePlans.js', 'server/notifications/storedWebhooks.js', 'server/lib/inboundEmailUserMatch.js',
'server/lib/listSyncApplication.js', 'server/lib/syncWebhookAccess.js', 'models/importZip.js']) {
assert.doesNotMatch(read(file), /memberCan\(board, /, `${file}: automation never gets a non-member's rights`);
}
});
test('the first edit joins; Admin Panel and the board each have their switch, off by default', () => {
const join = read('server/instanceEditing.js');
assert.match(join, /if \(!board \|\| !instanceEditable\(board\)\) return;/);
assert.match(join, /await board\.addMember\(userId\);/);
assert.match(read('server/models/collectionBootstrap.js'), /\{ _id: 'tableVisibilityMode-allowInstanceEditing' \},\n\s+\{ \$setOnInsert: \{ booleanValue: false/);
assert.match(read('client/components/settings/settingBody.jade'), /#accounts-allowInstanceEditing/);
assert.match(read('client/components/boards/boardHeader.jade'), /js-toggle-instance-editing/);
assert.match(read('models/boards.js'), /allowsInstanceEditing: \{/);
});