mirror of
https://github.com/wekan/wekan.git
synced 2026-11-24 09:59:47 -05:00
A card made from a card template, linked from another board, or copied - and a subtask copied with it - took its whole customFields array along: values of another board's fields, of deleted fields, and entries with no field id. The admin-only field guard could not match those to a field of the new card's board, refused the whole card and recorded AdminFieldBleed against the user. copy(), its subtask copies and link() now keep only the values of fields defined on the destination board (models/lib/customFieldsForBoard.cjs), read from the collection rather than the cache, just before the insert. An admin-only value of the destination board is kept, so the guard still decides it. tests/copyForeignCustomFields.test.cjs fails on the code before the fix, and fails on any card cloned from another and inserted without the filter. Thanks to Raymond-Voogt and xet7 ! Fixes #6800,
28 lines
1.3 KiB
JavaScript
28 lines
1.3 KiB
JavaScript
'use strict';
|
|
|
|
// #6800: the custom field values a NEW card may carry onto `boardId` - only
|
|
// values for fields defined on that board.
|
|
//
|
|
// A card copied, made from a card template, linked from another board, or a
|
|
// subtask copied with it, took its whole customFields array along: values of
|
|
// another board's fields, of deleted fields, and entries with no field id at all
|
|
// (old imports). The admin-only field guard (server/lib/adminOnlyCustomFields.js)
|
|
// cannot match such a value to a field of the new card's board, so it refused
|
|
// the whole card and recorded an AdminFieldBleed event against the user, who only
|
|
// saw that no card appeared. Such a value cannot be shown on the new card anyway.
|
|
//
|
|
// getDefinition(fieldId) -> { boardIds } | null, read as it is NOW: the copy may
|
|
// have just shared the field with the destination board (mapCustomFieldsToBoard).
|
|
async function customFieldsForBoard(customFields, boardId, getDefinition) {
|
|
if (!Array.isArray(customFields) || !boardId) return [];
|
|
const kept = [];
|
|
for (const field of customFields) {
|
|
if (!field || typeof field._id !== 'string' || !field._id) continue;
|
|
const definition = await getDefinition(field._id);
|
|
if (definition && Array.isArray(definition.boardIds) && definition.boardIds.includes(boardId)) kept.push(field);
|
|
}
|
|
return kept;
|
|
}
|
|
|
|
module.exports = { customFieldsForBoard };
|