@davoodmehraban89 / Factor-easy-2 Mirror · read-only / commits / b19b385
Fork 0

سامانه صدور فاکتور و حسابداری

Mirrored from https://github.com/davoodmehraban89/Factor-easy.git

Synced Dec 3, 17:00 UTC

Show organization loading failures and distinguish account access errors

davoodmehraban89 committed Nov 10, 2026 at 22:18 UTC b19b385fa5d9875ede92ec25024d93a3b2ba7351
13 files changed +249 -28
.github/workflows/quality.yml
+1 -1
@@ -126,7 +126,7 @@ jobs:
126 - name: Real DOM smoke
127 run: |
128 python3 -m http.server 4173 >/tmp/finora-http.log 2>&1 &
129 - npx playwright test scripts/commerce-route-types.spec.js scripts/workspace-access.spec.js scripts/password-recovery.spec.js scripts/password-admin-ui.spec.js scripts/login-auth-transport.spec.js scripts/login-startup-readiness.spec.js scripts/phase0-startup-performance.spec.js scripts/dom-smoke.spec.js scripts/platform-office.spec.js scripts/enterprise-license.spec.js scripts/enterprise-role.spec.js scripts/enterprise-invitation.spec.js scripts/enterprise-org-ux.spec.js scripts/identity-wave5a.spec.js scripts/identity-wave5b.spec.js scripts/identity-wave5c.spec.js scripts/branding-login.spec.js scripts/login-connectivity.spec.js scripts/shell-scroll-ownership.spec.js scripts/office-slice-c1.spec.js scripts/office-slice-c2.spec.js scripts/office-slice-c3.spec.js scripts/office-slice-c4.spec.js scripts/office-slice-c5.spec.js scripts/office-slice-c6.spec.js scripts/office-slice-c7.spec.js scripts/office-slice-c8.spec.js scripts/office-slice-c8-runtime.spec.js scripts/request-workflow-d2.spec.js scripts/request-workflow-d3b.spec.js scripts/request-workflow-d3c.spec.js scripts/request-workflow-d4a.spec.js scripts/taxpayer-print.spec.js scripts/chart-completeness.spec.js scripts/accounting-p0-journal.spec.js scripts/ux-hardening-r2.spec.js scripts/ux-keyboard-f2.spec.js scripts/phase0-dark-theme-contrast.spec.js scripts/phase0-selector-stress.spec.js scripts/phase0-invoice-persistence.spec.js scripts/phase0-modal-dashboard.spec.js scripts/accounting-document-workflow.spec.js scripts/admin-provisioning.spec.js scripts/pages-artifact.spec.js --reporter=line --workers=1
129 + npx playwright test scripts/login-account-errors.spec.js scripts/organization-manager-read-state.spec.js scripts/commerce-route-types.spec.js scripts/workspace-access.spec.js scripts/password-recovery.spec.js scripts/password-admin-ui.spec.js scripts/login-auth-transport.spec.js scripts/login-startup-readiness.spec.js scripts/phase0-startup-performance.spec.js scripts/dom-smoke.spec.js scripts/platform-office.spec.js scripts/enterprise-license.spec.js scripts/enterprise-role.spec.js scripts/enterprise-invitation.spec.js scripts/enterprise-org-ux.spec.js scripts/identity-wave5a.spec.js scripts/identity-wave5b.spec.js scripts/identity-wave5c.spec.js scripts/branding-login.spec.js scripts/login-connectivity.spec.js scripts/shell-scroll-ownership.spec.js scripts/office-slice-c1.spec.js scripts/office-slice-c2.spec.js scripts/office-slice-c3.spec.js scripts/office-slice-c4.spec.js scripts/office-slice-c5.spec.js scripts/office-slice-c6.spec.js scripts/office-slice-c7.spec.js scripts/office-slice-c8.spec.js scripts/office-slice-c8-runtime.spec.js scripts/request-workflow-d2.spec.js scripts/request-workflow-d3b.spec.js scripts/request-workflow-d3c.spec.js scripts/request-workflow-d4a.spec.js scripts/taxpayer-print.spec.js scripts/chart-completeness.spec.js scripts/accounting-p0-journal.spec.js scripts/ux-hardening-r2.spec.js scripts/ux-keyboard-f2.spec.js scripts/phase0-dark-theme-contrast.spec.js scripts/phase0-selector-stress.spec.js scripts/phase0-invoice-persistence.spec.js scripts/phase0-modal-dashboard.spec.js scripts/accounting-document-workflow.spec.js scripts/admin-provisioning.spec.js scripts/pages-artifact.spec.js --reporter=line --workers=1
130
131 identity-wave5a-database:
132 runs-on: ubuntu-latest
PROJECT_STATE.md
+9
@@ -243,3 +243,12 @@ Owner requests layer-by-layer click/functional testing of all controls and compa
243 - Financial continuation remains onPR195, publishedcandidate61092e4 withreadgraphprerequisite; preceding4149d50 allQuality/Security/WP1CI passed. It is not merged into this UI repair or production. WP1 stillincomplete; detailed phase state is onthatbranch.
244 - 2026-11-10 local checkpoint after urgent login work resumed: launcher moved to responsive topbar; organization access moved to a guarded Settings card with full users/access/capacity label. Existing submenu, exact eight-module rail, late-bound invitation/capacity wrappers and authority checks preserved. Three viewport cases RED before fix ->GREEN. All9 workspace cases PASS in source and generatedPages;51static/server/release commands PASS. Root visually inspected synthetic desktop/mobile screenshots. See docs/NAVIGATION_UTILITIES_2026-11-10.md. Full regression after integrating loginPR196, protectedCI/release and live readback remain pending; no production/data change claimed.
245 - Integrated navigation checkpoint: rebased onto urgent-login main4382e83 without changing the tested application tree. PR196 local220/220 and exact-head Quality42814901014/Security42814901043 PASS; protected merge completed, gated production verification tracked inPR196. Navigation prior candidate d24f85c Quality42815227230/Security42815227293 PASS. Local integrated run222/223 exposed an old timing assumption: diagnostic readiness now precedes login handlers. Added an explicit bounded login-button readiness assertion while preserving all early-ERP/actual-click assertions;5/5 repeats PASS. Final navigation exact-head CI/release ledger isPR197. No final independent review available due provider quota; root reviewed code and synthetic desktop/mobile captures. Remaining PR193 account/member read feedback, authenticated owner acceptance and financialWP1 work remain distinct.
246 +
247 +### 2026-11-01 — Reopened real login and tenant administration acceptance
248 +- Owner reports repeated login errors and difficult eventual entry today, plus missing organization member-management (not global licenses). Reopen operational acceptance; prior211synthetic tests and public artifacts do not resolve owner-network/account failures. Prioritize actual session/role/schema routing and cold-login evidence, independently recheck commerce fix. No customer financial/password/license mutations for testing.
249 +- Remote main4416794 remains current. Phase-status documentation PR192 remains separate. Investigate with available authenticated profile, bounded logs and minimal reproductions; keep remaining controls and phase gates visible.
250 +- Owner specifies10–11AM Chrome/wireless; assumed Iran06:30–07:30UTC window returned no logs, so no attribution. Broader00:00–09:50UTC shows3Auth200/1Auth400 and refresh_token_not_found; cannot attribute to owner. TinyFish run802c7832 expired/signed-out with no vault credentials; no authenticated menu observations. Secure re-entry link renewed, awaiting Save. Public10/10assets still match4416794. Anonymous aggregate platform-admin1/active-membership1/owner-membership1 gives no support to saved non-owner-org hypothesis for that identity; no rights were changed.
251 +- Reproduced diagnostics defect:6account error cases RED; actual revoked-refresh SDK test already PASS before changes, so no refresh repair claimed. Reproduced invisible pending manager dialog RED on prior runtime. Scoped repairs add safe error classification without raw errors/repeated alert, visible manager loading/error/retry, bounded waits and stale completion guards; optional invitation/capacity failures are visible. Owner's underlying login and account-specific missing menu remain unverified until actual evidence.
252 +- Focused19source/19generatedPages PASS,51static/behavioral/server/release checks PASS including49server/Golden. New regression suite verifies explicit read errors, bounded org wait/retry/close-reopen safety, invitation failure visibility and actual zero-context account loader; no mocked refresh fix claimed. Full224browser running. Detailed evidence/limits in docs/LOGIN_MEMBER_RECHECK_2026-11-01.md. PR192 phase docs remains separately open.
253 +- 2026-11-10 continuation of unfinishedPR193: reconcile the existing account-error and visible organization-read feedback repair with loginPR196 and navigationPR197, preserving independent diagnostics/recovery and Settings/topbar placement. Resolve only continuity/cache/test integration conflicts, bump all three changed organization extension versions, then rerun full synthetic/browser/server checks before protected release. No production account, role, quota or financial mutation is authorized for testing; owner-session acceptance remains distinct. OldPR193 CI was incomplete and cannot establish final readiness.
254 +- Final localPR193 reconciliation verification:236/236 canonical Chromium PASS(5.1m),22/22 generatedPages PASS,all51static/server/release commands PASS. Root reviewed preservation of authority/lifecycle guards and unchanged write operations; no independent final-review claim. Cache/continuity conflicts resolved without dropping login or navigation changes. Exact-head CI and protected deployment/readback are the next gates tracked inPR193. PR196 production4382e83 is verified (Quality42815871032/Security42815871028/Release42817044604/Pages42817111972;10/10public assets, fresh public diagnosticOK). PR197 merged13a21a6; deployment ledger remainsPR197. FinancialWP1 candidate61092e4 is stillunreleased; pending-edit-safe client integration,independentSQLreview,sourcecoverage,shadow/schema parity and realJWT/backup gates remain open.
docs/EXECUTION_STATUS.md
+2 -2
@@ -8,12 +8,12 @@
8
9 |کار|وضعیت|شواهد / اقدام بعدی|
10 |---|---|---|
11 -|ورود با دکمه‌های غیرفعال|اصلاح ادغام شد؛ ۲۲۰/۲۲۰ آزمون کامل و بررسی‌های PR196 موفق|[گزارش رخداد](LOGIN_BOOTSTRAP_INCIDENT_2026-11-10.md)؛ مرجع وضعیت انتشار و بازخوانی سایت: [PR196](https://github.com/davoodmehraban89/Factor-easy/pull/196)؛ پذیرش حساب و اینترنت مالک هنوز تأیید نشده|
11 +|ورود با دکمه‌های غیرفعال|منتشر؛ ۱۰/۱۰ فایل عمومی تطبیق داده شد و کلیک بررسی اتصال سالم است|[گزارش رخداد](LOGIN_BOOTSTRAP_INCIDENT_2026-11-10.md)؛ مرجع وضعیت انتشار و بازخوانی سایت: [PR196](https://github.com/davoodmehraban89/Factor-easy/pull/196)؛ پذیرش حساب و اینترنت مالک هنوز تأیید نشده|
12 |جابه‌جایی ماژول‌ها و دسترسی‌ها کنار خروج|پیاده‌سازی و بررسی؛ انتخابگر در نوار بالا، دسترسی در تنظیمات|۹/۹ source و ۹/۹ Pages؛ [گزارش](NAVIGATION_UTILITIES_2026-11-10.md) و مرجع CI/انتشار [PR197](https://github.com/davoodmehraban89/Factor-easy/pull/197)|
13 |WP1 سخت‌سازی مالی|کاندیدای جداگانه؛ روی سایت فعال نشده|PR195، نسخه61092e4: Quality41957583573 / Security41957583565 / WP141957583675 موفق؛ اتصال امن کلاینت و گیت‌های انتشار باقی است|
14 |تفکیک نوع سند خرید/فروش|منتشر در PR191؛ آزمون‌های مجدد در مجموعهٔ ۲۲۰ موفق|فروش: فروش/پیش‌فاکتور/صورت‌وضعیت؛ خرید: خرید؛ اسناد قبلی حفظ می‌شوند|
15 |سازمان، درخواست‌ها و مدیریت اعضا|مسیرها در PR191 منتشر شدند؛ جایگذاری جدید در PR197|پنجرهٔ مدیریت در خطای خواندن هنوز نیازمند PR193 است؛ نشر آن با جایگذاری منو یکی نیست|
16 -|خطاهای دریافت حساب و بارگذاری پنل کاربران|PR193 باز؛ اجرا و انتشار نهایی باقی است|کاندیدا۱۹source/۱۹Pages موفق؛ آزمون کامل و تطبیق با اصلاحات جدید قبل از انتشار|
16 +|خطاهای دریافت حساب و بارگذاری پنل کاربران|پیاده‌سازی یکپارچه و آزمون کامل موفق؛ انتشار در PR193 پیگیری می‌شود|۲۳۶/۲۳۶ مرورگر کامل، ۲۲/۲۲ Pages، ۵۱ بررسی ایستا/سرور؛ [مرجع انتشار](https://github.com/davoodmehraban89/Factor-easy/pull/193)|
17 |اصلاح شرکت|منتشر؛ بازکردن/انصراف واقعی قبول|ذخیرهٔ تغییر شرکت در حساب واقعی از این پذیرش نتیجه نمی‌شود|
18 |تعیین رمز مدیر کل|منتشر؛ تست مصنوعی موفق|آزمون واقعی پنجره با نقش مدیر کل و حساب کنترل‌شده باقی است|
19 |منوهای فازA|منتشر؛۲۰۳تست نسخهٔ مربوط موفق|پذیرش همهٔ نقش‌ها و داده‌ها جداست|
docs/LOGIN_MEMBER_RECHECK_2026-11-01.md new
+32
@@ -0,0 +1,32 @@
1 +# بازبینی ورود و پنل اعضای سازمان — ۱ نوامبر ۲۰۲۶
2 +
3 +## هدف و وضعیت
4 +
5 +گزارش جدید مالک از ورود دشوار و منوی مفقود مدیریت کاربران سازمان، پذیرش عملیاتی را دوباره باز می‌کند. هدف، ورود پایدار و مدیریت اعضای سازمان خریدار در محدودهٔ لایسنس است؛ پنل مدیر کل فروش لایسنس موضوع دیگری است. اصلاحات این نوبت هنوز علت قطعی مشکل دستگاه مالک را ثابت نمی‌کنند.
6 +
7 +## شواهد تازه
8 +
9 +- نسخهٔ عمومی۱۰فایل HTML/JS با main4416794 برابر بود؛ اصلاح تفکیک خرید/فروش منتشر است. این نتیجه کش مرورگر مالک را ثابت نمی‌کند.
10 +- مالک: امروز۱۰–۱۱صبح،Chrome،اینترنت وایرلس. با فرض ساعت ایران، بازه06:30–07:30UTC لاگ قابل تطبیق نداشت. در بازه بزرگ‌تر00:00–09:50UTC سه پاسخ200توکن و یک400با refresh_token_not_found دیده شد؛ انتساب این خطا به مالک ممکن نیست. فقدان لاگ، اثبات فقدان تلاش نیست.
11 +- پروفایل TinyFish تست به صفحه ورود برگشت؛ نشست بازنگشت و credentialذخیره‌شده‌ای موجود نبود. هیچ منوی درون حساب مشاهده نشد. لینک امن تمدید ورود داده شد؛ منتظرSaveهستیم. لینک/توکن/اطلاعات ورود در مخزن ذخیره نشده‌اند.
12 +- شمارش بی‌نام سرور: یک مدیر کل، یک عضویت فعال متعلق به او و همان عضویت مالک سازمان است. فرض انتخاب سازمان دیگری با نقش عادی برای این هویت پشتوانه ندارد؛ هیچ مجوزی دست‌کاری نشد.
13 +
14 +## ایرادهای بازتولیدشده و اصلاح
15 +
16 +۱. همه خطاهای دریافت حساب، حتی خطای دسترسی یا ساختار سرویس، به اینترنت نسبت داده می‌شدند و پیام تکراریalertمی‌دادند. شش تست قبل از اصلاح شکست خورد. پیام‌های ثابت و کدهای امن برای خطای شبکه/مجوز/ساختار/نبود حساب/نبود سازمان اضافه شد؛ متن خام سرور یا اطلاعات خصوصی نمایش/ثبت نمی‌شود. نبود سازمان/لایسنس قابل مشاهده نیز به‌جایTypeErrorکد مشخص دارد. هیچ مجوز جدیدی اعطا نمی‌شود.
17 +
18 +۲. پنل اعضا فقط پس از پایان درخواست‌های شبکه ظاهر می‌شد؛ خطا یا پاسخ معطل، کلیک را ظاهراً بی‌اثر می‌کرد. تست نسخهٔ قبل این رفتار را ثابت کرد. اکنون پنجره فوری با وضعیت بارگذاری باز می‌شود، انتظار هر مرحله محدود است، خطا و تلاش دوباره دارد و پاسخ قدیمی بعد بستن/بازکردن یا تغییر حساب/سازمان پنجره را بازنویسی نمی‌کند. خطای دعوت/ظرفیت نیز پنهان نمی‌ماند. محدودکردن انتظار به‌معنای تغییر زمان‌بندی عملیات نوشتن نیست؛ این مسیر فقط خواندنی است.
19 +
20 +۳. بازیابی از refresh_token_not_found با SDKواقعی و پاسخ مصنوعی از قبل موفق بود: نشست کهنه پاک شد و یک ورود رمز انجام شد. این مورد «اصلاح‌شده» محسوب نمی‌شود و ریشه خطای امروز اعلام نشده است.
21 +
22 +## آزمون و محدودیت
23 +
24 +۱۹ تست هدفمند sourceو۱۹ تست generatedPagesقبول؛۵۱ بررسی پیش از مرورگر/امنیت انتشار شامل۴۹تست سرور وGoldenقبول. اجرای کامل مرورگر وCIنهایی در حال انجام‌اند؛ نتیجه و شناسه انتشار درPRهمین اصلاح ثبت می‌شود. خطای تایپی یک تست جدید قبل از اجرا برطرف شد؛ هیچ انتظار رفتاری برای پنهان‌کردن نقص ضعیف نشد.
25 +
26 +باقی‌مانده: نشست واقعی مالک و بازتولید ورود روی شبکه او؛ تشخیص دلیل نبود ورودی پنل در همان حساب؛ پذیرش دعوت/نقش/ظرفیت با کاربران کنترل‌شده؛ تمام کنترل‌های پوشش‌ندادهٔ ممیزی و گیت‌های فازها. هیچ تغییر واقعی در رمز،عضویت،سهمیه،لایسنس یا سند مالی انجام نشده است.
27 +
28 +## ادامهٔ ۱۰ نوامبر
29 +
30 +این اصلاح با ورودPR196 و جایگذاریPR197 هماهنگ شد. نسخهٔ ضروری ورود روی سایت تأیید شد: main4382e83،Quality42815871032/Security42815871028،Release gate42817044604 وPages42817111972 موفق؛۱۰/۱۰ فایل عمومی برابر با build و بررسی اتصال از مرورگر تازه سالم. این پذیرش، ورود حساب مالک را ثابت نمی‌کند. نسخهٔ ناوبری درmain13a21a6 ادغام شده؛ وضعیت انتشار و بازخوانی آن درPR197 ثبت می‌شود.
31 +
32 +آزمون کامل محلی۲۳۶/۲۳۶سناریوی ترکیبی (۵٫۱دقیقه)،۲۲/۲۲آزمون generatedPages و تمام۵۱بررسی ایستا/سرور/انتشار موفق شدند. CIنسخهٔ نهایی و انتشار محافظت‌شده درPR193 پیگیری می‌شوند. نسخهٔ کش هر سه افزونهٔ سازمان و ورود به‌روز شد؛ مجوزها، دعوت‌ها و عملیات نوشتن حفظ شدند. مرجع نتیجهٔ نهایی و انتشار [PR193](https://github.com/davoodmehraban89/Factor-easy/pull/193) است. لینک امن تمدید نشست واقعی دوباره تحویل مالک شده؛ هیچ لینک یا اطلاعات ورود در مخزن ذخیره نمی‌شود.
index.html
+3 -3
@@ -15,7 +15,7 @@
15 <meta http-equiv="Content-Security-Policy" content="default-src 'self'; script-src 'self' 'unsafe-inline' https://cdn.jsdelivr.net; style-src 'self' 'unsafe-inline' https://cdn.jsdelivr.net; font-src 'self' https://cdn.jsdelivr.net data:; img-src 'self' data: blob:; connect-src 'self' https://hcsixhqbyuhpshfwqpjx.supabase.co; object-src 'none'; base-uri 'none'; form-action 'self'; frame-ancestors 'none'; upgrade-insecure-requests" />
16 <meta name="apple-mobile-web-app-capable" content="yes" />
17 <meta name="theme-color" content="#071a48" />
18 -<link rel="preload" as="script" href="js/core.js?v=20261110-login-bootstrap-v2" />
18 +<link rel="preload" as="script" href="js/core.js?v=20261110-account-read-v3" />
19 <link rel="preload" as="script" href="js/login-connectivity.js?v=20261110-login-bootstrap-v6" />
20 <script src="vendor/supabase.js"></script>
21 <script async src="https://cdn.jsdelivr.net/npm/xlsx@0.18.5/dist/xlsx.full.min.js"></script>
@@ -935,7 +935,7 @@ body{background:#f6f9fc}
935 login actions interactive. Hardened Pages binds static handlers just before core. -->
936 <script src="js/login-connectivity.js?v=20261110-login-bootstrap-v6"></script>
937 <script src="js/password-recovery.js?v=20261026-recovery-cancel-v2"></script>
938 -<script src="js/core.js?v=20261110-login-bootstrap-v2"></script>
938 +<script src="js/core.js?v=20261110-account-read-v3"></script>
939 <script src="js/admin.js?v=20261028-central-password-reset-v1"></script>
940 <script src="js/sync.js?v=20261012-login-read-cancel-v1"></script>
941 <script src="js/ui.js?v=20261031-workspace-recovery-v1"></script>
@@ -948,7 +948,7 @@ body{background:#f6f9fc}
948 <script src="js/companies.js?v=20261028-company-edit-v1"></script>
949 <script src="js/backup.js?v=20260928-data-v3"></script>
950 <script src="js/words.js"></script>
951 -<script src="js/bootstrap.js?v=20261110-navigation-utilities-v1"></script>
951 +<script src="js/bootstrap.js?v=20261110-account-read-v3"></script>
952
953 <style>
954 .form-control, textarea, select { direction: rtl; }
js/bootstrap.js
+3 -3
@@ -3,9 +3,9 @@
3 // browsers may download in parallel but preserve script execution/dependencies.
4 // Auth starts only once all extensions have finished loading or failed.
5 const FINORA_EXTENSION_SCRIPTS=[
6 - "js/organization-rbac.js?v=20261110-navigation-utilities-v1",
7 - "js/organization-invitations.js?v=20260930-eli3-v1",
8 - "js/organization-enterprise-ux.js?v=20260930-eli4-v1",
6 + "js/organization-rbac.js?v=20261110-organization-read-v2",
7 + "js/organization-invitations.js?v=20261110-organization-read-v2",
8 + "js/organization-enterprise-ux.js?v=20261110-organization-read-v2",
9 "js/platform-modules.js?v=20261031-workspace-recovery-v1",
10 "js/office-automation.js?v=20260930-c4-v1",
11 "js/request-workflow-d2.js?v=20261001-d2-v1",
js/core.js
+12 -3
@@ -354,6 +354,15 @@ async function skipSetPassword(){
354 authBusy=true;
355 try{await enterApp(u);}finally{authBusy=false;}
356 }
357 +function finoraAccountReadFailure(err){
358 + const code=String(err?.code||''),message=String(err?.message||'');
359 + if(message==='FINORA_ORGANIZATION_CONTEXT_UNAVAILABLE')return ['BOOT_ORGANIZATION_UNAVAILABLE','عضویت، سازمان یا لایسنس قابل دسترس برای این حساب پیدا نشد. مدیر سازمان باید عضویت و اشتراک را بررسی کند.'];
360 + if(code==='42501'||code==='PGRST301'||code==='PGRST302')return ['BOOT_ACCOUNT_ACCESS_DENIED','دسترسی به اطلاعات حساب تأیید نشد. دوباره وارد شوید؛ اگر تکرار شد مدیر سازمان باید مجوز حساب را بررسی کند.'];
361 + if(['42703','42P01','42883','PGRST200','PGRST202','PGRST204','PGRST205'].includes(code))return ['BOOT_ACCOUNT_SCHEMA','ساختار سرویس با این نسخه هماهنگ نیست. کد خطا را به پشتیبانی بدهید؛ تغییر رمز لازم نیست.'];
362 + if(code==='PGRST116')return ['BOOT_ACCOUNT_UNAVAILABLE','اطلاعات حساب پیدا نشد. مدیر سازمان باید وضعیت حساب را بررسی کند.'];
363 + if(/fetch|network|load failed|timeout|abort/i.test(message))return ['BOOT_ACCOUNT_NETWORK','ارتباط هنگام دریافت اطلاعات حساب قطع شد. اتصال را بررسی و دوباره تلاش کنید؛ تغییر رمز لازم نیست.'];
364 + return ['BOOT_ACCOUNT_READ_FAILED','دریافت اطلاعات حساب انجام نشد. دوباره تلاش کنید و در صورت تکرار، کد خطا را به پشتیبانی بدهید.'];
365 +}
366 async function enterApp(authUser,{timeoutMs=25000}={}){
367 if(window.FinoraPasswordRecovery?.active)return;
368 const controller=new AbortController();
@@ -395,9 +404,9 @@ async function enterApp(authUser,{timeoutMs=25000}={}){
404 }else if(err?.message==='FINORA_APP_ASSETS_UNAVAILABLE'){
405 setAuthLoginStatus('برخی اجزای نرم‌افزار از این شبکه دریافت نشدند (BOOT_APP_ASSETS_FAILED). برای جلوگیری از نمایش اطلاعات ناقص، محیط کار باز نشد. اتصال را تغییر دهید و صفحه را دوباره بارگذاری کنید.','error');
406 }else{
398 - console.error('Finora account hydration failed',err);
399 - setAuthLoginStatus('دریافت اطلاعات حساب ناموفق بود؛ اتصال را بررسی و دوباره تلاش کنید.','error');
400 - alert('خطا در بارگذاری اطلاعات حساب. اتصال اینترنت را بررسی کنید و دوباره وارد شوید.');
407 + const [code,message]=finoraAccountReadFailure(err);
408 + console.warn('Finora account hydration failed: '+code);
409 + setAuthLoginStatus(message+' ('+code+')','error');
410 }
411 document.getElementById('auth-screen').style.display='flex';
412 showAuthPanel('main');
js/organization-enterprise-ux.js
+6 -4
@@ -30,16 +30,18 @@ window.organizationCreateUnitFromUi=async function(){
30 const {error}=await sb.from('organization_units').insert({organization_id:currentUser.organizationId,parent_id:parent||null,code,title,unit_kind:kind,active:true});
31 if(error)return alert('ثبت واحد انجام نشد: '+error.message);await showOrganizationAccessManager();
32 };
33 -window.refreshEnterpriseOrganizationDashboard=async function(){
33 +window.refreshEnterpriseOrganizationDashboard=async function(context){
34 + if(context&&!window.finoraOrganizationPanelCurrent(context))return;
35 if(!window.finoraCanManageOrganization?.())return;
36 const modal=document.getElementById('finora-org-access-modal'),card=modal?.querySelector('.modal-card');if(!card)return;
37 modal.querySelector('#enterprise-org-dashboard')?.remove();enhanceUnitForm();
38 try{
38 - const {summary,units}=await enterpriseOrganizationData(),mods=summary?.modules||[];
39 + const {summary,units}=await window.finoraOrganizationPanelRead(enterpriseOrganizationData()),mods=summary?.modules||[];
40 + if(context&&!window.finoraOrganizationPanelCurrent(context))return;
41 const html='<div class="card" id="enterprise-org-dashboard"><h4>نمای سازمانی و ظرفیت‌ها</h4><div style="display:flex;gap:10px;flex-wrap:wrap">'+capacityCard('کاربران فعال',summary.active_users,summary.max_users)+capacityCard('شرکت‌های حقوقی',summary.company_count,summary.max_companies)+'</div><p class="af-hint" style="margin-top:10px">پلن: '+esc(summary.plan||'—')+' · وضعیت: '+esc(summary.status||'—')+' · ماژول‌ها: '+esc(mods.join('، ')||'—')+'</p><h4 style="margin-top:16px">درخت سازمانی</h4>'+window.renderEnterpriseOrganizationTree(units)+'</div>';
42 const first=card.querySelector('.card');if(first)first.insertAdjacentHTML('beforebegin',html);else card.insertAdjacentHTML('beforeend',html);
41 - }catch(e){console.error('enterprise organization dashboard failed',e)}
43 + }catch(e){if(context&&window.finoraOrganizationPanelCurrent(context))card.insertAdjacentHTML('beforeend','<div class="card" role="alert">دریافت ظرفیت‌های سازمان انجام نشد. <button class="btn btn-secondary" onclick="showOrganizationAccessManager()">تلاش دوباره</button></div>')}
44 };
45 const baseShowEnterprise=window.showOrganizationAccessManager;
44 -window.showOrganizationAccessManager=async function(){const r=await baseShowEnterprise();await window.refreshEnterpriseOrganizationDashboard();return r};
46 +window.showOrganizationAccessManager=async function(){const r=await baseShowEnterprise();if(r)await window.refreshEnterpriseOrganizationDashboard(r);return r};
47 })();
js/organization-invitations.js
+5 -4
@@ -20,15 +20,16 @@ function invitationPanelHtml(data){
20 }).join('');
21 return '<div class="card" id="org-invitation-card"><h4>دعوت کاربر جدید</h4><p class="af-hint">دعوت‌نامه به ایمیل و ظرفیت کاربری سازمان متصل است. لینک فقط هنگام ایجاد نمایش داده می‌شود.</p><div class="form-row"><div class="form-group"><label>ایمیل</label><input id="org-invite-email" class="form-control" type="email" autocomplete="off"></div><div class="form-group"><label>سمت</label><input id="org-invite-position" class="form-control"></div><div class="form-group"><label>اعتبار دعوت (ساعت)</label><input id="org-invite-hours" class="form-control" type="number" min="1" max="720" value="168"></div></div><div class="form-group"><label>نقش‌های اولیه</label><div id="org-invite-roles" style="display:flex;gap:10px;flex-wrap:wrap">'+data.roles.map(r=>'<label><input type="checkbox" value="'+esc(r.id)+'"> '+esc(r.title)+(r.is_system?' · پیش‌فرض':'')+'</label>').join('')+'</div></div><button class="btn btn-primary" onclick="organizationCreateInvitationFromUi()">ایجاد دعوت امن</button><div id="org-invite-result" style="display:none;margin-top:12px"><label>لینک یک‌بارنمایش دعوت</label><div style="display:flex;gap:8px;align-items:center"><input id="org-invite-url" class="form-control" readonly dir="ltr"><button class="btn btn-secondary btn-inline" onclick="organizationCopyInvitationUrl()">کپی</button></div><p class="af-hint">ارسال خودکار ایمیل هنوز فعال نشده؛ این لینک را از مسیر امن برای کاربر ارسال کنید.</p></div><div class="table-responsive" style="margin-top:12px"><table><thead><tr><th>ایمیل</th><th>سمت</th><th>نقش</th><th>وضعیت</th><th>انقضا</th><th>عملیات</th></tr></thead><tbody>'+rows+'</tbody></table></div><p class="af-hint">دعوت‌های در انتظار: '+toPersianDigits(pending.length)+'</p></div>';
22 }
23 -async function injectInvitationPanel(){
23 +async function injectInvitationPanel(context){
24 + if(!window.finoraOrganizationPanelCurrent(context))return;
25 if(!window.finoraCanManageOrganization?.())return;
26 const modal=document.getElementById('finora-org-access-modal');const card=modal?.querySelector('.modal-card');if(!card)return;
27 modal.querySelector('#org-invitation-card')?.remove();
27 - try{card.insertAdjacentHTML('beforeend',invitationPanelHtml(await invitationManagerData()));}
28 - catch(e){console.error('invitation manager load failed',e);}
28 + try{const data=await window.finoraOrganizationPanelRead(invitationManagerData());if(window.finoraOrganizationPanelCurrent(context))card.insertAdjacentHTML('beforeend',invitationPanelHtml(data));}
29 + catch(e){if(window.finoraOrganizationPanelCurrent(context))card.insertAdjacentHTML('beforeend','<div class="card" role="alert">دریافت دعوت‌های سازمان انجام نشد. <button class="btn btn-secondary" onclick="showOrganizationAccessManager()">تلاش دوباره</button></div>');}
30 }
31 const baseShowOrganizationAccessManager=window.showOrganizationAccessManager;
31 -window.showOrganizationAccessManager=async function(){const r=await baseShowOrganizationAccessManager();await injectInvitationPanel();return r};
32 +window.showOrganizationAccessManager=async function(){const r=await baseShowOrganizationAccessManager();if(r)await injectInvitationPanel(r);return r};
33 window.organizationCreateInvitationFromUi=async function(){
34 if(!window.finoraCanManageOrganization?.())return;
35 const email=String(document.getElementById('org-invite-email')?.value||'').trim().toLowerCase();
js/organization-rbac.js
+24 -5
@@ -13,7 +13,7 @@ async function loadOrganizationContext(user,{signal}={}){
13 const {data:members,error:memberError}=await finoraOrganizationRead(sb.from('organization_members').select('id,organization_id,unit_id,position_title,status,is_owner').eq('user_id',user.id).eq('status','active'),signal,'ORG_MEMBERSHIP');
14 if(memberError)throw memberError;
15 const orgIds=(members||[]).map(x=>x.organization_id);
16 - if(!orgIds.length)throw new Error('عضویت سازمانی برای این کاربر تعریف نشده است.');
16 + if(!orgIds.length)throw new Error('FINORA_ORGANIZATION_CONTEXT_UNAVAILABLE');
17 const [{data:orgs,error:orgError},{data:perms,error:permError},{data:licenses,error:licenseError},{data:activeMembers,error:seatError},{data:roles,error:roleError},{data:rolePerms,error:rolePermError},{data:memberRoles,error:memberRoleError}]=await Promise.all([
18 sb.from('organizations').select('id,name,status').in('id',orgIds),
19 sb.from('member_module_permissions').select('id,organization_id,member_id,module_key,capabilities,scope_type,scope_id,confidentiality_level').in('organization_id',orgIds),
@@ -34,6 +34,7 @@ async function loadOrganizationContext(user,{signal}={}){
34 }).filter(x=>x.organization&&x.license);
35 const saved=localStorage.getItem('finora_active_org_'+user.id);
36 const selected=contexts.find(x=>x.organization.id===saved)||contexts.find(x=>x.membership.is_owner)||contexts[0];
37 + if(!selected)throw new Error('FINORA_ORGANIZATION_CONTEXT_UNAVAILABLE');
38 const lic=selected.license,sub={type:lic.plan,startDate:lic.starts_at,endDate:lic.ends_at,status:lic.status};
39 user.organizations=contexts;
40 user.organizationId=selected.organization.id;
@@ -160,11 +161,25 @@ function configurableModules(){
161 return (currentUser?.modulePermissions||[]).filter(p=>p.capabilities?.includes('configure')).map(p=>[p.module_key,(window.FINORA_MODULE_CATALOG||{})[p.module_key]?.title||p.module_key]);
162 }
163 window.finoraCanOpenOrganizationAccess=function(){return !!currentUser?.organizationId&&(finoraCanManageOrganization()||configurableModules().length>0)};
164 +let organizationPanelEpoch=0;
165 +window.closeOrganizationAccessManager=function(){organizationPanelEpoch++;document.getElementById('finora-org-access-modal')?.classList.remove('active')};
166 +window.finoraOrganizationPanelCurrent=function(context){return !!context&&organizationPanelEpoch===context.epoch&&currentUser?.id===context.userId&&currentUser?.organizationId===context.orgId&&finoraCanManageOrganization()===context.canManage&&!!window.finoraCanOpenOrganizationAccess()&&document.getElementById('finora-org-access-modal')?.classList.contains('active')};
167 +window.finoraOrganizationPanelRead=async function(read){
168 + const controller=new AbortController(),timer=setTimeout(()=>controller.abort(),20000);
169 + try{return await finoraAbortableRead(read,controller.signal)}finally{clearTimeout(timer)}
170 +};
171 window.showOrganizationAccessManager=async function(){
172 const canManage=finoraCanManageOrganization();
165 - if(!window.finoraCanOpenOrganizationAccess())return alert('دسترسی مدیریت اعضا یا مجوزهای ماژول را ندارید.');
173 + if(!window.finoraCanOpenOrganizationAccess()){alert('دسترسی مدیریت اعضا یا مجوزهای ماژول را ندارید.');return false;}
174 let el=document.getElementById('finora-org-access-modal');if(!el){el=document.createElement('div');el.id='finora-org-access-modal';el.className='modal-backdrop';document.body.appendChild(el)}
167 - const members=await orgManagerData(),mods=configurableModules(),roleData=canManage?await roleManagerData():{roles:[],permissions:[],assignments:[]};
175 + const context={epoch:++organizationPanelEpoch,userId:currentUser.id,orgId:currentUser.organizationId,canManage};
176 + el.innerHTML='<div class="modal-card" style="max-width:900px"><h3>مدیریت دسترسی سازمان</h3><p role="status">در حال دریافت اطلاعات سازمان…</p><button class="btn btn-secondary" onclick="closeOrganizationAccessManager()">بستن</button></div>';
177 + el.classList.add('active');
178 + try{
179 + const members=await window.finoraOrganizationPanelRead(orgManagerData());
180 + if(!window.finoraOrganizationPanelCurrent(context))return false;
181 + const mods=configurableModules(),roleData=canManage?await window.finoraOrganizationPanelRead(roleManagerData()):{roles:[],permissions:[],assignments:[]};
182 + if(!window.finoraOrganizationPanelCurrent(context))return false;
183 const roleModules=canManage?roleConfigurableModules():[];
184 const activeCount=members.filter(m=>m.status==='active').length,maxUsers=Math.max(1,Number(currentUser.maxUsers||1)),remaining=Math.max(0,maxUsers-activeCount);
185 const memberRows=members.map(m=>{
@@ -172,11 +187,15 @@ window.showOrganizationAccessManager=async function(){
187 const recovery=canManage&&m.status==='active'?'<button class="btn btn-secondary btn-inline" data-recovery-user="'+esc(m.user_id)+'" onclick="finoraSendUserRecovery(\''+esc(m.user_id)+'\',\''+esc(currentUser.organizationId)+'\')">ارسال پیوند بازیابی</button>':'';
188 return '<tr><td>'+esc(m.profile?.full_name||m.profile?.email||m.user_id)+'</td><td>'+esc(m.position_title||'—')+'</td><td>'+esc(m.status)+'</td><td>'+status+' '+recovery+'</td></tr>';
189 }).join('');
175 - el.innerHTML='<div class="modal-card" style="max-width:900px"><div style="display:flex;justify-content:space-between;gap:10px"><div><h3>مدیریت دسترسی سازمان</h3><p class="af-hint">'+esc(currentUser.organizationName||'')+' · مجوز تجاری و مجوز عضو مستقل از هم هستند.</p><p id="org-seat-summary" class="af-hint"><strong>'+toPersianDigits(activeCount)+'</strong> کاربر فعال از <strong>'+toPersianDigits(maxUsers)+'</strong> · ظرفیت باقی‌مانده '+toPersianDigits(remaining)+'</p></div><button class="btn btn-secondary btn-inline" onclick="document.getElementById(\'finora-org-access-modal\').classList.remove(\'active\')">بستن</button></div>'+
190 + el.innerHTML='<div class="modal-card" style="max-width:900px"><div style="display:flex;justify-content:space-between;gap:10px"><div><h3>مدیریت دسترسی سازمان</h3><p class="af-hint">'+esc(currentUser.organizationName||'')+' · مجوز تجاری و مجوز عضو مستقل از هم هستند.</p><p id="org-seat-summary" class="af-hint"><strong>'+toPersianDigits(activeCount)+'</strong> کاربر فعال از <strong>'+toPersianDigits(maxUsers)+'</strong> · ظرفیت باقی‌مانده '+toPersianDigits(remaining)+'</p></div><button class="btn btn-secondary btn-inline" onclick="closeOrganizationAccessManager()">بستن</button></div>'+
191 (canManage?'<div class="card" style="margin-top:14px"><h4>افزودن عضو موجود فینورا</h4><div class="form-row"><div class="form-group"><label>ایمیل</label><input id="org-member-email" class="form-control" type="email"></div><div class="form-group"><label>سمت</label><input id="org-member-position" class="form-control"></div></div><button class="btn btn-primary" onclick="organizationAddMemberFromUi()">افزودن عضو</button><p class="af-hint">برای کاربر جدید از بخش «دعوت کاربر جدید» در همین پنجره استفاده کنید.</p><div class="table-responsive" style="margin-top:12px"><table><thead><tr><th>عضو</th><th>سمت</th><th>وضعیت</th><th>عملیات</th></tr></thead><tbody>'+memberRows+'</tbody></table></div></div>':'')+
192 (canManage?'<div class="card"><h4>نقش‌های سازمانی</h4><p class="af-hint">نقش‌ها مجوزهای قابل استفاده مجدد هستند؛ مجوز مستقیم هر کاربر همچنان به‌عنوان Override مستقل باقی می‌ماند.</p><div class="form-row"><div class="form-group"><label>کلید نقش سفارشی</label><input id="org-role-key" class="form-control" placeholder="regional_accountant"></div><div class="form-group"><label>عنوان نقش</label><input id="org-role-title" class="form-control" placeholder="حسابدار ناحیه"></div></div><button class="btn btn-primary btn-inline" onclick="organizationCreateRoleFromUi()">ایجاد/به‌روزرسانی نقش</button><hr style="margin:14px 0"><div class="form-row"><div class="form-group"><label>عضو</label><select id="org-role-member" class="form-control">'+members.filter(m=>!m.is_owner&&m.status==='active').map(m=>'<option value="'+esc(m.id)+'">'+esc(m.profile?.full_name||m.profile?.email||m.position_title||m.user_id)+'</option>').join('')+'</select></div><div class="form-group"><label>نقش</label><select id="org-role-assign" class="form-control">'+roleData.roles.filter(r=>r.active).map(r=>'<option value="'+esc(r.id)+'">'+esc(r.title)+(r.is_system?' · پیش‌فرض':'')+'</option>').join('')+'</select></div></div><button class="btn btn-success btn-inline" onclick="organizationAssignRoleFromUi()">تخصیص نقش</button><hr style="margin:14px 0"><div class="form-row"><div class="form-group"><label>نقش</label><select id="org-role-perm-role" class="form-control">'+roleData.roles.filter(r=>r.active).map(r=>'<option value="'+esc(r.id)+'">'+esc(r.title)+'</option>').join('')+'</select></div><div class="form-group"><label>ماژول</label><select id="org-role-perm-module" class="form-control">'+roleModules.map(x=>'<option value="'+esc(x[0])+'">'+esc(x[1])+'</option>').join('')+'</select></div><div class="form-group"><label>سطح محرمانگی</label><select id="org-role-perm-clearance" class="form-control"><option value="0">عادی</option><option value="1">محرمانه</option><option value="2">خیلی محرمانه</option><option value="3">سری</option></select></div></div><div class="form-group"><label>قابلیت‌های نقش</label><div id="org-role-perm-caps" style="display:flex;gap:10px;flex-wrap:wrap">'+[['read','مشاهده'],['create','ایجاد'],['edit','ویرایش'],['delete','حذف'],['approve','تأیید'],['register','ثبت دبیرخانه'],['refer','ارجاع'],['archive','بایگانی'],['configure','مدیریت']].map(x=>'<label><input type="checkbox" value="'+x[0]+'" '+(x[0]==='read'?'checked':'')+'> '+x[1]+'</label>').join('')+'</div></div><button class="btn btn-success btn-inline" onclick="organizationSaveRolePermissionFromUi()">ثبت مجوز نقش</button><div class="table-responsive" style="margin-top:12px"><table><thead><tr><th>نقش</th><th>نوع</th><th>مجوزها</th><th>تخصیص‌ها</th></tr></thead><tbody>'+roleData.roles.map(r=>'<tr><td>'+esc(r.title)+'</td><td>'+(r.is_system?'پیش‌فرض':'سفارشی')+'</td><td>'+roleData.permissions.filter(p=>p.role_id===r.id).map(p=>esc(p.module_key)+' ('+esc((p.capabilities||[]).join(', '))+')').join('<br>')+'</td><td>'+toPersianDigits(roleData.assignments.filter(a=>a.role_id===r.id).length)+'</td></tr>').join('')+'</tbody></table></div></div>':'')+
193 '<div class="card"><h4>مجوز مستقیم کاربر <small style="color:var(--text-muted)">Override پیشرفته</small></h4><div class="form-row"><div class="form-group"><label>عضو</label><select id="org-perm-member" class="form-control">'+members.filter(m=>!m.is_owner&&m.status==='active').map(m=>'<option value="'+esc(m.id)+'">'+esc(m.profile?.full_name||m.profile?.email||m.position_title||m.user_id)+'</option>').join('')+'</select></div><div class="form-group"><label>ماژول</label><select id="org-perm-module" class="form-control">'+mods.map(x=>'<option value="'+esc(x[0])+'">'+esc(x[1])+'</option>').join('')+'</select></div><div class="form-group"><label>دامنه</label><select id="org-perm-scope" class="form-control" onchange="document.getElementById(\'org-perm-scope-id\').disabled=[\'own\',\'organization\'].includes(this.value)"><option value="own">فقط رکوردهای خود</option><option value="unit">واحد</option><option value="branch">شعبه</option><option value="company">شرکت</option><option value="organization">کل سازمان</option></select></div><div class="form-group"><label>شناسه دامنه</label><input id="org-perm-scope-id" class="form-control" disabled></div></div><div class="form-group"><label>قابلیت‌ها</label><div id="org-perm-caps" style="display:flex;gap:10px;flex-wrap:wrap">'+[['read','مشاهده'],['create','ایجاد'],['edit','ویرایش'],['delete','حذف'],['approve','تأیید'],['register','ثبت دبیرخانه'],['refer','ارجاع'],['archive','بایگانی'],['configure','مدیریت ماژول']].map(x=>'<label><input type="checkbox" value="'+x[0]+'" '+(x[0]==='read'?'checked':'')+'> '+x[1]+'</label>').join('')+'</div></div><div class="form-row"><div class="form-group"><label>سطح محرمانگی</label><select id="org-perm-clearance" class="form-control"><option value="0">عادی</option><option value="1">محرمانه</option><option value="2">خیلی محرمانه</option><option value="3">سری</option></select></div></div><button class="btn btn-success" onclick="organizationSavePermissionFromUi()">ثبت/به‌روزرسانی مجوز مستقیم</button></div></div>';
179 - el.classList.add('active');
194 + return context;
195 + }catch(error){
196 + if(window.finoraOrganizationPanelCurrent(context))el.innerHTML='<div class="modal-card" style="max-width:900px"><h3>مدیریت دسترسی سازمان</h3><p role="alert">دریافت اطلاعات سازمان انجام نشد. اتصال یا مجوز دسترسی را بررسی کنید و دوباره تلاش کنید. (ORG_PANEL_READ_FAILED)</p><button class="btn btn-primary" onclick="showOrganizationAccessManager()">تلاش دوباره</button> <button class="btn btn-secondary" onclick="closeOrganizationAccessManager()">بستن</button></div>';
197 + return false;
198 + }
199 };
200 window.organizationAddMemberFromUi=async function(){
201 if(!finoraCanManageOrganization())return;
scripts/login-account-errors.spec.js new
+68
@@ -0,0 +1,68 @@
1 +const {test,expect}=require('@playwright/test');
2 +const BASE=process.env.FINORA_TEST_BASE_URL||'http://127.0.0.1:4173/index.html';
3 +async function ready(page){
4 + await page.route('https://*.supabase.co/**',route=>route.abort());
5 + await page.goto(BASE,{waitUntil:'domcontentloaded'});
6 + await page.waitForFunction(()=>window.FinoraStartupStatus?.authChecked&&window.FinoraStartupStatus?.extensionsReady);
7 +}
8 +for(const [failure,expected] of [
9 + [{message:'FINORA_ORGANIZATION_CONTEXT_UNAVAILABLE'},'BOOT_ORGANIZATION_UNAVAILABLE'],
10 + [{code:'42501',message:'permission denied synthetic-private-details'},'BOOT_ACCOUNT_ACCESS_DENIED'],
11 + [{code:'42703',message:'missing column synthetic-private-details'},'BOOT_ACCOUNT_SCHEMA'],
12 + [{code:'PGRST116',message:'no profile synthetic-private-details'},'BOOT_ACCOUNT_UNAVAILABLE'],
13 + [{message:'Failed to fetch synthetic-private-details'},'BOOT_ACCOUNT_NETWORK'],
14 + [{message:'unexpected synthetic-private-details'},'BOOT_ACCOUNT_READ_FAILED']
15 +])test('account hydration reports safe actionable code '+expected,async({page})=>{
16 + await ready(page);const dialogs=[];page.on('dialog',async d=>{dialogs.push(d.message());await d.dismiss()});
17 + await page.evaluate(failure=>{
18 + sb.auth.signInWithPassword=async()=>({data:{user:{id:'synthetic-user'}},error:null});
19 + fetchCurrentUser=async()=>{throw failure};
20 + },failure);
21 + await page.locator('#auth-email').fill('synthetic@example.test');await page.locator('#auth-password').fill('Synthetic!Password1');
22 + await page.locator('#auth-login-button').click();
23 + await expect(page.locator('#auth-login-status')).toContainText(expected);
24 + await expect(page.locator('#auth-login-status')).toHaveAttribute('data-state','error');
25 + await expect(page.locator('#auth-screen')).toBeVisible();
26 + expect(await page.evaluate(()=>currentUser)).toBe(null);
27 + expect(dialogs.join(' ')).not.toContain('synthetic-private-details');
28 + expect(await page.locator('#auth-login-status').textContent()).not.toContain('synthetic-private-details');
29 + if(expected!=='BOOT_ACCOUNT_NETWORK')expect(dialogs.join(' ')).not.toContain('اتصال اینترنت را بررسی');
30 +});
31 +
32 +test('invalid saved refresh token clears stale session and permits one manual password login through real SDK',async({page})=>{
33 + const session={access_token:'synthetic-access',refresh_token:'synthetic-refresh-new',token_type:'bearer',expires_in:3600,expires_at:Math.floor(Date.now()/1000)+3600,user:{id:'synthetic-user',aud:'authenticated',email:'synthetic@example.test',app_metadata:{provider:'email',providers:['email']},user_metadata:{},created_at:'2026-01-01T00:00:00Z'}};
34 + await page.addInitScript(session=>localStorage.setItem('sb-hcsixhqbyuhpshfwqpjx-auth-token',JSON.stringify({...session,refresh_token:'synthetic-revoked',expires_at:1})),session);
35 + const counts={refresh:0,password:0,other:0};
36 + await page.route('https://*.supabase.co/**',async route=>{
37 + const url=new URL(route.request().url());
38 + if(url.pathname==='/auth/v1/token'&&url.searchParams.get('grant_type')==='refresh_token'){
39 + counts.refresh++;return route.fulfill({status:400,contentType:'application/json',headers:{'x-supabase-api-version':'2024-01-01'},body:JSON.stringify({code:'refresh_token_not_found',message:'Invalid Refresh Token: Refresh Token Not Found'})});
40 + }
41 + if(url.pathname==='/auth/v1/token'&&url.searchParams.get('grant_type')==='password'){
42 + counts.password++;return route.fulfill({status:200,contentType:'application/json',body:JSON.stringify(session)});
43 + }
44 + counts.other++;await route.abort();
45 + });
46 + page.on('dialog',d=>d.dismiss());
47 + await page.goto(BASE,{waitUntil:'domcontentloaded'});
48 + await page.waitForFunction(()=>window.FinoraStartupStatus?.authChecked&&window.FinoraStartupStatus?.extensionsReady);
49 + await expect(page.locator('#auth-screen')).toBeVisible();
50 + expect(await page.evaluate(()=>localStorage.getItem(FINORA_AUTH_STORAGE_KEY))).toBe(null);
51 + await page.evaluate(()=>{
52 + fetchCurrentUser=async()=>({id:'synthetic-user',role:'user',modules:['full_suite'],subscription:{type:'lifetime',status:'active',endDate:'2099-01-01'}});
53 + pullAll=async()=>{};maybeMigrateLegacyData=()=>{};maybeShowUserOnboarding=()=>{};
54 + });
55 + await page.locator('#auth-email').fill('synthetic@example.test');await page.locator('#auth-password').fill('Synthetic!Password1');
56 + await page.locator('#auth-login-button').click();await expect(page.locator('#auth-screen')).toBeHidden();
57 + expect(await page.evaluate(()=>currentUser?.id)).toBe('synthetic-user');
58 + expect(counts).toEqual({refresh:1,password:1,other:0});
59 +});
60 +
61 +test('real organization loader fails clearly when membership has no visible organization/license',async({page})=>{
62 + await ready(page);
63 + const message=await page.evaluate(async()=>{
64 + sb.from=table=>({select(){return this},eq(){return this},in(){return this},single(){return this},then(resolve,reject){return Promise.resolve({data:table==='profiles'?{id:'QA',role:'user'}:table==='organization_members'?[{id:'QM',organization_id:'QO',status:'active',is_owner:true}]:[],error:null}).then(resolve,reject)}});
65 + try{await fetchCurrentUser({id:'QA'});return 'unexpected-success'}catch(e){return e.message}
66 + });
67 + expect(message).toBe('FINORA_ORGANIZATION_CONTEXT_UNAVAILABLE');
68 +});
scripts/login-connectivity-check.mjs
+3 -3
@@ -7,9 +7,9 @@ assert(html.includes('id="auth-connectivity-check"'),'Missing diagnostic action'
7 assert(html.includes('id="auth-connectivity-result"'),'Missing accessible result');
8 assert(html.includes('id="auth-connectivity-result" aria-live="polite"'),'Diagnostic must announce updates without adding a conflicting global role=status');
9 assert(html.includes('js/login-connectivity.js?v=20261110-login-bootstrap-v6'),'Missing versioned script');
10 -assert(html.includes('js/core.js?v=20261110-login-bootstrap-v2'),'Production login controls must use new cache version');
11 -assert(html.indexOf('<script src="js/login-connectivity.js?v=20261110-login-bootstrap-v6"')<html.indexOf('<script src="js/core.js?v=20261110-login-bootstrap-v2"'),'Connectivity handler script must execute before core (not just preload)');
12 -assert(html.includes('js/bootstrap.js?v=20261110-navigation-utilities-v1'),'Parallel bootstrap must also be cache-busted');
10 +assert(html.includes('js/core.js?v=20261110-account-read-v3'),'Production login controls must use new cache version');
11 +assert(html.indexOf('<script src="js/login-connectivity.js?v=20261110-login-bootstrap-v6"')<html.indexOf('<script src="js/core.js?v=20261110-account-read-v3"'),'Connectivity handler script must execute before core (not just preload)');
12 +assert(html.includes('js/bootstrap.js?v=20261110-account-read-v3'),'Parallel bootstrap must also be cache-busted');
13 assert(html.includes('id="auth-login-button"')&&html.includes('id="auth-login-status"'),'Login control requires real readiness/progress feedback');
14 assert(core.includes('window.FinoraAppAssetsReady'),'Authenticated workspace must remain gated until all module scripts settle');
15 assert(core.includes('window.FinoraOrganizationContextReady')&&core.includes('organizationAccount'),'Profile and license lookup must wait for the organization account adapter');
scripts/organization-manager-read-state.spec.js new
+81
@@ -0,0 +1,81 @@
1 +const {test,expect}=require('@playwright/test');
2 +test.setTimeout(15000);
3 +const BASE=process.env.FINORA_TEST_BASE_URL||'http://127.0.0.1:4173/index.html';
4 +async function fixture(page){
5 + await page.route(/https:\/\/[^/]*supabase\.co\//,r=>r.abort());
6 + await page.goto(BASE,{waitUntil:'domcontentloaded'});
7 + await page.waitForFunction(()=>window.FinoraStartupStatus?.extensionsReady&&window.FinoraStartupStatus?.authChecked);
8 + await page.evaluate(()=>{
9 + currentUser={id:'QA_OWNER',role:'user',isOrganizationOwner:true,organizationId:'QA_ORG',organizationName:'سازمان آزمایشی',organizations:[],modules:['full_suite'],commercialModules:['full_suite'],modulePermissions:[],maxUsers:5,maxCompanies:3,subscription:{type:'lifetime',status:'active',endDate:'2099-01-01'}};
10 + COLLS.forEach(k=>datastore[k]=[]);saveDatastore=()=>{};
11 + sb.from=table=>({select(){return this},eq(){return this},in(){return this},order(){return this},then(resolve,reject){return Promise.resolve({data:table==='organization_members'?[{id:'QA_MEMBER',user_id:'QA_OWNER',status:'active',is_owner:true}]:[],error:null}).then(resolve,reject)}});
12 + sb.rpc=async(name)=>({data:name==='organization_capacity_summary'?{active_users:1,max_users:5,company_count:1,max_companies:3,modules:['full_suite'],status:'active'}:[],error:null});
13 + document.querySelector('#auth-screen').style.display='none';document.body.classList.remove('shell-panel-collapsed');refreshAllSurfaces();
14 + });
15 +}
16 +test('organization access opens a visible loading dialog and reports failed membership reads',async({page})=>{
17 + await fixture(page);
18 + const errors=[];page.on('pageerror',error=>errors.push(error.message));
19 + await page.evaluate(()=>{
20 + const base=sb.from;
21 + sb.from=table=>table!=='organization_members'?base(table):{select(){return this},eq(){return this},then(resolve,reject){return new Promise(done=>{window.__finishMembers=()=>done({data:null,error:{message:'PRIVATE_BACKEND_DETAIL'}})}).then(resolve,reject)}};
22 + });
23 + await page.locator('#module-rail [data-module="settings"]').click();
24 + await page.locator('#module-panel-links [data-task="organization-access"]').click();
25 + const modal=page.locator('#finora-org-access-modal.active');
26 + await expect(modal).toBeVisible();
27 + await expect(modal).toContainText('در حال دریافت');
28 + await page.evaluate(()=>window.__finishMembers());
29 + await expect(modal).toContainText('دریافت اطلاعات سازمان انجام نشد');
30 + await expect(modal).not.toContainText('PRIVATE_BACKEND_DETAIL');
31 + await expect(modal.getByRole('button',{name:'تلاش دوباره',exact:true})).toBeVisible();
32 + await modal.getByRole('button',{name:'بستن',exact:true}).click();
33 + await expect(modal).toHaveCount(0);
34 + expect(errors).toEqual([]);
35 +});
36 +
37 +test('failed organization read can retry and load existing member and invitation controls',async({page})=>{
38 + await fixture(page);
39 + await page.evaluate(()=>{const base=sb.from;let fail=true;sb.from=table=>{if(table!=='organization_members'||!fail)return base(table);return {select(){return this},eq(){return this},then(resolve,reject){fail=false;return Promise.resolve({data:null,error:{message:'synthetic-error'}}).then(resolve,reject)}}}});
40 + await page.locator('#module-rail [data-module="settings"]').click();
41 + await page.locator('#module-panel-links [data-task="organization-access"]').click();
42 + await page.getByRole('button',{name:'تلاش دوباره',exact:true}).click();
43 + await expect(page.locator('#org-member-email')).toBeVisible();
44 + await expect(page.locator('#org-invitation-card')).toBeAttached();
45 + await expect(page.locator('#enterprise-org-dashboard')).toBeAttached();
46 +});
47 +
48 +test('closing a pending organization read prevents stale response replacing reopened panel',async({page})=>{
49 + await fixture(page);
50 + await page.evaluate(()=>{const base=sb.from;let first=true;sb.from=table=>{if(table!=='organization_members'||!first)return base(table);return {select(){return this},eq(){return this},then(resolve,reject){first=false;return new Promise(done=>window.__lateOrg=()=>done({data:null,error:{message:'old failure'}})).then(resolve,reject)}}}});
51 + await page.locator('#module-rail [data-module="settings"]').click();
52 + await page.locator('#module-panel-links [data-task="organization-access"]').click();
53 + await page.locator('#finora-org-access-modal').getByRole('button',{name:'بستن',exact:true}).click();
54 + await page.locator('#module-panel-links [data-task="organization-access"]').click();
55 + await expect(page.locator('#org-invitation-card')).toBeAttached();
56 + await page.evaluate(()=>window.__lateOrg());
57 + await expect(page.locator('#org-member-email')).toBeVisible();
58 + await expect(page.locator('#finora-org-access-modal')).not.toContainText('ORG_PANEL_READ_FAILED');
59 +});
60 +
61 +test('organization read has a bounded wait and stays closed after late completion',async({page})=>{
62 + await fixture(page);await page.clock.install();
63 + await page.evaluate(()=>{sb.from=()=>({select(){return this},eq(){return this},then(resolve,reject){return new Promise(()=>{}).then(resolve,reject)}})});
64 + await page.locator('#module-rail [data-module="settings"]').click();
65 + await page.locator('#module-panel-links [data-task="organization-access"]').click();
66 + await page.clock.runFor(20010);
67 + await expect(page.locator('#finora-org-access-modal')).toContainText('ORG_PANEL_READ_FAILED');
68 + await page.locator('#finora-org-access-modal').getByRole('button',{name:'بستن',exact:true}).click();
69 + await expect(page.locator('#finora-org-access-modal')).not.toHaveClass(/active/);
70 +});
71 +
72 +test('invitation read failure remains visible while existing member controls still load',async({page})=>{
73 + await fixture(page);
74 + await page.evaluate(()=>{const base=sb.from;sb.from=table=>table!=='organization_invitations'?base(table):{select(){return this},eq(){return this},order(){return this},then(resolve,reject){return Promise.resolve({data:null,error:{message:'private invitation error'}}).then(resolve,reject)}}});
75 + await page.locator('#module-rail [data-module="settings"]').click();
76 + await page.locator('#module-panel-links [data-task="organization-access"]').click();
77 + await expect(page.locator('#org-member-email')).toBeVisible();
78 + await expect(page.locator('#finora-org-access-modal')).toContainText('دریافت دعوت‌های سازمان انجام نشد');
79 + await expect(page.locator('#finora-org-access-modal')).not.toContainText('private invitation error');
80 + await expect(page.locator('#enterprise-org-dashboard')).toBeAttached();
81 +});