web/website/node/organisation-default-policies.mjs

40 lines
3.7 KiB
JavaScript

import {NODES} from './permissions.mjs';
import {ORGANISATION} from './organisation-model.mjs';
import {validatePolicyNodes} from './organisation-management.mjs';
const staff=['web.menu.staffmanual','web.mail.internal.view'];
const branchNodes={
customer_support:['web.tickets.support','web.tickets.staff','web.menu.tickets','web.accounts.view','dune.tickets.staff','dune.staff.open','dune.staff.history'],
sales_accounts:['web.tickets.sales','web.tickets.staff','web.menu.tickets','web.shop.support','web.accounts.view','web.bank.staff.view','web.bank.staff.clients'],
content_creative:['web.menu.items','web.items.manage','web.menu.inventory','web.quests.view','web.quests.manage','dune.items.give','dune.quests.view','dune.quests.admin','dune.atelier.view','dune.atelier.redeem'],
news_media:['web.menu.posts','web.posts.view','web.posts.edit'],
trust_safety:['web.menu.bans','web.bans.view','web.bans.manage','web.bans.evidence','web.bans.tickets','web.tickets.appeals','web.menu.forum','web.forum.moderate','web.menu.tickets','web.tickets.staff','dune.staff.open','dune.staff.history','dune.staff.kick','dune.staff.warn','dune.staff.mute','dune.staff.ban.local','dune.ban.local','dune.unban.local','dune.moderation.ban','dune.moderation.unban','duneprotect.inspect','duneprotect.lookup'],
it_operations:['web.tickets.network','web.tickets.staff','web.menu.tickets','web.menu.servers','web.servers.view','web.servers.logs','web.servers.power','web.servers.console','duneprotect.inspect','duneprotect.lookup','duneprotect.regions'],
engineering:['web.tickets.dev','web.tickets.staff','web.menu.tickets','web.menu.items','web.items.manage','web.menu.servers','web.servers.view','web.servers.logs','web.luckperms.view','web.quests.view'],
people_operations:['web.accounts.view','web.menu.staffmanual','web.menu.tickets','web.tickets.staff'],
legal_compliance:['web.tickets.legal','web.tickets.staff','web.menu.tickets','web.accounts.view','web.tickets.appeals','web.bans.view']
};
const leadNodes={
customer_support:['web.tickets.admin'],sales_accounts:['web.bank.projects.approve'],
content_creative:['duneprotect.worldedit','duneprotect.rollback','duneprotect.restore'],
news_media:['web.posts.publish'],trust_safety:['dune.staff.ban.network','dune.ban.global','dune.unban.global'],
it_operations:['web.git.admin'],engineering:['web.menu.permissions','web.ranks.manage','web.accounts.assign'],
people_operations:['web.accounts.assign','web.accounts.revoke'],legal_compliance:[]
};
const unique=nodes=>[...new Set(nodes)].sort();
export function defaultOrganisationPolicies(){
const result=[];
for(const department of ORGANISATION){
const departmentNodes=[...staff,'web.bank.staff.view','web.bank.staff.manage','web.bank.staff.deposit','web.bank.projects.approve'];
for(const branch of department.branches){
const officer=unique([...staff,...branchNodes[branch.key]]),lead=unique(leadNodes[branch.key]);
result.push({scopeType:'branch',scopeKey:branch.key,role:'officer',nodes:officer},{scopeType:'branch',scopeKey:branch.key,role:'branch_lead',nodes:lead});
departmentNodes.push(...officer,...lead);
}
result.push({scopeType:'department',scopeKey:department.key,role:'department_head',nodes:unique(departmentNodes)});
}
// Enumerated catalogue snapshot, never '*' or OP. Native privilege editors stay Dev-only.
const executives=Object.keys(NODES).filter(n=>!['web.forum.admin','web.luckperms.edit','cp.luckperms.edit','luckperms.editor','luckperms.applyedits','luckperms.trusteditor'].includes(n)&&!/(^|\.)op($|\.)/.test(n));
for(const role of ['owner_ceo','executive'])result.push({scopeType:'organisation',scopeKey:'dunerealms',role,nodes:unique(executives)});
for(const policy of result)validatePolicyNodes(policy.nodes,policy.scopeType,policy.role);
return result;
}