diff --git a/docs/design/REALM-CP-1.0.1.1.md b/docs/design/REALM-CP-1.0.1.1.md index 296dd70c..7cbb502a 100644 --- a/docs/design/REALM-CP-1.0.1.1.md +++ b/docs/design/REALM-CP-1.0.1.1.md @@ -40,7 +40,7 @@ until those adapters are implemented. The displayed quote does not debit money. Git/release version is 1.0.1.1. The user manages any saved header-version override. No game services are restarted or updated by this web rollout. PR337 stays open. -Next: separate cleanup PR, then design review. Later kit/item update integrates +Next: finish J.A.R.V.I.S. publishing, applications and promotion adapters for the shared workspaces before cleanup. PR392 is held; its earlier shell must not overwrite the newer CP changes. Later kit/item update integrates tools, weapons and banners into clan equipment using existing generator code, MK I-XIV metadata and native rarity. No equipment-stat effects are enabled here. @@ -49,3 +49,13 @@ local leadership retains access to Heir, Consort and specialist appointments; local succession does not inherit the mother's deed or restore independent political powers. The mother retains final deed authority. This remains a required rule for the later relationship/transfer handlers, not a claimed completed feature. + +## Completion of the visible copies + +PR393 adds the missing Company/Politics upper tiles, shared searchable register renderer and direct public profile routes. Reuse `clan-directory-view.mjs` with its `kind` option; Company profiles are `/companies/` and protected political Houses are `/political-houses/`. `public-organisations.mjs` projects active companies and verified current office terms. Missing company roster information remains unpublished; no fabricated population, charter or deed is inferred. + +PR394 connects Company identity and Company/Politics MOTD through one `organisation-editor.mjs` and `organisation-settings-route.mjs`. The existing `organisation_motd` table remains authoritative. Company founders/CEOs manage company identity; current sole officeholders manage political MOTD while protected office identity remains fixed. Writes require origin/session/game access, locked current authority, revision checks and audit. The shared dashboard uses `loadMotd` for display only. + +Official requested news can be seeded once from `scripts/news-announcements.json`, separately from development patchnote bundles; the existing news outboxes handle distribution. The summary explicitly identifies the unconnected J.A.R.V.I.S. posting work. + +Register browsing follows the clan access convention: available to signed-in community users; individual company and political House profiles remain publicly readable. Anonymous register pages offer sign-in rather than returning organisation rows. diff --git a/website/node/public-organisations.mjs b/website/node/public-organisations.mjs index d16ad6ac..b582bb45 100644 --- a/website/node/public-organisations.mjs +++ b/website/node/public-organisations.mjs @@ -1,3 +1,4 @@ +import {identity} from './auth.mjs'; import {readGovernmentOffices} from './public-government.mjs'; const assets='https://www.dunerealms.com/assets/'; // Public projections contain no account identifiers, private keys or financial records. @@ -7,11 +8,13 @@ export async function readPublicOrganisations(db,kind,now=Date.now()){ const {results=[]}=await db.prepare("SELECT c.slug,c.name,c.description,c.created_at,a.username AS owner_username,a.display_name AS owner_name FROM corrino_companies c LEFT JOIN site_accounts a ON a.id=c.ceo_account_id AND a.password_hash NOT LIKE '!%' WHERE c.status='active' ORDER BY c.name").all(); return results.map(c=>({...c,id:c.slug,tag:c.slug,emblem:assets+'guild.webp',standing:'Registered company',realm:'Spacing Guild · Commerce',member_count:null,members:c.owner_username?[{username:c.owner_username,title:'Chief Executive'}]:[]})); } -export function createPublicOrganisations(db,{clock=Date.now}={}){return async request=>{ +export function createPublicOrganisations(db,{clock=Date.now,authenticate=r=>identity(r,db)}={}){return async request=>{ const url=new URL(request.url),match=/^\/api\/public\/(companies|political-houses)(?:\/([a-z0-9_-]{1,64}))?\/?$/i.exec(url.pathname); const reply=(data,status=200)=>Response.json(data,{status,headers:{'Cache-Control':'no-store'}}); if(!['GET','HEAD'].includes(request.method))return reply({message:'Read-only organisation register.'},405); if(!match||url.search)return reply({message:'Organisation not found.'},404); + // Registers are community-visible to signed-in users; individual profiles stay public. + if(!match[2]&&!await authenticate(request))return reply({message:'Sign in to browse the organisation register.'},401); try{const kind=match[1]==='companies'?'company':'politics',rows=await readPublicOrganisations(db,kind,clock()),record=match[2]?rows.find(r=>r.tag.toLowerCase()===match[2].toLowerCase()):null; if(match[2]&&!record)return reply({message:'Organisation not found.'},404); return request.method==='HEAD'?new Response(null,{headers:{'Cache-Control':'no-store'}}):reply(record?{kind,organisation:record}:{kind,organisations:rows}); diff --git a/website/node/public/organisation-public.js b/website/node/public/organisation-public.js index d8b764c5..095ed87f 100644 --- a/website/node/public/organisation-public.js +++ b/website/node/public/organisation-public.js @@ -6,7 +6,7 @@ const [route,id]=location.pathname.split('/').filter(Boolean),company=route==='c document.body.classList.add(company?'public-company':'public-politics'); const back=document.querySelector('.public-clan>nav a');back.href='/'+route;back.textContent='← '+noun+' register'; try{ - const response=await fetch('/api/public/'+route+(id?'/'+encodeURIComponent(id):''),{cache:'no-store',credentials:'omit'}),data=await response.json();if(!response.ok)throw Error(data.message||'Register unavailable.'); + const response=await fetch('/api/public/'+route+(id?'/'+encodeURIComponent(id):''),{cache:'no-store',credentials:id?'omit':'same-origin'}),data=await response.json();if(!response.ok)throw Object.assign(Error(data.message||'Register unavailable.'),{status:response.status}); if(!id){document.title=noun+' Registry | DuneRealms';const search=el('input'),results=el('div');search.type='search';search.placeholder='Search the register…';search.setAttribute('aria-label','Search organisations');host.append(el('h1',noun+' Registry'),search,results);const render=()=>{const q=search.value.toLocaleLowerCase();renderClanRegister(results,data.organisations.filter(r=>[r.name,r.tag,r.owner_name,r.owner_username,r.realm].some(v=>String(v||'').toLocaleLowerCase().includes(q))),{kind});};search.oninput=render;render();} else{ const r=data.organisation;document.title=r.name+' · '+noun+' Register | DuneRealms'; @@ -17,4 +17,4 @@ try{ const deed=el('section',undefined,'clan-deed-card'),art=el('div',undefined,'clan-deed-picture'),copy=el('div');art.setAttribute('role','img');art.setAttribute('aria-label',company?'Company register seal':'Protected office seal');art.style.backgroundImage='url(https://cp.dunerealms.com/assets/'+(company?'organisation-deeds-company-tiers-v1.png':'organisation-deeds-protected-v1.png')+')';art.style.backgroundRepeat='no-repeat';art.style.backgroundSize=company?'300% 100%':'200% 100%';art.style.backgroundPosition=!company&&r.tag==='spacing_guild'?'right center':'left center'; copy.append(el('small',company?'COMMERCIAL REGISTER':'IMPERIAL REGISTER · OFFICE DEED'),el('h2',r.name),el('p',r.standing));if(r.created_at)copy.append(el('p','Est. '+formatDuneDate(Number(r.created_at))));if(r.term)copy.append(el('p','Term: '+formatDuneDate(r.term.startsAt)+' – '+formatDuneDate(r.term.expiresAt)));deed.append(art,copy);host.append(hero,about,deed); }status.hidden=true; -}catch(error){status.textContent=error.message;host.replaceChildren();} +}catch(error){status.textContent=error.message;host.replaceChildren();if(error.status===401){const login=el('a','Sign in →');login.href='/login.html?return_to='+encodeURIComponent(location.pathname);host.append(login);}} diff --git a/website/tests/public-organisation-register.test.mjs b/website/tests/public-organisation-register.test.mjs index 2122d74d..33e6a377 100644 --- a/website/tests/public-organisation-register.test.mjs +++ b/website/tests/public-organisation-register.test.mjs @@ -4,12 +4,13 @@ import {LocalD1} from './d1-adapter.mjs'; import {createPublicOrganisations} from '../node/public-organisations.mjs'; const schema="CREATE TABLE site_accounts(id TEXT,username TEXT,display_name TEXT,password_hash TEXT);CREATE TABLE corrino_companies(slug TEXT,name TEXT,description TEXT,created_at INT,ceo_account_id TEXT,status TEXT);CREATE TABLE political_office_terms(kind TEXT,faction TEXT,office TEXT,starts_at INT,expires_at INT,outcome TEXT,user_id TEXT);INSERT INTO site_accounts VALUES('a','Leader','A leader','hash');INSERT INTO corrino_companies VALUES('active-company','Enterprise','Public introduction',1,'a','active'),('pending-company','Private application','Do not expose',2,'a','pending');INSERT INTO political_office_terms VALUES('house','atreides','house_leader',10,100,'winner','a');"; test('company register and profile expose only active public identity, never invent roster counts',async()=>{ - const db=new LocalD1(schema);try{const api=createPublicOrganisations(db,{clock:()=>50}),get=path=>api(new Request('https://www.dunerealms.com/api/public/'+path)); + const db=new LocalD1(schema);try{const api=createPublicOrganisations(db,{clock:()=>50,authenticate:async()=>({id:'reader'})}),get=path=>api(new Request('https://www.dunerealms.com/api/public/'+path)); const listing=await(await get('companies')).json();assert.equal(listing.organisations.length,1);assert.equal(listing.organisations[0].member_count,null);assert.equal(listing.organisations[0].owner_username,'Leader');assert.ok(!JSON.stringify(listing).includes('ceo_account_id')); assert.equal((await get('companies/pending-company')).status,404);assert.equal((await get('companies/active-company')).status,200);assert.equal((await get('companies?account=a')).status,404); assert.equal((await api(new Request('https://www.dunerealms.com/api/public/companies',{method:'POST'}))).status,405); }finally{db.close();} }); +test('organisation registers require sign-in while direct company and political profiles remain public',async()=>{const db=new LocalD1(schema);try{const api=createPublicOrganisations(db,{clock:()=>50,authenticate:async()=>null});for(const path of ['companies','political-houses'])assert.equal((await api(new Request('https://www.dunerealms.com/api/public/'+path))).status,401);for(const path of ['companies/active-company','political-houses/atreides'])assert.equal((await api(new Request('https://www.dunerealms.com/api/public/'+path))).status,200);}finally{db.close();}}); test('political public profiles follow active unambiguous office terms, retain vacancies and expire holders',async()=>{ const db=new LocalD1(schema);let now=50;try{const api=createPublicOrganisations(db,{clock:()=>now}),get=async()=>await(await api(new Request('https://www.dunerealms.com/api/public/political-houses/atreides'))).json(); let data=await get();assert.equal(data.organisation.member_count,1);assert.equal(data.organisation.members[0].username,'Leader');assert.match(data.organisation.emblem,/assets\/seals\//);now=100;data=await get();assert.equal(data.organisation.member_count,0);assert.equal(data.organisation.term,null);assert.equal(data.organisation.owner_username,undefined);