Files
wekan/models/lib/ruleActingUser.js
T
Lauri Ojansivu 6f79e87914 Add the missing acting-user module and UI button for rule "add member" (#2522).
The "add member" rule action's acting-user option (issue #2522 - "add
whoever just moved the card as a member") landed on main missing its
shared module: server/rulesHelper.js and cardActions.js already import
RULE_ACTING_USER_SENTINEL/resolveActingUserId from
/models/lib/ruleActingUser, but that file was never committed, breaking
the import on main. It also landed without the actual UI button that
saves the sentinel action.

models/lib/ruleActingUser.js resolves "who triggered this rule" from
activity.userId - the exact same source buildRuleVars() already uses for
the {username} template variable (#3304/#3301) - so both call one shared
function instead of two implementations of the same concept.
cardActions.jade gets the missing trigger button, wired to the existing
js-add-actinguser-member-action handler in cardActions.js.

tests/ruleAddMemberActingUser.test.cjs pins the sentinel resolution, that
rulesHelper.js and buildRuleVars() both call the one shared resolver (with
a negative, whole-tree source-pattern check that no other file
re-implements the same activity.userId shape), that the ordinary
fixed-member path is unaffected, the client/jade wiring, and that every
locale file has a real (non-English-placeholder) translation of the new
label. tests/ruleRemoveMemberAction.test.cjs and
tests/rulesApiTriggerNormalize.test.cjs are updated for the addMember
block's new if/else shape around the sentinel check.

Thanks to arisjr and xet7 !

Closes #2522,
2026-09-10 20:46:04 +03:00

22 lines
1011 B
JavaScript

// #2522: shared "who triggered this rule" concept, used by the "add member"
// action's acting-user option. Reuses the exact activity.userId source
// server/rulesHelper.js's buildRuleVars() already resolves for the
// {username} template variable (#3304/#3301) - this file is the ONE place
// both call, so there is no second acting-user-resolution mechanism.
// Sentinel stored as an addMember action's `username` field to mean "resolve
// to whichever user's action fired this rule at execution time" instead of a
// fixed board member.
export const RULE_ACTING_USER_SENTINEL = '_actinguser_';
// The activity that triggered a rule always carries the id of the user who
// performed the triggering action as `activity.userId` (a '*' means a
// system/no-user activity, e.g. some scheduled actions, so there is no
// acting user to resolve to).
export function resolveActingUserId(activity) {
if (activity && activity.userId && activity.userId !== '*') {
return activity.userId;
}
return null;
}