forked from unimatrix/web
Separate personal bank eligibility from administrator inspection
This commit is contained in:
parent
716e14414b
commit
c58f3f2ffe
1 changed files with 18 additions and 4 deletions
|
|
@ -6,12 +6,13 @@ export function entityId(kind,key){const h=createHash('sha256').update('postbank
|
|||
const can= (rights,key)=>rights.nodes.includes(key);
|
||||
// Central identity/organisation records are read-only sources. No gameplay bank,
|
||||
// bearer gateway, old balance or historical bank transaction is read here.
|
||||
export function createPostbankAuthority(central,{clock=Date.now}={}){
|
||||
export function createPostbankAuthority(central,{clock=Date.now,rightsFor=accessFor}={}){
|
||||
const rows=async(sql,args=[])=>(await central.prepare(sql).bind(...args).all()).results||[];
|
||||
return async user=>{
|
||||
const rights=await accessFor(central,user),readAdmin=can(rights,'web.bank.staff.view'),manageAdmin=can(rights,'web.bank.staff.manage'),now=clock();
|
||||
const rights=await rightsFor(central,user),readAdmin=can(rights,'web.bank.staff.view'),manageAdmin=can(rights,'web.bank.staff.manage'),now=clock();
|
||||
const sources=[],operatorRoles=new Set(['owner','officer','admin','leader']);
|
||||
const add=(kind,key,name,operators=[],viewers=[],expiresAt=null)=>sources.push({id:entityId(kind,key),kind,key,name,canView:readAdmin||operators.includes(user.id)||viewers.includes(user.id),canActivate:manageAdmin||operators.includes(user.id),canPay:operators.includes(user.id),expiresAt});
|
||||
// Administrative inspection belongs to separate admin routes, never personal activation cards.
|
||||
const add=(kind,key,name,operators=[],viewers=[],expiresAt=null)=>sources.push({id:entityId(kind,key),kind,key,name,canView:operators.includes(user.id)||viewers.includes(user.id),canActivate:operators.includes(user.id),canPay:operators.includes(user.id),expiresAt});
|
||||
const policy=await central.prepare('SELECT game_link_exempt FROM site_account_policies WHERE user_id=?').bind(user.id).first();
|
||||
if(!policy?.game_link_exempt&&!['memorial','official_account'].includes(user.role))add('person',user.id,user.username,[user.id]);
|
||||
const clans=await rows('SELECT id,name,owner_id FROM site_clans WHERE active=1');
|
||||
|
|
@ -38,7 +39,7 @@ export function createPostbankAuthority(central,{clock=Date.now}={}){
|
|||
// Staff eligibility follows current central access roles, not cosmetic honours.
|
||||
const staff=await rows("SELECT a.id,a.username,a.role FROM site_accounts a LEFT JOIN site_account_policies p ON p.user_id=a.id WHERE a.password_hash NOT LIKE '!%' AND COALESCE(p.game_link_exempt,0)=0");
|
||||
const eligibleStaff=staff.filter(a=>STAFF_ROLES.has(a.role));
|
||||
for(const actor of eligibleStaff)add('staff',actor.id,actor.username+' · Staff',[actor.id]);
|
||||
for(const actor of eligibleStaff)add('staff',actor.id,actor.username+' · Staff',[actor.id]);
|
||||
return {entities:sources,readAdmin,manageAdmin,eligibleStaff:eligibleStaff.map(a=>({id:a.id,username:a.username})),server:{state:'not_linked',name:'Game server account'}};
|
||||
};
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue

Staff