mirror of
https://github.com/wekan/wekan.git
synced 2026-11-20 21:45:01 -05:00
When SMTP accepts a rule email for only some recipients, or its answer is lost, the attempt stays unconfirmed and WeKan never sends it again by itself. Admin Panel -> Problems -> Recovery now shows each recipient as accepted or not confirmed, and an administrator can resend to the unconfirmed recipients only (same headers, narrowed SMTP envelope), mark the attempt sent, or drop it. A drop completes the rule stage without mail. Decisions wait ten minutes after the attempt started, longer than any SMTP send can last, are one immutable record per attempt, and are serialized per command across server processes. A resend records its intent before SMTP, so an interrupted one is shown as in progress rather than repeated silently. The offline acceptance tool and the online decision exclude each other. Unit, MongoDB integration and source tests cover resend, partial resend, mark sent, drop, the quarantine and the refusals; a Playwright case covers review and drop in the Admin Panel. New interface text is in English, pending translation. Thanks to xet7 !
52 lines
3.7 KiB
JavaScript
52 lines
3.7 KiB
JavaScript
'use strict';
|
|
// #2713: a real partial dispatch on MongoDB records who accepted; after the
|
|
// quarantine an administrator resends to the rest only, or drops the attempt
|
|
// and the stage completes without mail.
|
|
const { test } = require('node:test');
|
|
const assert = require('node:assert/strict');
|
|
const { MongoClient, ObjectId } = require('mongodb');
|
|
const { prepareRulePlan } = require('../../server/lib/syncRulePlan');
|
|
const { ensureRuleEmailCommand } = require('../../server/lib/syncRuleEmailCommand');
|
|
const { dispatchRuleEmail: dispatch } = require('../../server/lib/syncRuleEmailDispatch');
|
|
const R = require('../../server/lib/syncRuleEmailResolution');
|
|
const uri = process.env.WEKAN_SYNC_TEST_MONGO_URL, composerPath = process.env.WEKAN_TEST_MAILCOMPOSER;
|
|
async function fixture(t) {
|
|
const client = await new MongoClient(uri).connect(), db = client.db(`rule_resolution_${new ObjectId().toHexString()}`);
|
|
t.after(async () => { await db.dropDatabase(); await client.close(); });
|
|
const f = { activity: { _id: 'a', boardId: 'b', cardId: 'c', userId: 'u' }, effectId: 'a'.repeat(64), index: 0,
|
|
assertCurrent: async () => {}, attempts: db.collection('attempts'), commands: db.collection('commands'),
|
|
outcomes: db.collection('outcomes'), resolutions: db.collection('resolutions'), MailComposer: require(composerPath), sent: [] };
|
|
f.plan = await prepareRulePlan({ ...f, selectRules: async () => [{ _id: 'r', boardId: 'b', actionId: 'a', triggerId: 't' }],
|
|
readAction: async () => ({ _id: 'a', actionType: 'sendEmail' }) });
|
|
f.command = await ensureRuleEmailCommand({ ...f, prepare: async () => ({
|
|
to: 'One <one@example.org>, two@example.org', from: 'sender@example.org', subject: 'Subject', text: 'Body' }) });
|
|
f.partial = async mail => { f.sent.push(mail); return { accepted: ['one@example.org'], rejected: ['two@example.org'] }; };
|
|
return f;
|
|
}
|
|
const later = () => new Date(Date.now() + R.QUARANTINE_MS + 1000);
|
|
|
|
test('partial dispatch, then resend to the unconfirmed recipient only', { skip: !uri || !composerPath }, async t => {
|
|
const f = await fixture(t);
|
|
await assert.rejects(dispatch({ ...f, send: f.partial }), /delivery-unconfirmed/);
|
|
assert.deepEqual((await f.outcomes.findOne({ _id: f.command._id })).accepted, ['one@example.org']);
|
|
await assert.rejects(dispatch({ ...f, send: () => assert.fail('never resent automatically') }), /delivery-uncertain/);
|
|
const detail = await R.ruleEmailRecoveryDetail({ ...f, commandId: f.command._id, now: later });
|
|
assert.deepEqual(detail.recipients.map(r => r.status), ['accepted', 'unconfirmed']);
|
|
const result = await R.resendUnconfirmedRuleEmail({ ...f, commandId: f.command._id, operator: 'admin', now: later,
|
|
send: async mail => { f.sent.push(mail); return { accepted: mail.envelope.to }; } });
|
|
assert.equal(result.status, 'sent');
|
|
assert.deepEqual(f.sent[1].envelope.to, ['two@example.org']);
|
|
assert.equal((await f.attempts.findOne({ _id: f.command._id })).state, 'sent');
|
|
assert.equal(await dispatch({ ...f, send: () => assert.fail('already sent') }), f.command.invocationId);
|
|
});
|
|
|
|
test('drop completes the stage without mail and cannot be reversed', { skip: !uri || !composerPath }, async t => {
|
|
const f = await fixture(t);
|
|
await assert.rejects(dispatch({ ...f, send: f.partial }));
|
|
await R.resolveRuleEmailAttempt({ ...f, commandId: f.command._id, decision: 'drop', operator: 'admin', now: later });
|
|
assert.equal(await dispatch({ ...f, send: () => assert.fail('dropped mail is not sent') }), f.command.invocationId);
|
|
await assert.rejects(R.resolveRuleEmailAttempt({ ...f, commandId: f.command._id, decision: 'mark-sent', operator: 'admin', now: later }),
|
|
/already-resolved/);
|
|
assert.equal(await f.resolutions.countDocuments({ decision: 'drop' }), 1);
|
|
});
|