Link the verified official owner alt and publish the official identity showcase

This commit is contained in:
unimatrixgit 2026-11-15 03:44:02 +01:00
commit a8956bc88e

View file

@ -1,5 +1,6 @@
import {effectiveOrganisationAccess} from './organisation-effective.mjs';
import {assignmentLabel,validStaffRole} from './organisation-model.mjs';
import {organisationSubject} from './official-account.mjs';
const SERVICE_ID='f7b88778-f0bc-41cc-9227-d8ef2f52264d';
const legacyStaff=new Set(['owners','owner','corestaff','staff','network_admin','web_net_admin','web_net_owner','web_network','official_account','admin','administrator','moderator','guardian','streamer','twitch','yt']);
const privileged=node=>/^web\.(accounts\.|ranks\.|servers\.|luckperms\.|tickets\.(staff|admin|appeals)|bank\.staff\.|payroll\.|posts\.(edit|publish)|items\.manage|bans\.|forum\.moderate|git\.admin)/.test(node)||/^cp\.(accounts\.|ranks\.|servers\.|luckperms\.|bank\.staff\.|items\.manage)/.test(node)||/^dune\.(admin|staff\.|moderation\.|ban\.|unban\.)/.test(node)||node.startsWith('duneprotect.')||/^(?:web|cp)\.menu\.(?:administration|staffmanual|permissions|servers|luckperms|bans|forum|items|posts)$/.test(node)||/^web\.(?:shop\.support|bank\.projects\.approve|mail\.staff\.)/.test(node);
@ -7,15 +8,16 @@ const nativeEditor=node=>['web.luckperms.edit','cp.luckperms.edit','luckperms.ed
export async function organisationRuntimeAccess(db,user,{registry,basicRank,legacyRanks,clock=Date.now}={}){
const now=clock();
const snapshot=await db.readSnapshot(async reader=>{
const principal=(await reader.query('SELECT principal_kind FROM org_control_principals WHERE user_id=?',[user.id]))[0];
const subject=await organisationSubject(reader,user.id);
const principal=(await reader.query('SELECT principal_kind FROM org_control_principals WHERE user_id=?',[subject.userId]))[0];
if(principal?.principal_kind==='service'){
const service=(await reader.query('SELECT service_uuid,game_link_exempt FROM site_account_policies WHERE user_id=?',[user.id]))[0];
if(user.id!==SERVICE_ID||!service?.game_link_exempt||service.service_uuid!=='00000000-0000-4000-8000-00000000de01')throw Error('Invalid service control identity.');
return {service:true};
}
const assignments=await reader.query("SELECT id,scope_type,scope_key,role_key,status,starts_at,ends_at FROM org_assignments WHERE user_id=? AND scope_type IN ('organisation','department','branch') AND status='active' AND starts_at<=? AND (ends_at IS NULL OR ends_at>?)",[user.id,now,now]);
const assignments=await reader.query("SELECT id,scope_type,scope_key,role_key,status,starts_at,ends_at FROM org_assignments WHERE user_id=? AND scope_type IN ('organisation','department','branch') AND status='active' AND starts_at<=? AND (ends_at IS NULL OR ends_at>?)",[subject.userId,now,now]);
const policies=await reader.query('SELECT scope_type,scope_key,role_key,permissions_json,version FROM org_role_policies',[]);
return {assignments,access:effectiveOrganisationAccess({assignments,policies,registry,principalKind:principal?.principal_kind,now})};
return {subject,assignments,access:effectiveOrganisationAccess({assignments,policies,registry,principalKind:principal?.principal_kind,now})};
});
if(snapshot.service)return null; // Preserve the existing verified Dev service access, including native tools.
const citizenRanks=legacyRanks.filter(r=>!legacyStaff.has(r.key)&&!r.key.startsWith('web_')&&!r.key.startsWith('game_'));
@ -27,5 +29,5 @@ export async function organisationRuntimeAccess(db,user,{registry,basicRank,lega
const precedence={owner_ceo:100,executive:90,department_head:80,branch_lead:70,officer:50};
active.sort((a,b)=>(precedence[b.role_key]||0)-(precedence[a.role_key]||0)||a.scope_key.localeCompare(b.scope_key));
const primary=active[0],citizen=ranks.reduce((a,b)=>a.level>=b.level?a:b,basicRank);
return {rank:primary?'org_'+primary.role_key:citizen.key,ranks:[...new Set([...ranks.map(r=>r.key),...active.map(a=>'org_'+a.role_key)])],label:primary?assignmentLabel(primary).roleLabel:citizen.label,level:primary?precedence[primary.role_key]||0:citizen.level,nodes:[...nodes].sort(),organisation:{mode:'active',assignments:active.map(assignmentLabel),missingPolicies:snapshot.access.missingPolicies,blocked:snapshot.access.blocked.length}};
return {rank:primary?'org_'+primary.role_key:citizen.key,ranks:[...new Set([...ranks.map(r=>r.key),...active.map(a=>'org_'+a.role_key)])],label:primary?assignmentLabel(primary).roleLabel:citizen.label,level:primary?precedence[primary.role_key]||0:citizen.level,nodes:[...nodes].sort(),organisation:{mode:'active',permissionPrincipalId:snapshot.subject.userId,officialOwnerAlias:snapshot.subject.alias,assignments:active.map(assignmentLabel),missingPolicies:snapshot.access.missingPolicies,blocked:snapshot.access.blocked.length}};
}