Align credit navigation and hide staff oversight from personal banking

This commit is contained in:
unimatrixgit 2026-11-14 17:23:30 +01:00
commit 60cb3f06d9
5 changed files with 6 additions and 4 deletions

View file

@ -1,6 +1,6 @@
import {NATIVE_SERVICES,nativeServiceAccess} from './cp-v2-native-services.mjs';
import {canSubmitDevRequest} from '../dev-request-access.mjs';
const legacy={"account-authorisations":"web.bank.staff.view","tax-treasury":"web.bank.staff.manage","bank-dashboard":"web.bank.personal.view","loan-centre":"web.bank.personal.view","loan-administration":"web.bank.staff.manage","electoral-roll":"web.menu.game","imperial-inbox":"web.mail.internal.view","faction-inbox":"web.mail.internal.view","staff-inbox":"web.mail.staff.view","clan-inbox":"web.mail.internal.view","council-motd":"web.menu.game","applications":"web.menu.game","formal-council":"web.menu.game","shared-inbox":"web.mail.internal.view","house-elections":"web.menu.game","imperial-elections":"web.menu.game","imperial-command":"web.menu.game","imperial-water":"web.menu.game","imperial-spice":"web.menu.game","discord-link":"web.menu.security","support-management":"web.tickets.admin","landsraad":"web.menu.game","hosting-control":"web.menu.security","user-management":"web.accounts.view","manual-seals":"web.accounts.assign","company-management":"web.accounts.assign","community-goals":"web.community.manage","marketplace-home":"web.menu.inventory","adventure-home":"web.menu.game","account-home":"web.menu.security","server-kits":"web.ranks.manage","kit-checkout":"web.menu.inventory","rewards-codes":"web.menu.rewards","transactions":"web.menu.inventory","kits-exchange":"web.menu.inventory","redeem-code":"web.menu.rewards","discovery-rewards":"web.quests.view","shop-settings":"web.menu.inventory","exchange-settings":"web.menu.inventory","shop-admin":"web.shop.support","exchange-settings-admin":"web.exchange.manage","user-home":null,"staff-home":null,"exchange":"web.menu.game","clans":"web.menu.game","imperial-atelier":"web.menu.game","personal-bank":"web.bank.personal.view","staff-bank":"web.bank.staff.view","clan-portal":"web.menu.game","clan-shops":"web.menu.game","clan-kits":"web.menu.game","clan-bank":"web.menu.game","clan-settings":"web.menu.game","clan-quests":"web.menu.game","clan-quests-player":"web.menu.game","clan-quests-clan":"web.menu.game","clan-quests-guild":"web.menu.game","quests":"web.quests.view","quests-admin":"web.quests.manage","game":"web.menu.game","webmail":"web.menu.security","git-admin":"web.git.admin","git-control":"web.menu.security","site-profile":"web.menu.security","planetary-inventory":"web.menu.inventory","rewards":"web.menu.rewards","security":"web.menu.security","server-operations":"web.menu.servers","staff":"web.menu.administration","permissions":"web.menu.permissions","game-permissions":"web.ranks.manage","items":"web.menu.items","staff-manual":"web.menu.staffmanual","luckperms":"web.menu.luckperms","tickets":"web.menu.tickets","staff-tickets":"web.tickets.staff","forum-admin":"web.menu.forum","exchange-admin":"web.menu.exchange","website-posts":"web.menu.posts","bans":"web.menu.bans","ban-evidence":"web.menu.bans","kit-publishing":"web.ranks.manage","kit-claims":"web.ranks.manage","company-management-v2":"web.accounts.assign","company-audit":"web.accounts.assign","seal-generator":"web.accounts.assign","bank-audit":"web.bank.staff.view","stock-admin":"web.exchange.manage","stock-surveillance":"web.exchange.manage","git-repositories":"web.menu.security","mail-admin":"web.menu.administration"};
const legacy={"account-authorisations":"web.bank.staff.view","tax-treasury":"web.bank.staff.manage","bank-dashboard":"web.bank.staff.view","company-finance":"web.bank.staff.view","loan-centre":"web.bank.personal.view","loan-administration":"web.bank.staff.view","electoral-roll":"web.menu.game","imperial-inbox":"web.mail.internal.view","faction-inbox":"web.mail.internal.view","staff-inbox":"web.mail.staff.view","clan-inbox":"web.mail.internal.view","council-motd":"web.menu.game","applications":"web.menu.game","formal-council":"web.menu.game","shared-inbox":"web.mail.internal.view","house-elections":"web.menu.game","imperial-elections":"web.menu.game","imperial-command":"web.menu.game","imperial-water":"web.menu.game","imperial-spice":"web.menu.game","discord-link":"web.menu.security","support-management":"web.tickets.admin","landsraad":"web.menu.game","hosting-control":"web.menu.security","user-management":"web.accounts.view","manual-seals":"web.accounts.assign","company-management":"web.accounts.assign","community-goals":"web.community.manage","marketplace-home":"web.menu.inventory","adventure-home":"web.menu.game","account-home":"web.menu.security","server-kits":"web.ranks.manage","kit-checkout":"web.menu.inventory","rewards-codes":"web.menu.rewards","transactions":"web.menu.inventory","kits-exchange":"web.menu.inventory","redeem-code":"web.menu.rewards","discovery-rewards":"web.quests.view","shop-settings":"web.menu.inventory","exchange-settings":"web.menu.inventory","shop-admin":"web.shop.support","exchange-settings-admin":"web.exchange.manage","user-home":null,"staff-home":null,"exchange":"web.menu.game","clans":"web.menu.game","imperial-atelier":"web.menu.game","personal-bank":"web.bank.personal.view","staff-bank":"web.bank.staff.view","clan-portal":"web.menu.game","clan-shops":"web.menu.game","clan-kits":"web.menu.game","clan-bank":"web.menu.game","clan-settings":"web.menu.game","clan-quests":"web.menu.game","clan-quests-player":"web.menu.game","clan-quests-clan":"web.menu.game","clan-quests-guild":"web.menu.game","quests":"web.quests.view","quests-admin":"web.quests.manage","game":"web.menu.game","webmail":"web.menu.security","git-admin":"web.git.admin","git-control":"web.menu.security","site-profile":"web.menu.security","planetary-inventory":"web.menu.inventory","rewards":"web.menu.rewards","security":"web.menu.security","server-operations":"web.menu.servers","staff":"web.menu.administration","permissions":"web.menu.permissions","game-permissions":"web.ranks.manage","items":"web.menu.items","staff-manual":"web.menu.staffmanual","luckperms":"web.menu.luckperms","tickets":"web.menu.tickets","staff-tickets":"web.tickets.staff","forum-admin":"web.menu.forum","exchange-admin":"web.menu.exchange","website-posts":"web.menu.posts","bans":"web.menu.bans","ban-evidence":"web.menu.bans","kit-publishing":"web.ranks.manage","kit-claims":"web.ranks.manage","company-management-v2":"web.accounts.assign","company-audit":"web.accounts.assign","seal-generator":"web.accounts.assign","bank-audit":"web.bank.staff.view","stock-admin":"web.exchange.manage","stock-surveillance":"web.exchange.manage","git-repositories":"web.menu.security","mail-admin":"web.menu.administration"};
export function visibleCPItem(user,workspace,item){
if(workspace==='bank'&&item.id==='federal-reserve')return true;
if(!user||!Array.isArray(user.permissions))return false;

View file

@ -7,7 +7,7 @@ import {mountPostbankPayments} from './cp-v2-postbank-payments.mjs';
import {mountPostbankFoundation,FOUNDATION_PAGES} from './cp-v2-postbank-foundation.mjs';
import {createCPV2ContentPage,element as el} from './cp-v2-page-template.mjs';
export const BANK_IMPORTS=Object.freeze({'bank-information':{kind:'foundation'},'bank-overview':{kind:'foundation'},'personal-bank':{kind:'foundation'},'bank-transfers':{kind:'payments'},'bank-statements':{kind:'payments'},'bank-history':{kind:'payments'},'staff-bank':{kind:'admin'}});
const titles={'bank-transfers':'Transfers','bank-statements':'Transactions','bank-history':'Transactions','bank-beneficiaries':'Beneficiaries','loan-centre':'Loan Applications','bank-loans':'My Loans','loan-administration':'Loan Management','bank-dashboard':'Operations Dashboard','staff-bank':'Treasury Accounts','company-finance':'Business Accounts','bank-audit':'Audit Log'};
const titles={'bank-transfers':'Transfers','bank-statements':'Transactions','bank-history':'Transactions','bank-beneficiaries':'Beneficiaries','loan-centre':'Loans & Grants','bank-loans':'My Credit','loan-administration':'Credit Management','bank-dashboard':'Operations Dashboard','staff-bank':'Treasury Accounts','company-finance':'Business Accounts','bank-audit':'Audit Log'};
export function mountBankPage(host,id,{fetcher=fetch,accountId=null}={}){
if(id==='bank-authorisations')return mountAuthorisations(host,{fetcher});
if(id==='federal-reserve')return mountReserveLedger(host,{fetcher});

View file

@ -35,7 +35,7 @@ export function mountPostbankCredit(host,id,{fetcher=fetch}={}){
const box=el('section',undefined,'pb-box'),motivation=el('textarea');motivation.required=true;motivation.minLength=10;motivation.maxLength=4000;box.append(el('h3','Request this credit'));const form=instruction(box,product.group==='grants'?'Accept launch grant':'Submit for bank review','/api/bank/credit/apply',()=>({...values,motivation:motivation.value.trim(),accepted:true,termsVersion:view.termsVersion}),{reason:false,confirmation:'I accept the credit terms: '+data.quote.amount+' DM, '+data.quote.annualRate+'% annually, '+data.quote.monthly+' DM per month. '+(product.group==='grants'?'Disbursement is queued; this grant must be repaid.':'A bank decision and separate offer acceptance are required before funding.')});form.prepend(field('Purpose and repayment plan',motivation));host.append(box);
}
function contractDetails(host,loan,staff=false){
let loaded=false;const expand=el('details'),summary=el('summary','+ Contract details & actions'),body=el('div');expand.append(summary,body);host.append(expand);expand.ontoggle=async()=>{if(!expand.open||loaded)return;loaded=true;body.textContent='Loading current contract…';try{const d=await api.request((staff?'/api/bank/admin/credit/details':'/api/bank/credit/details')+'?loanId='+encodeURIComponent(loan.id));if(!active)return;body.replaceChildren(el('p',loan.motivation),el('p','Annual rate: '+d.quote.annualRate+'% · Total repayment: '+d.quote.totalRepayment+' DM · Collateral: '+d.collateral+' DM'),el('p','Settlement estimate today: '+d.settlement+' DM'),el('p',d.decision||'No decision recorded.'));if(d.replacedBy)body.append(el('p','Replaced by refinancing contract '+d.replacedBy+'. Original history is retained.'));for(const notice of d.notices||[]){const box=el('aside',undefined,'pb-credit-notice'+(d.state==='arrears'?' pb-credit-notice-alert':''));box.append(el('strong',notice.subject),el('p',notice.body));body.append(box);}const enabled=staff?view.processing==='active':view.intakeEnabled;
let loaded=false;const expand=el('details'),summary=el('summary','+ Contract details & actions'),body=el('div');expand.append(summary,body);host.append(expand);expand.ontoggle=async()=>{if(!expand.open||loaded)return;loaded=true;body.textContent='Loading current contract…';try{const d=await api.request((staff?'/api/bank/admin/credit/details':'/api/bank/credit/details')+'?loanId='+encodeURIComponent(loan.id));if(!active)return;body.replaceChildren(el('p',loan.motivation),el('p','Annual rate: '+d.quote.annualRate+'% · Total repayment: '+d.quote.totalRepayment+' DM · Collateral: '+d.collateral+' DM'),el('p','Settlement estimate today: '+d.settlement+' DM'),el('p',d.decision||'No decision recorded.'));if(d.replacedBy)body.append(el('p','Replaced by refinancing contract '+d.replacedBy+'. Original history is retained.'));for(const notice of d.notices||[]){const box=el('aside',undefined,'pb-credit-notice'+(d.state==='arrears'?' pb-credit-notice-alert':''));box.append(el('strong',notice.subject),el('p',notice.body));body.append(box);}const enabled=staff?view.processing==='active'&&view.canManage:view.intakeEnabled;
if(enabled&&!staff){if(d.state==='offered')instruction(body,'Accept credit offer','/api/bank/credit/action',()=>({loanId:loan.id,action:'accept',expectedVersion:d.version,reason:'Accepted the disclosed credit offer'}),{reason:false,confirmation:'I accept the full repayment cost above and authorise the collateral reservation before disbursement.'});if(['submitted','approved_pending','offered','payout_queued'].includes(d.state))instruction(body,'Withdraw application','/api/bank/credit/action',()=>({loanId:loan.id,action:'withdraw'}));if(['active','arrears'].includes(d.state))instruction(body,'Make a repayment','/api/bank/credit/action',()=>({loanId:loan.id,action:'repay'}),{amount:true,confirmation:'Debit the linked current account at the next four-hour bank window. Earned interest is charged; future interest is waived. Confirmed reserved funds retain their bank value date.'});}
if(enabled&&staff){if(d.state==='submitted'&&loan.canReview){instruction(body,'Approve application','/api/bank/admin/credit/decision',()=>({loanId:loan.id,action:'approve'}),{risk:loan.score.score<400||loan.score.flags.includes('High Monthly Commitments')});instruction(body,'Decline application','/api/bank/admin/credit/decision',()=>({loanId:loan.id,action:'decline'}));}if(d.state==='arrears')instruction(body,'Recover pledged collateral','/api/bank/admin/credit/recover',()=>({loanId:loan.id,action:'recover'}),{amount:true,confirmation:'Recover only this contract’s pledged DM to reduce its debt. No inventory is involved.'});}
if(d.schedule.length){const {wrap,body:rows}=grid(['Due date','Principal · DM','Interest · DM','Paid · DM','Status']);for(const row of d.schedule){const tr=el('tr');for(const value of [new Date(row.dueAt).toLocaleDateString('en-GB'),row.principal,row.interest,row.paid,human(row.state)])tr.append(el('td',value));rows.append(tr);}body.append(wrap);}else body.append(el('p','The repayment schedule starts only when funds are disbursed.'));

File diff suppressed because one or more lines are too long

View file

@ -6,3 +6,5 @@ test('borrowing tabs filter product cards and simulation replaces the catalogue
test('credit groups reuse the banking package palette',()=>{assert.equal(creditTheme({key:'grant_start'}),'start');assert.equal(creditTheme({key:'grant_build'}),'connect');assert.equal(creditTheme({key:'grant_advance'}),'scale');assert.equal(creditTheme({key:'business_loan'}),'connect');assert.equal(creditTheme({key:'civic_loan'}),'civic');assert.equal(creditTheme({key:'personal_refinance',group:'refinancing'}),'scale');});
test('application confirmation and uncertain retry retain the same request and frozen disclosures',()=>fixture(async({nodes,calls})=>{nodes().find(n=>n.tagName==='BUTTON'&&n.textContent==='Simulate repayments').onclick();await nodes().find(n=>n.tagName==='FORM').onsubmit({preventDefault(){}});let form=nodes().find(n=>n.className==='pb-credit-action-form');const motivation=all(form).find(n=>n.tagName==='TEXTAREA'),check=all(form).find(n=>n.type==='checkbox');motivation.value='A genuine loan purpose';await form.onsubmit({preventDefault(){}});assert.equal(calls.filter(c=>c.path.endsWith('/apply')).length,0);check.checked=true;await form.onsubmit({preventDefault(){}});assert.equal(motivation.disabled,true);assert.ok(all(form).some(n=>n.tagName==='BUTTON'&&n.textContent==='Retry same instruction'));await form.onsubmit({preventDefault(){}});const posts=calls.filter(c=>c.path.endsWith('/apply'));assert.equal(posts.length,2);assert.equal(posts[0].body,posts[1].body);assert.equal(JSON.parse(posts[0].body).accountId,'1');assert.equal(JSON.parse(posts[0].body).motivation,'A genuine loan purpose');},{enabled:true,uncertain:true}));
test('bank oversight menus require staff view permission rather than ordinary personal banking',async()=>{const {visibleCPItem}=await import('../control-panel/public/cp-v2/cp-v2-access.mjs');for(const id of ['bank-dashboard','company-finance','loan-administration']){assert.equal(visibleCPItem({permissions:['web.bank.personal.view']},'bank',{id}),false);assert.equal(visibleCPItem({permissions:['web.bank.staff.view']},'bank',{id}),true);}assert.equal(visibleCPItem({permissions:['web.bank.personal.view']},'bank',{id:'loan-centre'}),true);});