mirror of
https://github.com/wekan/wekan.git
synced 2026-11-24 09:59:47 -05:00
Production log (v13.13): "scheduledRules: error running trigger ... User ID is required in cards insertAsync" on every run. Scheduled rules, auto-archive and attachment retention acted as board.createdBy, but the Boards schema has no createdBy, so it was undefined on every board: a scheduled rule ran as nobody and its "create card" action always failed. models/lib/boardActor.js names the board's first active admin, else its first active member. The rule's createCard action also passes its acting user as the card's author, since a scheduled run has no method user for the schema's autoValue. tests/boardActor.test.cjs scans the tree so that nothing reads board.createdBy again. Thanks to xet7 !
23 lines
1.1 KiB
JavaScript
23 lines
1.1 KiB
JavaScript
'use strict';
|
|
|
|
// Who a board's own timed work is recorded as and acts as: scheduled rules
|
|
// (server/scheduledRules.js), auto-archive (server/autoArchiveCards.js) and the
|
|
// attachment retention's soft delete (models/lib/attachmentRetention.js).
|
|
//
|
|
// They all used `board.createdBy`, but the Boards schema has no such field, so
|
|
// it was undefined on every board: a scheduled rule ran as nobody, and its
|
|
// "create card" action failed every time with "User ID is required in cards
|
|
// insertAsync". The board's first active admin is who answers for the board
|
|
// (an admin is never restricted by a list exception either); a board without
|
|
// one falls back to its first active member, and a board with no active member
|
|
// to nobody. Pure: tests/boardActor.test.cjs.
|
|
function boardActorId(board) {
|
|
const members = board && Array.isArray(board.members) ? board.members : [];
|
|
const active = members.filter(m => m && typeof m.userId === 'string' && m.userId && m.isActive === true);
|
|
const admin = active.find(m => m.isAdmin === true);
|
|
if (admin) return admin.userId;
|
|
return active.length ? active[0].userId : null;
|
|
}
|
|
|
|
module.exports = { boardActorId };
|