Files
wekan/client/components/rules/actions/mailActions.js
T
Lauri Ojansivu 75e260966b Rule emails: pick board members for To from a list with autocomplete.
The send-email action gets a member picker under To: typing filters the
board's active members by user name or full name, and a pick adds
@username to To. Addresses are still typed into To as before. When the
rule runs, each @username becomes that member's current email address,
so the rule - and whoever edits it - holds a user name, never somebody's
address, and a member who changes address is still reached. A @name of
somebody who is not an active member of the board, or has no address, is
dropped rather than sent as text, and nobody is mailed twice.

models/lib/ruleEmailMembers.js holds the parsing, the choices and the
expansion; tests/ruleEmailMembers.test.cjs covers them, non-members,
duplicates, an address with @ inside, and that the picker never reads an
email address. rulesHelper imports it, so the ruleEmailFailure harness,
which runs rulesHelper without require, is given it as it is given
ruleParts. The new strings are English placeholders until the next
translation pass.

Thanks to chenghongxi and xet7 !

Fixes #2435.
2026-10-14 14:30:10 +03:00

56 lines
2.2 KiB
JavaScript

import { Utils } from '/client/lib/utils';
import { saveRuleTriggerAction } from '/client/components/rules/rulesSaveHelper';
import { ReactiveCache } from '/imports/reactiveCache';
const { memberChoices, addRecipient } = require('/models/lib/ruleEmailMembers');
Template.mailActions.onCreated(function () {
this.memberQuery = new ReactiveVar('');
});
// #2435: the board's active members, for the To field's member picker.
Template.mailActions.helpers({
memberChoices() {
const board = Utils.getCurrentBoard();
const ids = ((board && board.members) || []).filter(m => m && m.isActive !== false).map(m => m.userId);
const members = ReactiveCache.getUsers({ _id: { $in: ids } })
.map(u => ({ username: u.username, fullname: (u.profile || {}).fullname }));
return memberChoices(members, Template.instance().memberQuery.get());
},
});
Template.mailActions.events({
'input .js-email-to-member'(event, tpl) {
tpl.memberQuery.set(event.currentTarget.value);
},
// A choice from the list (or a typed @username) goes into To, once.
'change .js-email-to-member'(event, tpl) {
const value = String(event.currentTarget.value || '').trim();
if (!/^@[A-Za-z0-9._-]+$/.test(value)) return;
const to = tpl.find('#email-to');
to.value = addRecipient(to.value, value);
event.currentTarget.value = '';
tpl.memberQuery.set('');
},
'click .js-mail-action'(event, tpl) {
const emailTo = tpl.find('#email-to').value;
const emailSubject = tpl.find('#email-subject').value;
const emailMsg = tpl.find('#email-msg').value;
const data = Template.currentData();
const trigger = data.triggerVar.get();
const ruleName = data.ruleName.get();
const boardId = Session.get('currentBoard');
const desc = Utils.getTriggerActionDesc(event, tpl);
saveRuleTriggerAction(boardId, data.ruleId, ruleName, trigger, {
actionType: 'sendEmail',
emailTo,
emailSubject,
emailMsg,
includeCardDetails: tpl.find('#email-card-details').checked,
includeChecklistsAndComments: tpl.find('#email-discussion').checked,
includeAttachments: tpl.find('#email-attachments').checked,
boardId,
desc,
});
},
});