mirror of
https://github.com/wekan/wekan.git
synced 2026-11-24 09:59:47 -05:00
The Import page reads nine more kinds of export, each into the view it is for: mail (mbox, .eml) as cards of Board View / Email, one per conversation with the replies as comments; an .ics file's tasks by status and its events, with their dates; a Google Takeout .zip as one board with a swimlane per product (Mail, Tasks, Keep, Calendar, Google Chat); a Slack workspace export, a Mattermost bulk export, Telegram Desktop's JSON, a WhatsApp chat .txt and a DiscordChatExporter JSON as channels whose messages are comments, for Board View / Chat; and an Evernote .enex as notes with their to-dos as checklists. The Export menu writes a board as an .mbox, an .enex and a Mattermost bulk import file, each read back by the same import. MIME is decoded with mailparser and ENEX with htmlparser2 on the server, and the zips are read under the zip-bomb guards of the other zip imports. An imported message's Message-IDs pass the import sanitizer without their brackets, so a later reply to the board joins the thread. The instructions of the nine are translated into every language. TODO.md also gets the next items: grouped menus, large-file import and export, and the reports to add. Thanks to xet7 !
64 lines
4.0 KiB
JavaScript
64 lines
4.0 KiB
JavaScript
'use strict';
|
|
|
|
// Import loss reporting (models/lib/importLossReport.js).
|
|
// Run: node tests/importLossReport.test.cjs
|
|
//
|
|
// Every external parser and the shared planner return `unsupported` and
|
|
// `warnings` entries, but nothing stored them, so an import that dropped a
|
|
// board's sharing rules or a parent outside the file looked exactly like a
|
|
// complete one. The creators now record one bounded Recovery row per import
|
|
// with losses, and none for a complete import.
|
|
|
|
const assert = require('node:assert/strict');
|
|
const fs = require('node:fs');
|
|
const path = require('node:path');
|
|
|
|
async function main() {
|
|
const { importLossReport, IMPORT_WARNINGS_EVENT } = await import('../models/lib/importLossReport.js');
|
|
|
|
const report = importLossReport({
|
|
source: 'deck',
|
|
warnings: [{ path: '/stacks/0/cards', reason: '1 deleted card(s) skipped' }],
|
|
unsupported: [{ path: '/acl', reason: '1 sharing rule(s)' }, { path: '/x/attachments', reason: '2 attachment(s)' }],
|
|
});
|
|
assert.equal(report.type, IMPORT_WARNINGS_EVENT);
|
|
assert.equal(report.type, 'import-completed-with-warnings');
|
|
assert.equal(report.severity, 'warning');
|
|
assert.equal(report.count, 3);
|
|
assert.equal(report.detail,
|
|
'deck: 2 not imported, 1 warning(s). /acl 1 sharing rule(s); /x/attachments 2 attachment(s); /stacks/0/cards 1 deleted card(s) skipped');
|
|
|
|
// Negative: a complete import records nothing.
|
|
for (const none of [undefined, {}, { source: 'x', warnings: [], unsupported: [] }, { unsupported: [null, {}] }, { unsupported: 'x' }]) {
|
|
assert.equal(importLossReport(none), null);
|
|
}
|
|
|
|
// Bounded: a huge source cannot grow one row without limit.
|
|
const many = importLossReport({ source: 'zenkit', unsupported: Array.from({ length: 500 }, (_, i) => ({ path: `/items/${i}`, reason: 'r'.repeat(1000) })) });
|
|
assert.equal(many.count, 500);
|
|
assert.match(many.detail, /; and 480 more$/);
|
|
assert.ok(many.detail.length < 20 * 420, `detail is bounded (${many.detail.length})`);
|
|
|
|
// Both external-import creators record it after the board exists.
|
|
const read = file => fs.readFileSync(path.join(__dirname, '..', file), 'utf8');
|
|
const kanboard = read('models/kanboardCreator.js');
|
|
// The Scrum planning stage (GitLab, OpenProject, Asana) runs between, so
|
|
// the report also carries what it could not keep.
|
|
assert.match(kanboard, /await this\.createCards\(board, boardId\);\s*await this\.createScrumPlanning\(board, boardId\);\s*await recordImportLosses\(\{/);
|
|
assert.match(kanboard, /this\.losses\.push\(\.\.\.customFieldPlan\.unsupported\)/);
|
|
assert.match(kanboard, /this\.losses\.push\(\.\.\.unsupported\)/);
|
|
const jira = read('models/jiraCreator.js');
|
|
assert.match(jira, /await recordImportLosses\(\{\s*source: 'jira',\s*warnings: jiraPageWarnings\(board\)/);
|
|
const importJs = read('models/import.js');
|
|
// kanboard, markdown, todotxt, taskwarrior, focalboard, todoist, planner (Microsoft Planner), meistertask, obsidian, linear, ticktick, clickup, nullboard, kanri, pivotal, redmine, tasksorg, monday, superproductivity, taiga, vikunja, wrike, teamwork, businessmap, quire, notion, plane, orgmode, leo (the Leo outline), opml, the shared default branch, the parts of "One board per project" (models/lib/importSplit.js), and the six fetched from a service's API (planka ... googlekeep, one branch passing importSource), and the mail, calendar, chat and note sources (mail ... evernote, one branch passing importSource).
|
|
assert.equal((importJs.match(/new KanboardCreator\(data, /g) || []).length, 34, 'every KanboardCreator knows its source');
|
|
assert.doesNotMatch(importJs, /new KanboardCreator\(data\)/);
|
|
const children = read('models/lib/importedCardChildren.js');
|
|
assert.match(children, /RecoveryEvents\.record\(report\.type/);
|
|
assert.match(read('models/recoveryEvents.js'), /IMPORT_COMPLETED_WITH_WARNINGS: 'import-completed-with-warnings'/);
|
|
|
|
console.log(' ok - imports with losses record one bounded Recovery row; complete imports record none');
|
|
}
|
|
|
|
main().catch(error => { console.error(error); process.exitCode = 1; });
|