forked from unimatrix/web
Read citizen memberships from existing sources and close legacy permission aliases
This commit is contained in:
parent
d0dd371348
commit
2138030e13
7 changed files with 45 additions and 2 deletions
|
|
@ -22,8 +22,9 @@ export function mountCitizenDirectory(host){
|
|||
function choices(label,items,value,onChange){const field=element('label',label,'md-field'),s=element('select');for(const [key,title]of items){const o=element('option',title);o.value=key;s.append(o);}s.value=value;s.onchange=()=>onChange(s.value);field.append(s);return field;}
|
||||
function badge(label){return element('span',label,'md-badge');}
|
||||
function assignments(){const panel=box(context==='staff'?'Staff assignments':'Memberships & offices');
|
||||
if(context==='users')for(const membership of selected.memberships||[]){const row=element('div',undefined,'md-assignment');row.append(element('strong',membership.label),element('p',membership.kind),badge(membership.source));panel.append(row);}
|
||||
if(selected.assignments.length){for(const a of selected.assignments){const card=element('div',undefined,'md-assignment');card.append(element('strong',a.roleLabel),element('p',a.scopeLabel),badge(a.source||'Recorded assignment'));if(a.endsAt)card.append(element('small','Until '+date(a.endsAt)));panel.append(card);}}
|
||||
else panel.append(element('p',context==='staff'?'No new-model staff assignments have been activated for this account.':'No memberships or offices have been registered in the new assignment model yet. Existing memberships remain in their source systems.','md-muted'));
|
||||
else if(context==='staff'||!selected.memberships?.length)panel.append(element('p',context==='staff'?'No new-model staff assignments have been activated for this account.':'No additional memberships or offices are recorded.','md-muted'));
|
||||
if(context==='staff'){
|
||||
panel.append(element('p',assignmentMode==='active'?'Staff assignments control current access. Function changes update central permissions and synchronise connected services.':assignmentMode==='preparing'?'The assignment register is being prepared. Permission activation is pending.':'Current functions are listed above. Open Staff assignments to manage access.','md-note'));
|
||||
if(tab!=='assignments')panel.append(button('Manage assignments',()=>{tab='assignments';renderAccount();}));
|
||||
|
|
|
|||
|
|
@ -88,6 +88,12 @@ duplicate page. Corrections hide the page while retaining history. This metadata
|
|||
does not change login access, linked identity, ranks or bank records. Existing
|
||||
community tribute content is preserved; no real-life death status is inferred.
|
||||
|
||||
Citizen details read earned tiers, house/office/path/Order ranks and current clan
|
||||
membership from the existing registers. They do not expose staff functions in the
|
||||
User view or copy membership authority into the staff register. Legacy User/VIP
|
||||
permission lists cannot retain staff powers through cp.* aliases, native forum
|
||||
administration, job ticket nodes, item issuance or lobby administration.
|
||||
|
||||
## Batch 2: audited assignment editor and policy preparation
|
||||
|
||||
Staff assignments can be recorded and revoked within the manager's scope. One
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import {identity} from './auth.mjs';
|
||||
import {can} from './permissions.mjs';
|
||||
import {ORGANISATION,ASSIGNMENT_ROLES,STAFF_SCOPE_TYPES,assignmentLabel} from './organisation-model.mjs';
|
||||
import {citizenMemberships} from './citizen-memberships.mjs';
|
||||
|
||||
const reply=(data,status=200)=>Response.json(data,{status,headers:{'Cache-Control':'no-store'}});
|
||||
const LEGACY_STAFF=['staff','corestaff','owners','official_account','web_net_admin','web_net_owner','web_network','network_admin','web_dev'];
|
||||
|
|
@ -64,6 +65,7 @@ export function createCitizenDirectory(db,{authenticate=identity,authorize=can,c
|
|||
if(!row)return reply({message:'Account not found.'},404);
|
||||
const current=await assignments([row.id],filter.context);
|
||||
const account={...project(row),assignments:current.map(assignmentLabel)};
|
||||
if(filter.context==='users')account.memberships=await citizenMemberships(db,row.id);
|
||||
// Staff provenance and legacy staff ranks never leave the Staff view.
|
||||
if(filter.context==='staff'){
|
||||
const {results}=await db.prepare('SELECT source_name,source_ref,imported_at FROM staff_source_members WHERE user_id=? ORDER BY source_key').bind(row.id).all();
|
||||
|
|
|
|||
13
website/node/citizen-memberships.mjs
Normal file
13
website/node/citizen-memberships.mjs
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
import {accessFor,rankFor} from './permissions.mjs';
|
||||
const tiers=new Set(['user','vip','patron_caravan','patron_guild','patron_grand','council_member','memorial']);
|
||||
export function citizenRankVisible(rank){return ['house','office','path','order'].includes(rank.kind)||tiers.has(rank.key);}
|
||||
// Read the existing owners of memberships; never create a second authority ledger.
|
||||
export async function citizenMemberships(db,id){
|
||||
const target=await db.prepare('SELECT id,username,role FROM site_accounts WHERE id=?').bind(id).first();
|
||||
if(!target)return [];
|
||||
const access=await accessFor(db,target),items=[];
|
||||
for(const key of access.ranks){if(key.startsWith('org_'))continue;const rank=await rankFor(db,key);if(citizenRankVisible(rank))items.push({key:'rank:'+key,label:rank.label,kind:rank.kind==='access'?'Account tier':rank.kind,source:'Central membership register'});}
|
||||
const {results}=await db.prepare('SELECT c.id,c.name,c.tag,m.clan_role FROM site_clan_members m JOIN site_clans c ON c.id=m.clan_id WHERE m.user_id=? AND c.active=1').bind(id).all();
|
||||
for(const c of results)items.push({key:'clan:'+c.id,label:c.name+(c.tag?' ['+c.tag+']':''),kind:{leader:'Clan Leader',officer:'Clan Officer',member:'Clan Member'}[c.clan_role]||'Clan Member',source:'Clan Center'});
|
||||
return items;
|
||||
}
|
||||
|
|
@ -3,7 +3,14 @@ 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);
|
||||
const privileged=value=>{
|
||||
const node=value.startsWith('cp.')?'web.'+value.slice(3):value;
|
||||
return /^web\.(accounts\.|ranks\.|servers\.|luckperms\.|tickets\.|bank\.staff\.|payroll\.|posts\.(edit|publish)|items\.manage|bans\.|forum\.(moderate|admin)|git\.admin|community\.manage|quests\.manage)/.test(node)
|
||||
||/^dune\.(admin|staff\.|moderation\.|ban\.|unban\.|items\.give|tickets\.staff)/.test(node)
|
||||
||node.startsWith('duneprotect.')||/^dunelobby\.(admin|build)$/.test(node)
|
||||
||/^web\.menu\.(?:administration|staffmanual|permissions|servers|luckperms|bans|forum|items|posts|tickets)$/.test(node)
|
||||
||/^web\.(?:shop\.support|bank\.projects\.approve|mail\.staff\.)/.test(node);
|
||||
};
|
||||
const nativeEditor=node=>['web.luckperms.edit','cp.luckperms.edit','luckperms.editor','luckperms.applyedits','luckperms.trusteditor'].includes(node);
|
||||
export async function organisationRuntimeAccess(db,user,{registry,basicRank,legacyRanks,clock=Date.now}={}){
|
||||
const now=clock();
|
||||
|
|
|
|||
7
website/tests/citizen-memberships.test.mjs
Normal file
7
website/tests/citizen-memberships.test.mjs
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
import test from 'node:test';import assert from 'node:assert/strict';
|
||||
import {citizenRankVisible} from '../node/citizen-memberships.mjs';
|
||||
test('Citizen views retain earned tiers, houses, paths and Order membership while excluding staff titles',()=>{
|
||||
for(const key of ['user','vip','patron_caravan','patron_guild','patron_grand','council_member'])assert(citizenRankVisible({key,kind:'access'}));
|
||||
for(const kind of ['house','office','path','order'])assert(citizenRankVisible({key:'source-role',kind}));
|
||||
for(const key of ['org_owner_ceo','org_officer','staff','corestaff','web_dev','game_admin'])assert(!citizenRankVisible({key,kind:'access'}));
|
||||
});
|
||||
|
|
@ -45,3 +45,10 @@ test('Safe persisted citizen features survive while accidental staff grants on U
|
|||
const result=await organisationRuntimeAccess(database({assignments:[]}),user,{registry:NODES,basicRank:base,legacyRanks:[vip],clock:()=>10});
|
||||
assert(result.nodes.includes('web.mail.internal.view'));assert(result.nodes.includes('web.quests.view'));assert(result.nodes.includes('duneess.chat.colors'));assert(result.ranks.includes('vip'));assert(!result.nodes.includes('web.bank.staff.manage'));assert(!result.nodes.includes('web.accounts.assign'));
|
||||
});
|
||||
test('Citizen ranks cannot retain staff powers through CP aliases, ticket scopes or native administration',async()=>{
|
||||
const unwanted=['cp.community.manage','web.tickets.dev','web.tickets.sales','web.forum.admin','dune.items.give','dunelobby.admin','dunelobby.build'];
|
||||
const base={...DEFAULT_RANKS[0],nodes:[...DEFAULT_RANKS[0].nodes,...unwanted]};
|
||||
const result=await organisationRuntimeAccess(database({assignments:[]}),user,{registry:NODES,basicRank:base,legacyRanks:[],clock:()=>10});
|
||||
for(const node of unwanted)assert(!result.nodes.includes(node),node);
|
||||
assert(result.nodes.includes('dunelobby.visit'));assert(result.nodes.includes('duneess.basics'));
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue

Staff