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

fix(A04): preflight mixed source-company backup records

davoodmehraban89 committed Oct 20, 2026 at 10:02 UTC ef89bf4b7eb130a7073807bba1830922c761d686
1 file changed +16
src/controllers/SettingsController.js
+16
@@ -193,6 +193,22 @@ class SettingsControllerImpl {
193 backup.data.audit_events = prepareAuditRows(history, backup.auditAnchor ?? null);
194 }
195
196 + // Validate the source ownership of every company-scoped row before
197 + // restoreCompanyBackup reassigns rows to the selected target company.
198 + // Cross-company migration may deliberately change the *target* company;
199 + // it must never import a mixed or unowned source snapshot.
200 + for (const store of COMPANY_BACKUP_STORES) {
201 + const rows = backup.data[store];
202 + if (rows === undefined) continue;
203 + if (!Array.isArray(rows)) throw new Error(`جدول ${store} در فایل پشتیبان نامعتبر است`);
204 + for (const row of rows) {
205 + if (!row || typeof row !== 'object' || Array.isArray(row) ||
206 + row.companyId !== backup.companyId) {
207 + throw new Error('فایل پشتیبان حاوی رکورد متعلق به شرکت دیگری است');
208 + }
209 + }
210 + }
211 +
212 const companyId = await DataScope.companyId();
213 // Prevent an accidental merge of one company's books into another.
214 // Explicit cross-company migration is a separate, intentional operation.