mirror of
https://github.com/wekan/wekan.git
synced 2026-11-25 04:49:41 -05:00
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.
75 lines
3.5 KiB
JavaScript
75 lines
3.5 KiB
JavaScript
'use strict';
|
|
|
|
import { parseCardKey } from './boardKey.js';
|
|
|
|
// Pure helpers for board card search. Extracted from models/boards.js
|
|
// (Board.searchCards) so the query it builds is unit-testable without Meteor.
|
|
//
|
|
// #5680 (can't search numbers in custom fields): "number" and "currency" custom
|
|
// fields store their value as a JS Number (the inputs save `parseInt(...)` /
|
|
// `Number(...)`), but the search only matched custom fields with
|
|
// `{ value: <regex> }`. A MongoDB / Minimongo regex only matches STRING values,
|
|
// so it silently skipped every numeric custom field — searching a card's
|
|
// transaction number (e.g. 2025001) or currency amount (e.g. 123) never found
|
|
// it. We add an exact numeric-equality clause when the term parses to a plain
|
|
// finite number, so numeric custom fields match too. (Card search runs against
|
|
// Minimongo on the client, which — like MongoDB — cannot regex a numeric field,
|
|
// so equality is the correct cross-environment match rather than `$toString`.)
|
|
|
|
// Parse a search term into a Number the way the number/currency custom-field
|
|
// inputs store their value (a comma is accepted as a decimal separator, matching
|
|
// the currency input's `value.replace(',', '.')`). Returns null when the term is
|
|
// not a plain number, so we never widen a text search into an accidental match.
|
|
function parseNumericSearchTerm(term) {
|
|
if (typeof term !== 'string') return null;
|
|
const trimmed = term.trim();
|
|
if (trimmed === '') return null;
|
|
const normalized = trimmed.replace(',', '.');
|
|
// Require a plain decimal number. This rejects things Number() would otherwise
|
|
// coerce (Number('') === 0, Number('0x1f') === 31, Number('1e3') === 1000) so
|
|
// only genuine numeric terms add the numeric clause.
|
|
if (!/^[+-]?(\d+(\.\d+)?|\.\d+)$/.test(normalized)) return null;
|
|
const n = Number(normalized);
|
|
return Number.isFinite(n) ? n : null;
|
|
}
|
|
|
|
// Build the `$or` clause array for a board card search on `term`. `term` is
|
|
// expected to be a trimmed, non-empty string (Board.searchCards guards that).
|
|
function buildCardSearchOr(term, { boardKey = null } = {}) {
|
|
const regex = new RegExp(term, 'i');
|
|
const or = [
|
|
{ title: regex },
|
|
{ description: regex },
|
|
{ customFields: { $elemMatch: { value: regex } } },
|
|
];
|
|
const numeric = parseNumericSearchTerm(term);
|
|
if (numeric !== null) {
|
|
// #5680: also match numeric custom fields (number / currency) by value.
|
|
or.push({ customFields: { $elemMatch: { value: numeric } } });
|
|
}
|
|
// #2449/#2450: the card's own KEY-7, on its board.
|
|
const byKey = parseCardKey(term);
|
|
if (byKey && boardKey && byKey.key === boardKey) or.push({ cardNumber: byKey.number });
|
|
return or;
|
|
}
|
|
|
|
// #3841: board search must also find cards whose match is only in a COMMENT,
|
|
// not just title/description/custom fields. `comments` is a plain array of
|
|
// `{ cardId, text }` (as pulled from the CardComments collection for the
|
|
// current board); returns the de-duplicated list of `cardId`s whose comment
|
|
// text matches `term`, using the SAME case-insensitive regex the rest of the
|
|
// card search uses (reuses `buildCardSearchOr`'s matching rule rather than a
|
|
// second implementation of "does this term match this text").
|
|
function matchingCommentCardIds(comments, term) {
|
|
const regex = new RegExp(term, 'i');
|
|
const ids = new Set();
|
|
(comments || []).forEach(comment => {
|
|
if (comment && typeof comment.text === 'string' && regex.test(comment.text)) {
|
|
ids.add(comment.cardId);
|
|
}
|
|
});
|
|
return Array.from(ids);
|
|
}
|
|
|
|
export { parseNumericSearchTerm, buildCardSearchOr, matchingCommentCardIds };
|