mirror of
https://github.com/wekan/wekan.git
synced 2026-11-24 09:59:47 -05:00
Two of the features other kanban apps call AI, done with plain code
(docs/Features/General/Assistants/Assistants.md):
- A due date typed at the end of a new card's title ("... tomorrow 14:00",
"huomenna klo 14", "friday 9:30", "in 3 days", "23.10.") becomes the card's
due date, read with the browser's own Intl tables so every language works.
A hint under the field shows the date, and its x keeps the words. The
opened card's title reads it too, but only when the title changed.
- Similar cards: letter triples and the Dice coefficient (letter pairs for
scripts without spaces). The add-card form lists up to three close cards,
marking a possible duplicate, and the opened card has a Similar cards
section. The server method applies the board's read rules and the
assigned-only role.
Both are rows of Board Settings / Card and of Admin Panel / Settings /
Visibility / Features / Card fields, so a board admin or a site admin can
hide them. Translated in every language.
Thanks to xet7 !
113 lines
5.9 KiB
JavaScript
113 lines
5.9 KiB
JavaScript
'use strict';
|
|
|
|
// #3967: quick-add's "More options" panel lets description, due date and
|
|
// assignees be filled in BEFORE the card is created, so they travel in the
|
|
// SAME Cards.insert call as the title rather than as separate Cards.update
|
|
// calls made right after. That matters because every watcher-notification
|
|
// email is triggered from a single place — the Activities.after.insert hook
|
|
// in server/models/activities.js, which fires once per Activities document.
|
|
// A bare-title card followed by N field edits creates 1 (createCard) + N
|
|
// activities, i.e. N+1 separate e-mails; a card created with those N fields
|
|
// already set creates exactly 1 (createCard) activity, i.e. 1 e-mail.
|
|
//
|
|
// This is proven two ways:
|
|
// 1. server/models/cards.js's card-creation hook (cardCreation) is shown to
|
|
// insert exactly ONE Activities document per Cards.insert, regardless of
|
|
// how many optional fields the inserted doc carries — it does not loop
|
|
// over doc fields the way the customField update hook does.
|
|
// 2. client/components/lists/listBody.js's addCard() is shown to fold the
|
|
// "More options" description/due date/assignees into the SAME cardFields
|
|
// object passed to the single Cards.insert call, not into a follow-up
|
|
// Cards.update.
|
|
|
|
const assert = require('node:assert/strict');
|
|
const fs = require('node:fs');
|
|
const path = require('node:path');
|
|
|
|
const cardsServerSource = fs.readFileSync(
|
|
path.join(__dirname, '..', 'models/cards.js'),
|
|
'utf8',
|
|
);
|
|
const cardsServerHookSource = fs.readFileSync(
|
|
path.join(__dirname, '..', 'server/models/cards.js'),
|
|
'utf8',
|
|
);
|
|
|
|
// --- 1. Card creation inserts exactly one Activities document -------------
|
|
|
|
const creationStart = cardsServerSource.indexOf('async function cardCreation(userId, doc) {');
|
|
assert.notEqual(creationStart, -1, 'cardCreation must exist');
|
|
const creationEnd = cardsServerSource.indexOf('\nasync function cardRemover', creationStart);
|
|
assert.notEqual(creationEnd, -1);
|
|
const creationBody = cardsServerSource.slice(creationStart, creationEnd);
|
|
|
|
const insertCalls = creationBody.match(/Activities\.insertAsync/g) || [];
|
|
assert.equal(insertCalls.length, 1,
|
|
'positive: card creation inserts exactly one Activities document, ' +
|
|
'no matter how many fields (description, dueAt, assignees, members, ' +
|
|
'labelIds, customFields) were set on the inserted card doc');
|
|
|
|
assert.doesNotMatch(creationBody, /for\s*\(|\.forEach\(|\.map\(/,
|
|
'negative: cardCreation must not loop over the card\'s fields to fire a ' +
|
|
'per-field activity - that loop is what would turn a single insert into ' +
|
|
'several notification emails');
|
|
|
|
// Cards.after.insert calls cardCreation and nothing else that inserts an
|
|
// Activities document (trackOriginalPosition only updates card position).
|
|
const afterInsertStart = cardsServerHookSource.indexOf('Cards.after.insert(async (userId, doc) => {');
|
|
assert.notEqual(afterInsertStart, -1);
|
|
const afterInsertEnd = cardsServerHookSource.indexOf('\n});', afterInsertStart);
|
|
const afterInsertBody = cardsServerHookSource.slice(afterInsertStart, afterInsertEnd);
|
|
assert.match(afterInsertBody, /await cardCreation\(userId, doc\)/,
|
|
'positive: Cards.after.insert calls cardCreation once');
|
|
assert.equal((afterInsertBody.match(/Activities\.insertAsync/g) || []).length, 0,
|
|
'negative: Cards.after.insert itself never inserts an Activities document ' +
|
|
'(only cardCreation does, exactly once)');
|
|
|
|
// --- 2. The quick-add "More options" fields flow into the SAME insert -----
|
|
|
|
const listBodySource = fs.readFileSync(
|
|
path.join(__dirname, '..', 'client/components/lists/listBody.js'),
|
|
'utf8',
|
|
);
|
|
|
|
const addCardStart = listBodySource.indexOf('this.addCard = async (evt) => {');
|
|
assert.notEqual(addCardStart, -1);
|
|
const addCardEnd = listBodySource.indexOf('\n this.clickOnMiniCard', addCardStart);
|
|
const addCardBody = listBodySource.slice(addCardStart, addCardEnd);
|
|
|
|
assert.match(addCardBody, /formComponent\.description\?\.get\(\)/,
|
|
'positive: description is read from the same form that supplies the title');
|
|
assert.match(addCardBody, /formComponent\.dueAt\?\.get\(\)/,
|
|
'positive: due date is read from the same form that supplies the title');
|
|
assert.match(addCardBody, /formComponent\.assignees\?\.get\(\)/,
|
|
'positive: assignees are read from the same form that supplies the title');
|
|
|
|
const cardFieldsStart = addCardBody.indexOf('const cardFields = {');
|
|
assert.notEqual(cardFieldsStart, -1);
|
|
const insertCallStart = addCardBody.indexOf('Cards.insertAsync(cardFields)', cardFieldsStart);
|
|
assert.notEqual(insertCallStart, -1);
|
|
const insertSetup = addCardBody.slice(cardFieldsStart, insertCallStart);
|
|
|
|
assert.match(insertSetup, /cardFields\.description = description/,
|
|
'positive: description is assigned onto cardFields before the single insert');
|
|
// The due date is More options' one, or else the one typed at the end of the
|
|
// title (docs/Features/Cards/Dates/Due-Date-From-Title.md) - cardDueAt is the
|
|
// first of the two, and it still travels in the same single insert.
|
|
assert.match(addCardBody, /const cardDueAt = dueAt \|\| \(fromTitle && fromTitle\.dueAt\);/,
|
|
'positive: More options wins over a date read from the title');
|
|
assert.match(insertSetup, /cardFields\.dueAt = cardDueAt/,
|
|
'positive: dueAt is assigned onto cardFields before the single insert');
|
|
assert.match(insertSetup, /cardFields\.assignees = assignees/,
|
|
'positive: assignees is assigned onto cardFields before the single insert');
|
|
|
|
// Negative: none of these three fields are ever sent through a *separate*
|
|
// Cards.update/updateAsync call from addCard - that would be the per-field
|
|
// notification-email pattern this feature exists to avoid.
|
|
assert.doesNotMatch(addCardBody, /Cards\.updateAsync?\(/,
|
|
'negative: addCard never calls Cards.update/updateAsync - description, ' +
|
|
'due date and assignees must travel in the single Cards.insert call, not ' +
|
|
'as follow-up edits that would each fire their own notification email');
|
|
|
|
console.log('quickAddMoreOptionsNotification: single-insert / single-notification wiring verified for #3967');
|