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

fix(A06): preserve local authorization and enforce user limits during full backup import

davoodmehraban89 committed Oct 16, 2026 at 17:35 UTC 47e663f6e52c77641c537c070975c2cf1819b0b3
1 file changed +32 -4
src/core/StorageService.js
+32 -4
@@ -391,18 +391,46 @@ class StorageServiceImpl {
391 }
392
393 async _importUsers(tx, items) {
394 + const localUsers = await tx.getAll('users');
395 + const byId = new Map(localUsers.map(u => [u.id, u]));
396 + const imported = new Map();
397 for (const incoming of items) {
398 const user = stripCredentials(incoming);
399 if (!user.id) user.id = this.uid();
397 - const existing = await tx.get('users', user.id);
400 + const existing = byId.get(user.id);
401 if (existing) {
399 - CREDENTIAL_FIELDS.forEach(f => { if (existing[f] !== undefined) user[f] = existing[f]; });
400 - if (existing.mustSetPassword !== undefined) user.mustSetPassword = existing.mustSetPassword;
402 + // Passwords and access grants belong to the authenticated local
403 + // installation. A JSON backup cannot promote a user to admin or
404 + // assign another company's permissions.
405 + CREDENTIAL_FIELDS.forEach(f => {
406 + if (existing[f] !== undefined) user[f] = existing[f];
407 + });
408 + user.role = existing.role;
409 + user.companyIds = existing.companyIds;
410 + if (existing.mustSetPassword !== undefined) {
411 + user.mustSetPassword = existing.mustSetPassword;
412 + }
413 } else {
414 + user.role = 'user';
415 + user.companyIds = [];
416 user.mustSetPassword = true;
417 }
404 - await tx.putRaw('users', user);
418 + imported.set(user.id, user);
419 + }
420 + const final = new Map(byId);
421 + for (const [id, user] of imported) final.set(id, user);
422 + if (final.size > 4) {
423 + throw Error('فایل پشتیبان بیش از چهار کاربر برای این نصب ایجاد می‌کند');
424 + }
425 + const names = new Set();
426 + for (const user of final.values()) {
427 + const name = typeof user.username === 'string' ? user.username.trim() : '';
428 + if (!name || names.has(name)) {
429 + throw Error('نام کاربری تکراری یا نامعتبر در فایل پشتیبان');
430 + }
431 + names.add(name);
432 }
433 + for (const user of imported.values()) await tx.putRaw('users', user);
434 }
435
436 // ---------- شناسه یکتا ----------