mirror of
https://github.com/wekan/wekan.git
synced 2026-11-24 09:59:47 -05:00
A rule email prepared before commands recorded their source (no source binding), or one with card Details whose binding predates the related- source chain, is refused by dispatch and was waiting for a recovery that did not exist. Admin Panel -> Problems -> Recovery now lists them with their board, card, recipients, subject and reason. Nothing runs them automatically. An administrator re-binds one - its content is prepared again from the card as it is now, after re-checking that the rule's author is enabled with write access and that the rule and action are unchanged - or discards it, which records a dropped attempt so the rule stage completes without mail. Each decision writes one immutable audit record, is serialized per command, and is final once an attempt exists. Unit, MongoDB integration and source tests cover listing, re-bind, discard and every refusal, and pin that only the admin methods call them; a Playwright case covers review and discard. New interface text is in English, pending translation. Thanks to xet7 !
31 lines
2.2 KiB
JavaScript
31 lines
2.2 KiB
JavaScript
'use strict';
|
|
// Legacy rule email review on a real MongoDB: the list query finds unbound
|
|
// commands, skips ones already attempted, and a discard is final.
|
|
const { test } = require('node:test');
|
|
const assert = require('node:assert/strict');
|
|
const { MongoClient, ObjectId } = require('mongodb');
|
|
const { canonical, sha256 } = require('../../models/lib/changeHistoryIntegrity');
|
|
const L = require('../../server/lib/syncRuleEmailLegacy');
|
|
const uri = process.env.WEKAN_SYNC_TEST_MONGO_URL;
|
|
test('list, skip attempted, discard once', { skip: !uri }, async t => {
|
|
const client = await new MongoClient(uri).connect(), db = client.db(`rule_legacy_${new ObjectId().toHexString()}`);
|
|
t.after(async () => { await db.dropDatabase(); await client.close(); });
|
|
const f = { commands: db.collection('commands'), plans: db.collection('plans'), attempts: db.collection('attempts'),
|
|
resolutions: db.collection('resolutions'), operator: 'admin' };
|
|
const plan = { version: 1, actions: [{ id: 'i'.repeat(64), rule: { _id: 'r' }, action: { _id: 'a', actionType: 'sendEmail' } }] };
|
|
await f.plans.insertOne({ _id: 'p', plan, checksum: sha256(canonical(plan)) });
|
|
const command = (id, extra = {}) => ({ _id: id, version: 1, planId: 'p', invocationId: 'i'.repeat(64), boardId: 'b', cardId: 'c',
|
|
checksum: 'c'.repeat(64), mail: { to: 'x@example.org', from: 'w@example.org', subject: 'S', text: 'secret body' }, ...extra });
|
|
await f.commands.insertMany([command('1'.repeat(64)), command('2'.repeat(64)),
|
|
command('3'.repeat(64), { version: 2, sourceBinding: { version: 5 } })]);
|
|
await f.attempts.insertOne({ _id: '2'.repeat(64), state: 'sending' });
|
|
const list = await L.listLegacyRuleEmailCommands(f);
|
|
assert.deepEqual(list.rows.map(row => row.commandId), ['1'.repeat(64)]);
|
|
assert.ok(!JSON.stringify(list).includes('secret body'), 'the body is not listed');
|
|
await L.discardLegacyRuleEmailCommand({ ...f, commandId: '1'.repeat(64) });
|
|
assert.equal((await f.attempts.findOne({ _id: '1'.repeat(64) })).state, 'dropped');
|
|
await assert.rejects(L.discardLegacyRuleEmailCommand({ ...f, commandId: '1'.repeat(64) }), /attempt-exists/);
|
|
assert.equal(await f.resolutions.countDocuments({ decision: 'legacy-discard' }), 1);
|
|
assert.equal((await L.listLegacyRuleEmailCommands(f)).total, 0);
|
|
});
|