mirror of
https://github.com/wekan/wekan.git
synced 2026-11-26 20:45:07 -05:00
Delete on an attachment used to remove the document and its file at once. It is now the 'attachments.softDelete' method (History.md section 12): the document gets deletedAt/deletedBy/deleteBatchId with the same helpers lists use, the file is kept, and the card's cover is unset if this was it. Every card-facing read - the opened card's gallery and "Attachments (N)" count, the minicard paperclip badge, the slideshow, the cover, the board-background picker, My Attachments, the API list endpoints and the exporters - filters to live attachments with liveAttachments(); the publications keep sending the deleted ones so the card history can reach them. The card history records who deleted it and when, with the filename in the row. Restore - the table's selection + Restore, or the row's own Restore button, both through changeHistory.restore and applyAttachmentContent - clears the mark, so the card, its count and the minicard badge include the attachment again; the cover is never re-set. An attachment row previews with the existing attachmentViewer slideshow and downloads with the same link the gallery draws, and never offers cover or background. Uploads and renames are recorded through the existing history hooks. There is no per-attachment hard delete any more: api.attachment.delete, DELETE /api/attachment/delete/:id and removeBoardBackground soft-delete, permanentlyDeleteAttachmentFromFilesReport and the Files report's delete button are gone, Attachments.allow remove and onBeforeRemove refuse every client remove and log the attempt under Admin Panel / Problems. The one hard delete is Admin Panel / Problems / Delete enabled, board archived, board deleted from the archive: boardRemover now removes every attachment of the board, live and soft-deleted, with its file. One new i18n key, attachment-soft-delete-pop, replaces the "permanent, no undo" confirmation text; it is inserted in English into every locale at the same position for translation. Thanks to xet7 !
73 lines
3.6 KiB
JavaScript
73 lines
3.6 KiB
JavaScript
'use strict';
|
|
|
|
// Admin Panel / Problems / Files reuses the card attachment preview contract.
|
|
const assert = require('assert');
|
|
const fs = require('fs');
|
|
const path = require('path');
|
|
const read = rel => fs.readFileSync(path.join(__dirname, '..', rel), 'utf8');
|
|
|
|
let passed = 0;
|
|
function test(name, fn) { fn(); passed += 1; console.log(' ok -', name); }
|
|
|
|
console.log('filesReportPreview:');
|
|
|
|
test('Files Report puts preview controls in its leftmost column', () => {
|
|
const reports = read('client/components/settings/adminProblems.js');
|
|
const tables = reports.slice(reports.indexOf('const REPORT_TABLES = {'));
|
|
const files = tables.slice(tables.indexOf("'report-files':"),
|
|
tables.indexOf("'report-rules':"));
|
|
assert.ok(files.indexOf("labelKey: 'preview'") < files.indexOf("label: 'Filename'"));
|
|
assert.match(files, /attachmentKind\(d\)/);
|
|
assert.match(files, /Attachments\.link\.call\(d\)/);
|
|
assert.match(files, /name: cleanFileName\(d\.name\)/);
|
|
});
|
|
|
|
test('the shared cell has thumbnail, preview and sanitized download controls', () => {
|
|
const jade = read('client/components/settings/tablePage.jade');
|
|
assert.match(jade, /\.table-page-attachment/);
|
|
assert.match(jade, /img\.table-page-attachment-thumbnail/);
|
|
assert.match(jade, /\.js-table-page-attachment-preview/);
|
|
assert.match(jade, /a\.js-table-page-attachment-download/);
|
|
assert.match(jade, /download="\{\{attachment\.name\}\}"/);
|
|
});
|
|
|
|
test('preview uses the card viewer and only the displayed report page', () => {
|
|
const table = read('client/components/settings/tablePage.js');
|
|
const attachments = read('client/components/cards/attachments.js');
|
|
const reports = read('client/components/settings/adminProblems.jade');
|
|
assert.match(reports, /\+attachmentViewer/);
|
|
assert.match(table, /openAttachmentSlideshow/);
|
|
assert.match(table, /findAll\('\.js-table-page-attachment-preview'\)/);
|
|
assert.doesNotMatch(table, /Attachments\.collection\.find/,
|
|
'unpublished or unrelated Minimongo files must not enter the slideshow');
|
|
assert.match(attachments, /export function openAttachmentSlideshow/);
|
|
assert.match(attachments, /slideshowAttachmentIds/);
|
|
});
|
|
|
|
test('the Files report offers no per-attachment delete (History.md §12.3)', () => {
|
|
const reports = read('client/components/settings/adminProblems.js');
|
|
const jade = read('client/components/settings/tablePage.jade');
|
|
const table = read('client/components/settings/tablePage.js');
|
|
const server = read('server/attachmentApi.js');
|
|
// The button, its handler, its method and the flag that used to show it are
|
|
// all gone: the only way an attachment is ever removed is deleting an
|
|
// archived board with the permanent-delete setting enabled.
|
|
assert.doesNotMatch(jade, /js-table-page-attachment-delete/);
|
|
assert.doesNotMatch(table, /permanentlyDeleteAttachmentFromFilesReport/);
|
|
assert.doesNotMatch(server, /async permanentlyDeleteAttachmentFromFilesReport\(/);
|
|
assert.doesNotMatch(server, /await Attachments\.removeAsync\(/);
|
|
assert.doesNotMatch(reports, /canPermanentlyDelete:/);
|
|
// The pane says so, in the description the Files report shows.
|
|
const tables = reports.slice(reports.indexOf('const REPORT_TABLES = {'));
|
|
const files = tables.slice(tables.indexOf("'report-files':"),
|
|
tables.indexOf("'report-rules':"));
|
|
assert.match(files, /additionalDesc: FILES_REPORT_DELETE_DESCRIPTION/);
|
|
assert.match(reports, /Attachments are never deleted one at a time/);
|
|
// The board purge keeps its Recovery description; it no longer claims a
|
|
// file-deletion record it cannot write.
|
|
assert.doesNotMatch(reports,
|
|
/PERMANENT_DELETE_RECOVERY_DESCRIPTION =[^;]*file deletion records/);
|
|
});
|
|
|
|
console.log(`\nfilesReportPreview: ${passed} tests passed`);
|