From fba37b7ad06ac4c9acebcf4972a1d57ae2d5bc1d Mon Sep 17 00:00:00 2001 From: Owen Date: Tue, 2 Jun 2026 15:31:21 -0700 Subject: [PATCH] Add command to make other user server admin --- cli/commands/setServerAdmin.ts | 51 ++++++++++++++++++++++++++++++++++ cli/index.ts | 2 ++ 2 files changed, 53 insertions(+) create mode 100644 cli/commands/setServerAdmin.ts diff --git a/cli/commands/setServerAdmin.ts b/cli/commands/setServerAdmin.ts new file mode 100644 index 000000000..341b70bc1 --- /dev/null +++ b/cli/commands/setServerAdmin.ts @@ -0,0 +1,51 @@ +import { CommandModule } from "yargs"; +import { db, users } from "@server/db"; +import { eq } from "drizzle-orm"; + +type SetServerAdminArgs = { + email: string; +}; + +export const setServerAdmin: CommandModule<{}, SetServerAdminArgs> = { + command: "set-server-admin", + describe: "Mark any user as a server admin by email address", + builder: (yargs) => { + return yargs.option("email", { + type: "string", + demandOption: true, + describe: "User email address" + }); + }, + handler: async (argv: { email: string }) => { + try { + const email = argv.email.trim().toLowerCase(); + + const [user] = await db + .select() + .from(users) + .where(eq(users.email, email)) + .limit(1); + + if (!user) { + console.error(`User with email '${email}' not found`); + process.exit(1); + } + + if (user.serverAdmin) { + console.log(`User '${email}' is already a server admin`); + process.exit(0); + } + + await db + .update(users) + .set({ serverAdmin: true }) + .where(eq(users.userId, user.userId)); + + console.log(`User '${email}' has been marked as a server admin`); + process.exit(0); + } catch (error) { + console.error("Error:", error); + process.exit(1); + } + } +}; diff --git a/cli/index.ts b/cli/index.ts index 19585bc6f..cfa65625c 100644 --- a/cli/index.ts +++ b/cli/index.ts @@ -11,6 +11,7 @@ import { deleteClient } from "./commands/deleteClient"; import { generateOrgCaKeys } from "./commands/generateOrgCaKeys"; import { clearCertificates } from "./commands/clearCertificates"; import { disableUser2fa } from "./commands/disableUser2fa"; +import { setServerAdmin } from "./commands/setServerAdmin"; yargs(hideBin(process.argv)) .scriptName("pangctl") @@ -23,5 +24,6 @@ yargs(hideBin(process.argv)) .command(generateOrgCaKeys) .command(clearCertificates) .command(disableUser2fa) + .command(setServerAdmin) .demandCommand() .help().argv;