// Central assignment vocabulary. This catalogue never grants permissions by itself. export const ORGANISATION = [ {key:'community_operations',label:'Community Operations',branches:[ {key:'customer_support',label:'Customer Support'}, {key:'sales_accounts',label:'Sales & Account Services'}, {key:'content_creative',label:'Content & Creative'}, {key:'news_media',label:'News & Media'}]}, {key:'dunerealms_operations',label:'DuneRealms Operations',branches:[ {key:'trust_safety',label:'Trust & Safety'}, {key:'it_operations',label:'IT Operations'}, {key:'engineering',label:'Engineering'}, {key:'people_operations',label:'People Operations'}, {key:'legal_compliance',label:'Legal & Compliance'}]} ]; export const STAFF_SCOPE_TYPES = ['organisation','department','branch']; export const ASSIGNMENT_ROLES = { organisation:[{key:'owner_ceo',label:'Owner & CEO'},{key:'executive',label:'Executive'}], department:[{key:'department_head',label:'Department Head'}], branch:[{key:'branch_lead',label:'Branch Lead'},{key:'officer',label:'Officer'}], clan:[{key:'leader',label:'Clan Leader'},{key:'officer',label:'Clan Officer'},{key:'member',label:'Clan Member'}], house:[{key:'member',label:'House Member'},{key:'leader',label:'House Leader'},{key:'mentat',label:'Mentat'}], office:[{key:'emperor',label:'Emperor'},{key:'water_rights',label:'Water Rights'},{key:'spice_rights',label:'Spice Rights'}], company:[{key:'owner',label:'Company Owner'},{key:'director',label:'Company Director'},{key:'delegate',label:'Company Delegate'}], order:[{key:'member',label:'Order Member'}], service:[{key:'officeholder',label:'Service Officeholder'}] }; export function assignmentLabel(row){ const scopeType=row.scope_type??row.scopeType,scopeKey=row.scope_key??row.scopeKey,roleKey=row.role_key??row.roleKey; const scopes=ORGANISATION.flatMap(d=>[d,...d.branches]); return {scopeType,scopeKey,scopeLabel:scopeType==='organisation'?'DuneRealms':scopes.find(s=>s.key===scopeKey)?.label||scopeKey, role:roleKey,roleLabel:ASSIGNMENT_ROLES[scopeType]?.find(r=>r.key===roleKey)?.label||roleKey, source:row.source_kind??row.source,startsAt:row.starts_at??row.startsAt,endsAt:row.ends_at??row.endsAt, id:row.id,version:Number(row.version||1)}; } export const organisationSchema = [ `CREATE TABLE IF NOT EXISTS org_assignments ( id CHAR(36) PRIMARY KEY, user_id CHAR(36) NOT NULL, scope_type VARCHAR(24) NOT NULL, scope_key VARCHAR(80) NOT NULL, role_key VARCHAR(40) NOT NULL, source_kind VARCHAR(24) NOT NULL, source_ref VARCHAR(160) NULL, status VARCHAR(16) NOT NULL DEFAULT 'active', starts_at BIGINT NOT NULL, ends_at BIGINT NULL, created_by CHAR(36) NOT NULL, created_at BIGINT NOT NULL, version INT NOT NULL DEFAULT 1, INDEX org_user_status(user_id,status), INDEX org_scope_role(scope_type,scope_key,role_key,status), FOREIGN KEY(user_id) REFERENCES site_accounts(id) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4`, `CREATE TABLE IF NOT EXISTS staff_source_members ( user_id CHAR(36) NOT NULL, source_key VARCHAR(40) NOT NULL, source_name VARCHAR(80) NOT NULL, source_uuid CHAR(36) NOT NULL, source_ranks_json TEXT NOT NULL, source_ref VARCHAR(255) NOT NULL, imported_at BIGINT NOT NULL, imported_by CHAR(36) NOT NULL, PRIMARY KEY(user_id,source_key), UNIQUE KEY staff_source_uuid(source_key,source_uuid), FOREIGN KEY(user_id) REFERENCES site_accounts(id) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4` ]; export async function initializeOrganisation(db){ for(const sql of organisationSchema)await db.prepare(sql).run(); // No automatic appointments, account rewrites, rank resets or game grants. }