فینورا پرو - سامانه جامع حسابداری و صدور فاکتور

fix(a02): keep private Excel workbook in scoped session; serialize imports and release on cancel

davoodmehraban89 committed Oct 31, 2026 at 00:43 UTC 00ed48cca44996caf230c783f4a929c5da2f7a57
1 file changed +23 -10
src/views/SettingsView.js
+23 -10
@@ -17,6 +17,9 @@ import { LicenseService } from '../core/LicenseService.js';
17 import { probeHolooBackupZip } from '../core/HolooBackupProbe.mjs';
18
19 let cache = { company: {}, stats: {}, invoiceSettings: { numberingMode: 'auto', nextNumber: 1 } };
20 +// Excel workbooks can contain private customer data. Never retain previews on window.
21 +let pendingExcelImport = null;
22 +let excelImportBusy = false;
23
24 class SettingsViewImpl {
25 async render() {
@@ -325,12 +328,17 @@ class SettingsViewImpl {
328 <button type="button" class="btn btn-secondary" onclick="FINORA.Modal.close()">انصراف</button>
329 <button type="button" class="btn btn-success" data-excel-import-submit>✅ شروع ایمپورت</button>
330 `;
328 - const modal = Modal.open({ title: `📤 ورود ${kindLabel} از Excel`, body, footer, size: 'md' });
331 + const pending = { kind, rawData: preview.raw, card: null };
332 + pendingExcelImport = pending;
333 + const modal = Modal.open({
334 + title: `📤 ورود ${kindLabel} از Excel`, body, footer, size: 'md',
335 + onClose: () => {
336 + // Cancel/close releases the private workbook immediately.
337 + if (pendingExcelImport === pending) pendingExcelImport = null;
338 + }
339 + });
340 + pending.card = modal.card;
341 modal.card.querySelector('[data-excel-import-submit]').addEventListener('click', () => this._confirmImport(kind));
330 -
331 - // ذخیره‌ی موقت داده
332 - window.__importRawData = preview.raw;
333 - window.__importKind = kind;
342 } catch (err) {
343 console.error(err);
344 Toast.error('خطا: ' + err.message);
@@ -339,17 +347,22 @@ class SettingsViewImpl {
347
348 async _confirmImport(kind) {
349 const mode = document.getElementById('importMode')?.value;
342 - if (mode !== 'merge' || !['products', 'contacts'].includes(kind) || window.__importKind !== kind) {
350 + const pending = pendingExcelImport;
351 + if (excelImportBusy) return;
352 + if (mode !== 'merge' || !['products', 'contacts'].includes(kind) || pending?.kind !== kind) {
353 Toast.error('حالت ورود نامعتبر است؛ هیچ اطلاعاتی تغییر نکرد.');
354 return;
355 }
346 - const rawData = window.__importRawData;
356 + const rawData = pending?.rawData;
357
358 if (!rawData) {
359 Toast.error('داده‌ای برای ایمپورت نیست');
360 return;
361 }
362
363 + excelImportBusy = true;
364 + const submitButton = pending.card?.querySelector('[data-excel-import-submit]');
365 + if (submitButton) submitButton.disabled = true;
366 try {
367 Toast.info('در حال ایمپورت...');
368 let result;
@@ -359,7 +372,7 @@ class SettingsViewImpl {
372 result = await ExcelController.importContacts(rawData, { mode });
373 }
374
362 - Modal.close();
375 + if (Modal.stack[Modal.stack.length - 1]?.card === pending.card) Modal.close();
376 Toast.success(`ایمپورت انجام شد: ${Formatters.number(result.added)} اضافه، ${Formatters.number(result.skipped)} رد شده`);
377
378 // رفرش KPI ها
@@ -370,8 +383,8 @@ class SettingsViewImpl {
383 console.error(err);
384 Toast.error('خطا در ایمپورت: ' + err.message);
385 } finally {
373 - window.__importRawData = null;
374 - window.__importKind = null;
386 + excelImportBusy = false;
387 + if (pendingExcelImport === pending) pendingExcelImport = null;
388 }
389 }
390