diff --git a/website/node/staff-roster.mjs b/website/node/staff-roster.mjs index 37a259dc..f00bedb4 100644 --- a/website/node/staff-roster.mjs +++ b/website/node/staff-roster.mjs @@ -31,7 +31,9 @@ export async function publicStaffRoster(db){ for(const user of results){ const access=await accessFor(db,user); if(!access.ranks.some(r=>!['user','vip'].includes(r))||!access.nodes.some(n=>['web.tickets.staff','web.forum.moderate','web.posts.edit','web.ranks.manage'].includes(n)))continue; - const rankLabels=[];for(const key of access.ranks.filter(k=>!['user','vip'].includes(k)))rankLabels.push((await rankFor(db,key)).label); + const currentRanks=await Promise.all(access.ranks.filter(k=>!['user','vip'].includes(k)).map(key=>rankFor(db,key))); + currentRanks.sort((a,b)=>b.level-a.level||a.label.localeCompare(b.label)); + const rankLabels=[...new Set(currentRanks.map(rank=>rank.label))]; let publicProfile={};try{const profile=await publicProfileFor(db,user.id);publicProfile={bio:profile.bio,socials:profile.socials,git:profile.git};}catch{} let linked=false;try{linked=!!await db.prepare('SELECT 1 AS linked FROM site_game_links WHERE user_id=?').bind(user.id).first();}catch{} const portrait={url:'https://cp.dunerealms.com/api/avatars/roster/'+encodeURIComponent(user.username),mode:linked?'skin':'image'}; @@ -39,7 +41,20 @@ export async function publicStaffRoster(db){ } return roster.sort((a,b)=>b.level-a.level||a.username.localeCompare(b.username)); } -const styles=`.roster-ticket-stats{margin-top:12px;padding:11px 13px;border:1px solid #7c814f;border-radius:6px;background:#112d22}.roster-ticket-stats>div{display:flex;align-items:center;gap:12px}.roster-ticket-stats small{text-transform:uppercase;letter-spacing:.1em;font-size:9px;color:#c5ba87}.roster-ticket-stats strong{font-size:21px;color:#edd496}.roster-ticket-stats p{font-size:10px!important;color:#b9cdb3!important;margin:7px 0 0!important}.roster-ticket-stats>span{font-size:11px;color:#b0c4ae} +export function staffHierarchy(roster){ + const bands=new Map(); + for(const person of [...roster].sort((a,b)=>b.level-a.level||a.username.localeCompare(b.username))){ + const key=person.level; + if(!bands.has(key))bands.set(key,{level:key,members:[]}); + bands.get(key).members.push(person); + } + return [...bands.values()]; +} +function hierarchyMarkup(roster){ + if(!roster.length)return ''; + return '

People of the realms

Staff hierarchy

Ordered by current rank. Departments below show each person’s areas of service; this overview does not imply individual reporting lines.

    '+staffHierarchy(roster).map(band=>'
  1. '+[...new Set(band.members.map(p=>p.rankLabels[0]||'Staff'))].map(esc).join(' · ')+'

      '+band.members.map(p=>'
    • '+esc(p.username)+''+esc(p.rankLabels[0]||'Staff')+'
    • ').join('')+'
  2. ').join('')+'
'; +} +const styles=`.roster-hierarchy{padding:24px;border:1px solid #a58d4f;border-radius:9px;background:linear-gradient(135deg,#203f32,#10291f);margin:24px 0}.roster-hierarchy h2{color:#f0d89e;margin:0;font-size:26px}.roster-hierarchy>p{max-width:760px;color:#c4d2bc}.roster-rank-tree{list-style:none;padding:0 0 0 22px;margin:24px 0;border-left:2px solid #b69a55}.roster-rank-tree>li{position:relative;padding:0 0 20px 14px}.roster-rank-tree>li:before{content:'';position:absolute;left:-29px;top:9px;width:10px;height:10px;background:#e6c775;transform:rotate(45deg);border:1px solid #162e23}.roster-rank-tree h3{font-size:16px;color:#e8d29d;margin:0 0 9px}.roster-rank-tree ul{list-style:none;display:flex;flex-wrap:wrap;gap:10px;padding:0}.roster-rank-tree ul li{border:1px solid #69774e;border-radius:6px;background:#102b21;padding:10px 15px;min-width:130px;max-width:100%;box-sizing:border-box;overflow-wrap:anywhere}.roster-rank-tree span,.roster-rank-tree small{display:block}.roster-rank-tree small{color:#b6c8af;font-size:11px}.roster-hierarchy nav{display:flex;flex-wrap:wrap;gap:8px}.roster-hierarchy nav a{border:1px solid #8a7b4a;border-radius:5px;padding:7px 11px;color:#ead3a0;text-decoration:none}.roster-hierarchy nav a:focus-visible{outline:2px solid #f2d991;outline-offset:3px}.roster-team{scroll-margin-top:20px}@media(max-width:540px){.roster-hierarchy{padding:17px}.roster-rank-tree{padding-left:15px}.roster-rank-tree>li:before{left:-22px}.roster-rank-tree ul li{min-width:0;width:100%}}.roster-ticket-stats{margin-top:12px;padding:11px 13px;border:1px solid #7c814f;border-radius:6px;background:#112d22}.roster-ticket-stats>div{display:flex;align-items:center;gap:12px}.roster-ticket-stats small{text-transform:uppercase;letter-spacing:.1em;font-size:9px;color:#c5ba87}.roster-ticket-stats strong{font-size:21px;color:#edd496}.roster-ticket-stats p{font-size:10px!important;color:#b9cdb3!important;margin:7px 0 0!important}.roster-ticket-stats>span{font-size:11px;color:#b0c4ae} body{margin:0;background:#0c211a;color:#eee4cc;font:15px/1.65 system-ui,sans-serif}.roster-main{max-width:1120px;margin:0 auto;padding:32px 24px 48px}.roster-intro{padding:26px;border:1px solid #8a7b4a;border-radius:9px;background:linear-gradient(110deg,#203f32eb,#142e25eb),url('/assets/sietch.webp') center/cover;margin-bottom:26px}.roster-kicker{text-transform:uppercase;letter-spacing:.18em;color:#d8b86e;font-size:11px}.roster-intro h1{font-size:32px;line-height:1.2;margin:10px 0 12px;color:#f2e3b7}.roster-intro p{max-width:690px}.roster-grid{display:grid;grid-template-columns:repeat(auto-fit,minmax(240px,1fr));gap:16px}.roster-card{border:1px solid #5b704d;background:linear-gradient(145deg,#1f3e30,#112b21);border-radius:8px;padding:22px;display:flex;gap:16px;align-items:center;box-shadow:0 4px 12px #0002}.roster-card img{width:88px;height:88px;object-fit:contain;flex-shrink:0}.roster-card h2{font-size:19px;line-height:1.25;margin:0 0 7px;color:#f0d89e;overflow-wrap:anywhere}.roster-card p{font-size:12px;color:#c4d2bc;margin:5px 0}.roster-handle{color:#aebeab!important}.roster-teams{margin-top:32px;display:grid;grid-template-columns:repeat(auto-fit,minmax(290px,1fr));gap:16px}.roster-team{border:1px solid #526849;background:#142f24;border-radius:8px;padding:20px}.roster-team h2{font-size:18px;margin:0 0 14px;color:#e4ca8b;display:flex;align-items:center;gap:10px}.roster-team h2 img{width:44px;height:44px;object-fit:contain}.roster-team ul{list-style:none;display:flex;flex-wrap:wrap;gap:8px;margin:0;padding:0}.roster-team li{border:1px solid #4d6748;border-radius:5px;background:#203e2e;padding:5px 10px;color:#e5dec6;font-size:13px}.roster-help{margin-top:25px;padding:18px 22px;border-left:3px solid #b59b55;background:#183429}.roster-help a{color:#e4c478}.roster-footer{padding:22px 24px;text-align:center;border-top:1px solid #5a6949;background:#10271e;color:#c4c9ad;font-size:12px}.roster-footer a{color:#dec17c}@media(max-width:540px){.roster-main{padding:20px 14px}.roster-intro{padding:20px}.roster-intro h1{font-size:26px}.roster-grid{grid-template-columns:1fr}.roster-card{padding:17px}.roster-card img{width:74px;height:74px}}.roster-directory{border:1px solid #5a704c;border-radius:8px;background:#142f24;padding:20px;margin-bottom:24px}.roster-directory h2{font-size:21px;margin:0 0 16px;color:#e8d39e}.roster-table-scroll{overflow:auto}.roster-directory table{width:100%;border-collapse:collapse;font-size:12px;text-align:left}.roster-directory th,.roster-directory td{padding:11px;border-bottom:1px solid #3f5d43;vertical-align:top}.roster-directory thead{background:#254734;color:#ecd49a}.roster-directory tbody th{color:#ead7ab;white-space:nowrap}.roster-teams{display:block;margin-top:24px}.roster-team{padding:18px;margin-bottom:22px}.roster-team h2{margin-bottom:8px}.roster-team h2 small{margin-left:auto;color:#b9c8ac;font-size:11px;font-weight:400}.roster-team-table{width:100%;table-layout:fixed;border-collapse:separate;border-spacing:10px}.roster-team-table>tbody>tr>td{width:50%;padding:0;vertical-align:top}.roster-member-card{padding:18px;align-items:flex-start;gap:15px;height:100%;box-sizing:border-box}.roster-portrait{position:relative;flex:0 0 72px}.roster-portrait>img{width:72px;height:72px;border:1px solid #9b8c4c;border-radius:7px;background:#10281d}.roster-portrait>.roster-role-crest{position:absolute;width:32px;height:32px;right:-7px;bottom:-7px;border:0;background:#142e23;border-radius:50%}.roster-member-info{min-width:0;flex:1}.roster-member-info h3{margin:0 0 6px;font-size:18px;line-height:1.3;color:#efd49a;overflow-wrap:anywhere}.roster-rank-label{color:#dfc58c!important;font-weight:600}.roster-member-info dl{font-size:11px;line-height:1.6;margin:11px 0 0}.roster-member-info dt{color:#a9c2aa;font-size:10px;text-transform:uppercase;letter-spacing:.1em}.roster-member-info dd{margin:3px 0 0;color:#d0d8bf}.roster-public-profile{margin-top:11px;border-top:1px solid #496447;padding-top:8px;font-size:12px}.roster-public-profile summary{cursor:pointer;color:#dfc58c}.roster-socials{display:flex;flex-wrap:wrap;gap:7px;margin-top:10px}.roster-socials a{font-size:10px;padding:3px 7px;border:1px solid #64774d;border-radius:4px;color:#ead3a1;text-decoration:none}.roster-socials a:hover{background:#34553a}@media(max-width:700px){.roster-team-table,.roster-team-table tbody,.roster-team-table tr,.roster-team-table>tbody>tr>td{display:block;width:100%;box-sizing:border-box}.roster-team-table{border-spacing:0}.roster-team-table>tbody>tr>td{margin:10px 0}.roster-empty-cell{display:none!important}.roster-team{padding:14px}.roster-member-card{padding:15px}.roster-portrait{flex-basis:62px}.roster-portrait>img{width:62px;height:62px}.roster-directory{padding:14px}} /* Every team owns one full-width register; keep cached earlier grid rules from squeezing tables. */ @@ -59,7 +74,7 @@ export function createStaffRoster(db){return async request=>{ const closureBlock=(p,team)=>{const stats=p.closedTickets;if(!stats)return '
Resolved ticketsStatistics unavailable
';const key=departmentForTeam[team],count=key?(stats.departments[key]||0):null;return '
Tickets closed'+stats.totalClosed+'
'+(key?'

'+esc(team)+': '+count+' · '+(count>=PERSONAL_DEPARTMENT_THRESHOLD?'Personal department seal earned':count+' / '+PERSONAL_DEPARTMENT_THRESHOLD+' for a personal department seal')+'

':'')+'
';}; const memberCard=(p,team)=>'
'+(p.portrait.mode==='skin'?'':'Steve avatar for '+esc(p.username)+'')+''+esc(p.rankLabels[0]||'Staff')+' seal

'+esc(p.username)+'

'+bioBox(p)+closureBlock(p,team)+(Object.keys(p.publicProfile.socials||{}).length?'
'+Object.entries(p.publicProfile.socials).map(([label,url])=>''+socialIcon(label)+''+esc(socialLabels[label]||label)+'').join('')+'
':'')+'
'; - const groups=teams.map(([name,,seal])=>{const members=roster.filter(p=>p.teams.includes(name));if(!members.length)return'';const rows=[];for(let i=0;i'+members.slice(i,i+2).map(p=>''+memberCard(p,name)+'').join('')+'');return '

'+esc(name)+''+members.length+' members

'+rows.join('')+'
';}).join(''); - const html='DuneRealms Staff Roster | Community Teams'+SHARED_HEAD+''+SHARED_HEADER+'

The Imperial Service Register

Meet the DuneRealms staff

Behind every safe caravan stands a watchful crew. Meet the people caring for our community, its worlds and the journey ahead.

Current roles and team access are drawn from the account rank system.

'+(!roster.length?'

No staff members are currently listed.

':'')+'
'+groups+'
'; + const groups=teams.map(([name,,seal])=>{const members=roster.filter(p=>p.teams.includes(name));if(!members.length)return'';const rows=[];for(let i=0;i'+members.slice(i,i+2).map(p=>''+memberCard(p,name)+'').join('')+'');return '

'+esc(name)+''+members.length+' members

'+rows.join('')+'
';}).join(''); + const html='DuneRealms Staff Roster | Community Teams'+SHARED_HEAD+''+SHARED_HEADER+'

The Imperial Service Register

Meet the DuneRealms staff

Behind every safe caravan stands a watchful crew. Meet the people caring for our community, its worlds and the journey ahead.

Current roles and team access are drawn from the account rank system.

'+(!roster.length?'

No staff members are currently listed.

':'')+hierarchyMarkup(roster)+'
'+groups+'
'; return new Response(request.method==='HEAD'?null:html,{headers:{'Content-Type':'text/html; charset=utf-8','Cache-Control':'public, max-age=30'}}); };} diff --git a/website/tests/staff-roster.test.mjs b/website/tests/staff-roster.test.mjs index b9eae8a3..0e08826c 100644 --- a/website/tests/staff-roster.test.mjs +++ b/website/tests/staff-roster.test.mjs @@ -48,3 +48,18 @@ test('all staff portraits use username-resolved Minecraft or Steve images, never const html=await(await createStaffRoster(db)(new Request('https://www.dunerealms.com/staff.html'))).text();assert(html.includes('roster-skin-face'));assert(html.includes('roster-skin-hat'));assert(html.includes('class="roster-steve-avatar"'));assert(!html.includes('49d2fe76-7977-4d49-bd39-e48fc8c648b8'));assert(html.includes('Introduction coming soon.'));assert(!html.includes('class="roster-rank-label"')); }finally{db.close();} }); + +test('hierarchy groups effective levels, sorts ties and keeps each person once',async()=>{ + const {staffHierarchy}=await import('../node/staff-roster.mjs'); + const people=[{username:'beta',level:55,rankLabels:['Dev Team']},{username:'owner',level:100,rankLabels:['Owner']},{username:'alpha',level:55,rankLabels:['Legal Team']}]; + const bands=staffHierarchy(people);assert.deepEqual(bands.map(b=>b.level),[100,55]);assert.deepEqual(bands[1].members.map(p=>p.username),['alpha','beta']);assert.equal(people[0].username,'beta'); +}); +test('hierarchy deduplicates equivalent web/game labels and reflects revocation',async()=>{ + const db=setup();try{ + await db.prepare("INSERT INTO site_accounts(id,username,role) VALUES('a','helper','web_support')").run(); + await db.prepare("INSERT INTO cp_account_ranks(user_id,rank_key) VALUES('a','game_support')").run(); + let roster=await publicStaffRoster(db);assert.deepEqual(roster[0].rankLabels,['Support Team']); + let html=await(await createStaffRoster(db)(new Request('https://www.dunerealms.com/staff.html'))).text();assert(html.includes('Staff hierarchy'));assert(html.includes('href="#staff-team-3"'));assert(html.includes('id="staff-team-3"'));assert(!html.includes('reporting to')); + await db.prepare("DELETE FROM cp_account_ranks WHERE user_id='a'").run();await db.prepare("UPDATE site_accounts SET role='user' WHERE id='a'").run();html=await(await createStaffRoster(db)(new Request('https://www.dunerealms.com/staff.html'))).text();assert(!html.includes('class="roster-hierarchy"')); + }finally{db.close();} +});