Link the verified official owner alt and publish the official identity showcase

This commit is contained in:
unimatrixgit 2026-11-15 03:44:02 +01:00
commit a8956bc88e
2 changed files with 181 additions and 19 deletions

View file

@ -0,0 +1,14 @@
import {randomUUID} from 'node:crypto';import {fileURLToPath} from 'node:url';import {resolve} from 'node:path';
import {openDatabase} from '../node/mysql.mjs';import {OFFICIAL_ACCOUNT} from '../node/official-account.mjs';
export async function adoptAutomatedNewsAuthor(db,{actorId,apply=false}={}){
if(![OFFICIAL_ACCOUNT.ownerId,'f7b88778-f0bc-41cc-9227-d8ef2f52264d'].includes(actorId))throw Error('Pinned Owner or Dev actor required.');
return db.transaction(async tx=>{
const account=await tx.first("SELECT id FROM site_accounts WHERE id=? AND username=? AND role='official_account' AND password_hash NOT LIKE '!%' FOR SHARE",[OFFICIAL_ACCOUNT.id,OFFICIAL_ACCOUNT.username]);if(!account)throw Error('Official publishing identity unavailable.');
const actor=await tx.first("SELECT p.principal_kind FROM org_control_principals p JOIN site_accounts a ON a.id=p.user_id WHERE p.user_id=? AND a.password_hash NOT LIKE '!%' FOR SHARE",[actorId]);if(!['owner','service'].includes(actor?.principal_kind))throw Error('Current control actor required.');
const rows=await tx.query("SELECT id,source_key FROM website_posts WHERE author_id='release-register' AND LEFT(source_key,8)='release:' FOR UPDATE");
if(!apply)return {applied:false,automatedPosts:rows.length};
for(const p of rows){await tx.query("UPDATE website_posts SET author_id=?,version=version+1 WHERE id=? AND author_id='release-register'",[OFFICIAL_ACCOUNT.id,p.id]);await tx.query('INSERT INTO account_audit(id,actor_id,action,details,created_at) VALUES(?,?,?,?,?)',[randomUUID(),actorId,'automated-news-author',JSON.stringify({postId:p.id,source:p.source_key,previousAuthor:'release-register',authorId:OFFICIAL_ACCOUNT.id}),Date.now()]);}
return {applied:true,updated:rows.length,manualPostsChanged:false,newArticlesCreated:false};
});
}
if(process.argv[1]&&fileURLToPath(import.meta.url)===resolve(process.argv[1])){const db=await openDatabase(process.env);try{console.log(JSON.stringify(await adoptAutomatedNewsAuthor(db,{actorId:process.argv.find(a=>a.startsWith('--actor='))?.slice(8),apply:process.argv.includes('--apply')})));}finally{await db.close();}}

View file

@ -0,0 +1,23 @@
import {randomUUID} from 'node:crypto';import {fileURLToPath} from 'node:url';import {resolve} from 'node:path';
import {openDatabase} from '../node/mysql.mjs';import {initializeOrganisation} from '../node/organisation-model.mjs';import {OFFICIAL_ACCOUNT,organisationSubject} from '../node/official-account.mjs';
import {nativeSyncMutation} from '../node/native-sync-outbox.mjs';
const SERVICE_ID='f7b88778-f0bc-41cc-9227-d8ef2f52264d';
export async function bootstrapOfficialAlias(db,{actorId,apply=false}={}){
if(![OFFICIAL_ACCOUNT.ownerId,SERVICE_ID].includes(actorId))throw Error('Owner or pinned Dev actor required.');
return db.transaction(async tx=>{
const actor=await tx.first("SELECT p.principal_kind FROM org_control_principals p JOIN site_accounts a ON a.id=p.user_id WHERE p.user_id=? AND a.password_hash NOT LIKE '!%' FOR SHARE",[actorId]);
if(actor?.principal_kind!==(actorId===SERVICE_ID?'service':'owner'))throw Error('Current control actor required.');
const account=await tx.first("SELECT a.id FROM site_accounts a JOIN site_game_links l ON l.user_id=a.id WHERE a.id=? AND a.username=? AND a.role='official_account' AND a.password_hash NOT LIKE '!%' AND l.minecraft_uuid=? FOR SHARE",[OFFICIAL_ACCOUNT.id,OFFICIAL_ACCOUNT.username,OFFICIAL_ACCOUNT.minecraftUuid]);
const owner=await tx.first("SELECT p.user_id FROM org_control_principals p JOIN site_accounts a ON a.id=p.user_id WHERE p.user_id=? AND p.principal_kind='owner' AND a.username='unimatrix999' AND a.password_hash NOT LIKE '!%' FOR SHARE",[OFFICIAL_ACCOUNT.ownerId]);
if(!account||!owner)throw Error('Pinned official and owner identities must match.');
const existing=await tx.first('SELECT principal_kind,created_by FROM org_control_principals WHERE user_id=? FOR UPDATE',[OFFICIAL_ACCOUNT.id]);
if(existing&&(existing.principal_kind!=='owner_alias'||existing.created_by!==OFFICIAL_ACCOUNT.ownerId))throw Error('Existing control identity differs; refusing overwrite.');
if(!apply)return {applied:false,aliasUserId:OFFICIAL_ACCOUNT.id,permissionPrincipalId:OFFICIAL_ACCOUNT.ownerId,alreadyLinked:!!existing};
if(!existing){const now=Date.now();await tx.query('INSERT INTO org_control_principals(user_id,principal_kind,created_by,created_at) VALUES(?,?,?,?)',[OFFICIAL_ACCOUNT.id,'owner_alias',OFFICIAL_ACCOUNT.ownerId,now]);
await tx.query('INSERT INTO org_assignment_events(id,user_id,actor_id,action,scope_type,scope_key,reason,after_json,created_at) VALUES(?,?,?,?,?,?,?,?,?)',[randomUUID(),OFFICIAL_ACCOUNT.id,actorId,'owner-alias-baseline','organisation','dunerealms','Owner explicitly authorised dunerealms Bedrock alternate account to follow the same function rights',JSON.stringify({permissionPrincipalId:OFFICIAL_ACCOUNT.ownerId,extraStaffAppointment:false}),now]);
const sync=nativeSyncMutation(now);await tx.query(sync.sql,sync.values);}
const subject=await organisationSubject(tx,OFFICIAL_ACCOUNT.id,{lock:true});if(!subject.alias)throw Error('Official identity verification failed.');
return {applied:true,created:!existing,aliasUserId:OFFICIAL_ACCOUNT.id,permissionPrincipalId:subject.userId};
});
}
if(process.argv[1]&&fileURLToPath(import.meta.url)===resolve(process.argv[1])){const db=await openDatabase(process.env);try{await initializeOrganisation(db);console.log(JSON.stringify(await bootstrapOfficialAlias(db,{actorId:process.argv.find(a=>a.startsWith('--actor='))?.slice(8),apply:process.argv.includes('--apply')})));}finally{await db.close();}}