سامانه صدور فاکتور و حسابداری
Mirrored from https://github.com/davoodmehraban89/Factor-easy.git
Synced Dec 3, 22:00 UTC
fix: company form save state and expired-license affordance (current main) (#141)
* fix: enforce company form action-state and license permission * docs: preserve verified company-form work and outstanding release gates
davoodmehraban89 committed
Oct 14, 2026 at 20:52 UTC
9693b342670915271e3b471cf68da44b2530d99a
2 files changed
+40
PROJECT_STATE.md
+6
@@ -668,3 +668,9 @@ Owner reports login blocked with generic 'check internet/VPN' network error on l
668
- **Exact protected-main SHA gate verified:** Quality **`38230349289` SUCCESS**, Security **`38230349290` SUCCESS**, Release Gate **`38230688599` SUCCESS**, gated Pages deployment **`38230726054` SUCCESS**. Earlier duplicate Release `38230517388` was CANCELLED, duplicate Pages `38230704316` SKIPPED; excluded from successes.
669
- **Honest external check:** The authorized remote Windows machine `DESKTOP-71SJ63M` was **offline** when post-publish HTTP parity check was attempted; alternate public fetch was inaccessible. Therefore GitHub proves SHA-gated Pages deploy but **direct domain HTTP parity and owner's actual observed latency not independently verified in this last check**. Owner should hard-refresh once at `factoreasy.ir`, record approximate time to see login and time after sign-in; no password/session/network token disclosure. A remaining possible factor is `enterApp()` awaiting `fetchCurrentUser()` and serial tenant `pullAll()` after authentication, not changed without data-consistency tests.
670
- **Acceptance:** Focused Phase-0 startup/performance **FIX_IMPLEMENTED / CONTROLLED_QA_PASSED / PAGES_DEPLOYED**; **OWNER_REAL_ISP_BENCHMARK_OPEN**. F0-01/02/03/04/07 remain unaccepted; Phase 0 **OPEN**. No Auth/RLS/roles, server schema, Supabase data, financial posting or account credentials changed. Rollback: revert PR #100 and rerun guarded Pages; no data rollback.
671
+
672
+### 2026-10-14 Company form action-state / license permission follow-up
673
+- Owner requested autonomous continuation with short summaries after completed work parts.
674
+- Live read-only TinyFish dashboard showed expired organization subscription for an account expected to have lifetime entitlement; license truth is not independently verified against live database. `js/organization-rbac.js` replaces profile subscription with organization license; `js/core.js` `canWrite()` prevents edits when expired. Do not bypass license or change financial data.
675
+- Company editor action state updated in `js/companies.js`: require nonempty name, subsidiary parent, actual edit changes and `canWrite()` before enabling save. Save handler still enforces `requireWrite()`; button tooltip explains blocked license. Source originated PR #140; old branch was behind `main` by one merge and GitHub returned `405` requiring 3 missing status checks despite green Quality/Security workflows. Rebased changes on current `main` in a new PR branch, without bypassing branch protection.
676
+- Verification: previous head `2a8dc526ec4b3eaae077d0614b060e421c081d91` Quality and Security both SUCCESS, but fresh branch CI and production real DOM not yet verified. Next: verify CI and merge gates; test real DOM without modifying production accounting records; investigate organization entitlement only with authorized live DB access.
js/companies.js
+34
@@ -17,6 +17,35 @@ function companyLegalSummary(c){
17
return sector+' · '+form;
18
}
19
20
+// Form-action state: required input, actual changes, and write permission are distinct.
21
+let companyEditBaseline='';
22
+const COMPANY_FORM_FIELDS=['company-entity-type','company-sector','company-legal-form','company-organization-role','company-parent-id','company-activity-type','company-accounting-template','company-name-input','company-phone-input','company-national-input','company-economic-input','company-reg-input','company-postal-input','company-address-input','company-footer-input'];
23
+function companyFormSnapshot(){
24
+ return JSON.stringify(COMPANY_FORM_FIELDS.map(id=>document.getElementById(id)?.value??''));
25
+}
26
+function updateCompanyFormAction(){
27
+ const button=document.getElementById('company-save-btn');
28
+ if(!button)return;
29
+ const hasName=!!document.getElementById('company-name-input')?.value.trim();
30
+ const role=document.getElementById('company-organization-role')?.value;
31
+ const isSubsidiary=document.getElementById('company-entity-type')?.value==='legal'&&role==='subsidiary';
32
+ const valid=hasName&&(!isSubsidiary||!!document.getElementById('company-parent-id')?.value);
33
+ const changed=!editingCompanyId||companyFormSnapshot()!==companyEditBaseline;
34
+ const writeAllowed=typeof canWrite==='function'&&canWrite();
35
+ button.disabled=!(valid&&changed&&writeAllowed);
36
+ button.style.opacity=button.disabled?'0.45':'1';
37
+ button.style.cursor=button.disabled?'not-allowed':'pointer';
38
+ button.title=!writeAllowed?'امکان ثبت یا اصلاح شرکت وجود ندارد؛ وضعیت اشتراک سازمان فعال را بررسی کنید.':button.disabled?(editingCompanyId&&!changed?'ابتدا اطلاعات شرکت را تغییر دهید':'نام شرکت و سایر فیلدهای الزامی را تکمیل کنید'):'';
39
+}
40
+function installCompanyFormActionState(){
41
+ const button=document.getElementById('company-save-btn');
42
+ if(!button||button.dataset.actionStateBound)return;
43
+ button.dataset.actionStateBound='1';
44
+ const form=button.closest('.accordion-item')||button.parentElement;
45
+ form?.addEventListener('input',updateCompanyFormAction);
46
+ form?.addEventListener('change',updateCompanyFormAction);
47
+ updateCompanyFormAction();
48
+}
49
function resetCompanyForm(){
50
editingCompanyId='';
51
['company-name-input','company-phone-input','company-national-input','company-economic-input','company-reg-input','company-postal-input','company-address-input','company-footer-input'].forEach(id=>{
@@ -31,6 +60,7 @@ function resetCompanyForm(){
60
const saveBtn=document.getElementById('company-save-btn');
61
if(saveBtn){saveBtn.innerHTML='➕ ثبت شرکت جدید';saveBtn.className='btn btn-success';}
62
const cancelBtn=document.getElementById('company-edit-cancel-btn');if(cancelBtn)cancelBtn.style.display='none';
63
+ companyEditBaseline='';updateCompanyFormAction();
64
}
65
66
function editCompany(id){
@@ -48,12 +78,15 @@ function editCompany(id){
78
const saveBtn=document.getElementById('company-save-btn');
79
if(saveBtn){saveBtn.innerHTML='💾 ذخیره اصلاحات';saveBtn.className='btn btn-primary';}
80
const cancelBtn=document.getElementById('company-edit-cancel-btn');if(cancelBtn)cancelBtn.style.display='inline-flex';
81
+ companyEditBaseline=companyFormSnapshot();updateCompanyFormAction();
82
const nameInput=document.getElementById('company-name-input');
83
if(nameInput){nameInput.focus();nameInput.scrollIntoView({behavior:'smooth',block:'center'});}
84
}
85
86
function cancelCompanyEdit(){resetCompanyForm();}
87
function commitSaveCompany(){
88
+ updateCompanyFormAction();
89
+ if(document.getElementById('company-save-btn')?.disabled)return;
90
if(!requireWrite())return;
91
if(!currentUser)return;
92
const entity_type=document.getElementById('company-entity-type').value;
@@ -90,6 +123,7 @@ function commitSaveCompany(){
123
refreshAllSurfaces();
124
}
125
function renderCompanies(){
126
+ installCompanyFormActionState();
127
const tbody=document.getElementById('companies-table-body');
128
const invoiceCompSelect=document.getElementById('invoice-company-id');
129
const filterCompSelect=document.getElementById('filter-invoice-company');