From e33f713b4c315949e3aecb7c8d5fdcf0f78a83d5 Mon Sep 17 00:00:00 2001 From: Nathan Broadbent Date: Fri, 4 Dec 2026 07:09:02 +1300 Subject: [PATCH 1/2] app/: the staff commands ported from the Loco server's tasks: user:set-staff, org:add-member, org:set-plan, org:delete, stripe:setup (sc-8900) Co-authored-by: Claude --- app/src/console/mod.rs | 1 + app/src/console/staff.rs | 219 ++++++++++++++++++++++++++++++++++++ app/src/lib.rs | 5 + app/tests/staff_commands.rs | 164 +++++++++++++++++++++++++++ docs/deploy.md | 14 ++- 5 files changed, 401 insertions(+), 2 deletions(-) create mode 100644 app/src/console/staff.rs create mode 100644 app/tests/staff_commands.rs diff --git a/app/src/console/mod.rs b/app/src/console/mod.rs index 64cb643c..e3b6b1c5 100644 --- a/app/src/console/mod.rs +++ b/app/src/console/mod.rs @@ -8,6 +8,7 @@ use laravel::schedule::{self, Schedule}; pub use crate::heartbeat; pub mod demo; pub mod retention; +pub mod staff; #[schedule::tasks] fn schedule(schedule: &mut Schedule) { diff --git a/app/src/console/staff.rs b/app/src/console/staff.rs new file mode 100644 index 00000000..ab3db1a9 --- /dev/null +++ b/app/src/console/staff.rs @@ -0,0 +1,219 @@ +//! Staff commands, run in a web pod (`visualci-app `), ported from the Loco server's tasks with the same +//! arguments and behaviour: make someone staff, add someone to an organization, put an organization on a plan, delete +//! an empty organization, and set up the Stripe catalog. Each refuses clearly (an error naming what's wrong) where the +//! old task did, and running one again with the same arguments changes nothing more. + +use laravel::console::{Console, clap, command}; +use laravel::db; + +use crate::auth::Role; +use crate::auth::memberships::MembershipChanged; +use crate::billing::stripe::{self, Method}; +use crate::models::{Organization, User}; + +fn refuse(message: impl Into) -> laravel::Error { + laravel::Error::msg(message.into()) +} + +async fn organization(slug: &str) -> laravel::Result { + Organization::query() + .filter(Organization::slug.eq(slug)) + .first() + .await? + .ok_or_else(|| refuse(format!("no organization {slug}"))) +} + +/// The configured Stripe key, or why there's none. +fn stripe_key(why: &str) -> laravel::Result { + laravel::config() + .section::() + .secret_key + .clone() + .filter(|k| !k.is_empty()) + .ok_or_else(|| refuse(why)) +} + +/// `user:set-staff --email
--staff `: make a user staff, or not. Staff read every +/// organization's data through the admin MCP server (`/mcp/admin`) and the staff pages. Only Nathan and DocSpring's own +/// agents. +#[derive(clap::Parser)] +#[command(name = "user:set-staff")] +pub struct UserSetStaff { + /// The user's email address. + #[arg(long)] + email: String, + /// `true` or `false`. + #[arg(long, action = clap::ArgAction::Set)] + staff: bool, +} + +#[command] +impl UserSetStaff { + async fn handle(self, console: &mut Console) -> laravel::Result<()> { + let (email, staff) = (self.email.trim().to_lowercase(), self.staff); + let updated: Option = db::query!( + "UPDATE users SET staff = {staff}, updated_at = now() WHERE lower(email) = {email} RETURNING id" + ) + .scalar() + .await?; + if updated.is_none() { + return Err(refuse(format!("no user {}", self.email))); + } + console.line(format!("{}: staff {staff}", self.email)); + Ok(()) + } +} + +/// `org:add-member --org --user [--role admin|member|read]`: add an existing user to an +/// organization, or change their role there, as staff (`memberships.source = staff`, which the forge's sync never +/// changes). For support: someone whose forge permission doesn't cover them. The role defaults to `member`. Someone new +/// to the organization is told, as an invitation's joiner is. +#[derive(clap::Parser)] +#[command(name = "org:add-member")] +pub struct OrgAddMember { + /// The organization's slug. + #[arg(long)] + org: String, + /// The user's email address, or a forge login (`octocat` or `@octocat`). + #[arg(long)] + user: String, + /// `admin`, `member` or `read`. + #[arg(long, default_value = "member")] + role: String, +} + +#[command] +impl OrgAddMember { + async fn handle(self, console: &mut Console) -> laravel::Result<()> { + let role = Role::parse(&self.role).ok_or_else(|| refuse("role must be admin, member or read"))?; + let org = organization(&self.org).await?; + let login = self.user.trim_start_matches('@').to_lowercase(); + let email = self.user.to_lowercase(); + let user: Option> = db::query!( + "SELECT COALESCE((SELECT user_id FROM identities WHERE lower(login) = {login} ORDER BY id LIMIT 1), \ + (SELECT id FROM users WHERE lower(email) = {email} LIMIT 1))" + ) + .scalar() + .await?; + let user = match user.flatten() { + Some(id) => User::find_or_fail(id).await?, + None => return Err(refuse(format!("no user with the email or forge login {}", self.user))), + }; + let (org_id, user_id, role_name) = (org.id, user.id, role.as_str()); + let added: Option = db::query!( + "INSERT INTO memberships (organization_id, user_id, role, source, created_at, updated_at) \ + VALUES ({org_id}, {user_id}, {role_name}, 'staff', now(), now()) \ + ON CONFLICT (organization_id, user_id) DO NOTHING RETURNING id" + ) + .scalar() + .await?; + if added.is_some() { + MembershipChanged::now(org_id, user_id, Some(role)).dispatch().await?; + } else { + db::query!( + "UPDATE memberships SET role = {role_name}, source = 'staff', synced_at = NULL, updated_at = now() \ + WHERE organization_id = {org_id} AND user_id = {user_id}" + ) + .update() + .await?; + } + console.line(format!("{} is now {} of {} (staff)", user.email, role.as_str(), org.slug)); + Ok(()) + } +} + +/// `org:set-plan --org --plan `: put an organization on a plan by hand. For DocSpring's own +/// organizations (Staff: unlimited, never offered) and for support. Team normally comes from a Stripe subscription, so +/// setting it here doesn't bill anyone. +#[derive(clap::Parser)] +#[command(name = "org:set-plan")] +pub struct OrgSetPlan { + /// The organization's slug. + #[arg(long)] + org: String, + /// `free`, `team` or `staff`. + #[arg(long)] + plan: String, +} + +#[command] +impl OrgSetPlan { + async fn handle(self, console: &mut Console) -> laravel::Result<()> { + let plan = self.plan.clone(); + if ![crate::billing::FREE.id, crate::billing::TEAM.id, crate::billing::STAFF.id].contains(&plan.as_str()) { + return Err(refuse("plan must be free, team or staff")); + } + let id = organization(&self.org).await?.id; + db::query!("UPDATE organizations SET plan = {plan}, updated_at = now() WHERE id = {id}").update().await?; + console.line(format!("{} is on the {} plan", self.org, self.plan)); + Ok(()) + } +} + +/// `org:delete --org `: delete an empty organization (a test or a mistake) and its Stripe customer. It refuses +/// an organization with projects, a subscription or any Stripe invoice: those have data or money attached and need a +/// person's decision, not a command. +#[derive(clap::Parser)] +#[command(name = "org:delete")] +pub struct OrgDelete { + /// The organization's slug. + #[arg(long)] + org: String, +} + +#[command] +impl OrgDelete { + async fn handle(self, console: &mut Console) -> laravel::Result<()> { + let slug = &self.org; + let org = organization(slug).await?; + let id = org.id; + let projects: i64 = + db::query!("SELECT COUNT(*) FROM projects WHERE organization_id = {id}").scalar().await?.unwrap_or(0); + if projects > 0 { + return Err(refuse(format!("{slug} has {projects} projects; not deleting it"))); + } + if org.stripe_subscription_id.is_some() { + return Err(refuse(format!("{slug} has a Stripe subscription; not deleting it"))); + } + if let Some(customer) = &org.stripe_customer_id { + let key = stripe_key("the organization has a Stripe customer, but Stripe isn't configured")?; + let customer_query = ("customer", customer.clone()); + let subs = stripe::get( + &key, + "subscriptions", + &[customer_query.clone(), ("status", "all".into()), ("limit", "1".into())], + ) + .await?; + let invoices = stripe::get(&key, "invoices", &[customer_query, ("limit", "1".into())]).await?; + let has = |v: &serde_json::Value| v["data"].as_array().is_some_and(|d| !d.is_empty()); + if has(&subs) || has(&invoices) { + return Err(refuse(format!("{customer} has subscriptions or invoices; not deleting it"))); + } + stripe::request(&key, Method::Delete, &format!("customers/{customer}"), &[], None).await?; + console.line(format!("deleted Stripe customer {customer}")); + } + db::query!("DELETE FROM organizations WHERE id = {id}").delete().await?; + console.line(format!("deleted organization {slug}")); + Ok(()) + } +} + +/// `stripe:setup`: create or update VisualCI's Stripe products, prices (Team monthly, the credit pack) and customer +/// portal configuration. The app does the same the first time it needs them, so this is for checking a new Stripe +/// account, or applying a price change before anyone pays. +#[derive(clap::Parser)] +#[command(name = "stripe:setup")] +pub struct StripeSetup; + +#[command] +impl StripeSetup { + async fn handle(self, console: &mut Console) -> laravel::Result<()> { + let key = stripe_key("Stripe isn't configured (VISUALCI_STRIPE_SECRET_KEY)")?; + let catalog = stripe::ensure_catalog(&key).await?; + console.line(format!( + "Team price {}, credit pack price {}, portal configuration {}", + catalog.team_price, catalog.pack_price, catalog.portal_configuration + )); + Ok(()) + } +} diff --git a/app/src/lib.rs b/app/src/lib.rs index bbba2ba9..f214ea91 100644 --- a/app/src/lib.rs +++ b/app/src/lib.rs @@ -112,5 +112,10 @@ pub fn configure() -> ApplicationBuilder { commands.add::(); commands.add::(); commands.add::(); + commands.add::(); + commands.add::(); + commands.add::(); + commands.add::(); + commands.add::(); }) } diff --git a/app/tests/staff_commands.rs b/app/tests/staff_commands.rs new file mode 100644 index 00000000..97c8e185 --- /dev/null +++ b/app/tests/staff_commands.rs @@ -0,0 +1,164 @@ +//! The staff commands ported from the Loco server's tasks: the same arguments, the same changes, idempotent where those +//! were, and the same refusals. + +use app::models::{Membership, Organization, User}; +use laravel::db; +use laravel::model::create; +use laravel::testing::prelude::*; + +async fn person(name: &str, email: &str) -> laravel::Result { + create!(User { pid: laravel::str::uuid7(), name: name, email: email, staff: false }).await +} + +async fn org(slug: &str) -> laravel::Result { + create!(Organization { pid: laravel::str::uuid7(), slug: slug, name: "Acme" }).await +} + +#[laravel::test] +async fn user_set_staff_turns_staff_on_and_off(app: Application) -> laravel::Result<()> { + let ada = person("Ada", "ada@example.com").await?; + for _ in 0..2 { + app.command("user:set-staff --email Ada@Example.com --staff true") + .await + .assert_successful() + .assert_output_contains("staff true"); + assert!(User::find_or_fail(ada.id).await?.staff); + } + app.command("user:set-staff --email ada@example.com --staff false").await.assert_successful(); + assert!(!User::find_or_fail(ada.id).await?.staff); + app.command("user:set-staff --email nobody@example.com --staff true") + .await + .assert_failed() + .assert_error_output_contains("no user nobody@example.com"); + app.command("user:set-staff --email ada@example.com --staff maybe").await.assert_failed(); + Ok(()) +} + +#[laravel::test] +async fn org_add_member_adds_or_changes_a_role_as_staff(app: Application) -> laravel::Result<()> { + let ada = person("Ada", "ada@example.com").await?; + let bea = person("Bea", "bea@example.com").await?; + let bea_id = bea.id; + db::query!( + "INSERT INTO identities (user_id, forge, forge_user_id, login, created_at, updated_at) \ + VALUES ({bea_id}, 'github', '42', 'BeaCodes', now(), now())" + ) + .insert() + .await?; + let acme_id = org("acme").await?.id; + let membership = |user: i64| async move { + Membership::query() + .filter(Membership::organization_id.eq(acme_id)) + .filter(Membership::user_id.eq(user)) + .first() + .await + }; + + // By email, as a member by default; again changes nothing + for _ in 0..2 { + app.command("org:add-member --org acme --user ada@example.com") + .await + .assert_successful() + .assert_output_contains("ada@example.com is now member of acme (staff)"); + } + let m = membership(ada.id).await?.expect("a membership"); + assert_eq!((m.role.as_str(), m.source.as_str()), ("member", "staff")); + let ada_id = ada.id; + let joined: i64 = db::query!("SELECT count(*) FROM emails WHERE kind = 'added_to_org' AND user_id = {ada_id}") + .scalar() + .await? + .unwrap_or(0); + assert_eq!(joined, 1, "told once, when they joined"); + + // A forge membership is taken over: the role changes and the source becomes staff, so the sync leaves it alone + db::query!( + "INSERT INTO memberships (organization_id, user_id, role, source, synced_at, created_at, updated_at) \ + VALUES ({acme_id}, {bea_id}, 'read', 'github', now(), now(), now())" + ) + .insert() + .await?; + app.command("org:add-member --org acme --user @beacodes --role admin").await.assert_successful(); + let m = membership(bea.id).await?.expect("a membership"); + assert_eq!((m.role.as_str(), m.source.as_str(), m.synced_at.is_none()), ("admin", "staff", true)); + + app.command("org:add-member --org acme --user ada@example.com --role owner") + .await + .assert_failed() + .assert_error_output_contains("role must be admin, member or read"); + app.command("org:add-member --org nope --user ada@example.com") + .await + .assert_failed() + .assert_error_output_contains("no organization nope"); + app.command("org:add-member --org acme --user ghost") + .await + .assert_failed() + .assert_error_output_contains("no user with the email or forge login ghost"); + Ok(()) +} + +#[laravel::test] +async fn org_set_plan_puts_an_organization_on_a_plan(app: Application) -> laravel::Result<()> { + let acme = org("acme").await?; + for plan in ["staff", "team", "team", "free"] { + app.command(&format!("org:set-plan --org acme --plan {plan}")) + .await + .assert_successful() + .assert_output_contains(&format!("acme is on the {plan} plan")); + assert_eq!(Organization::find_or_fail(acme.id).await?.plan, plan); + } + app.command("org:set-plan --org acme --plan gold") + .await + .assert_failed() + .assert_error_output_contains("plan must be free, team or staff"); + app.command("org:set-plan --org nope --plan team") + .await + .assert_failed() + .assert_error_output_contains("no organization nope"); + Ok(()) +} + +#[laravel::test] +async fn org_delete_deletes_only_an_empty_organization(app: Application) -> laravel::Result<()> { + let ada = person("Ada", "ada@example.com").await?; + let busy = org("busy").await?; + create!(app::models::Project { pid: laravel::str::uuid7(), organization_id: busy.id, slug: "docs", name: "Docs" }) + .await?; + app.command("org:delete --org busy") + .await + .assert_failed() + .assert_error_output_contains("busy has 1 projects; not deleting it"); + + let paying = org("paying").await?; + let paying_id = paying.id; + db::query!("UPDATE organizations SET stripe_subscription_id = 'sub_1' WHERE id = {paying_id}").update().await?; + app.command("org:delete --org paying") + .await + .assert_failed() + .assert_error_output_contains("paying has a Stripe subscription; not deleting it"); + + // A Stripe customer is checked (and deleted) in Stripe: without Stripe configured, it's refused + let customer = org("customer").await?; + let customer_id = customer.id; + db::query!("UPDATE organizations SET stripe_customer_id = 'cus_1' WHERE id = {customer_id}").update().await?; + app.command("org:delete --org customer") + .await + .assert_failed() + .assert_error_output_contains("Stripe isn't configured"); + + let empty = org("empty").await?; + app::testing::fixtures::member(&empty, &ada, "admin").await?; + app.command("org:delete --org empty") + .await + .assert_successful() + .assert_output_contains("deleted organization empty"); + assert!(Organization::find(empty.id).await?.is_none()); + assert!(User::find(ada.id).await?.is_some(), "its members stay"); + app.command("org:delete --org empty").await.assert_failed().assert_error_output_contains("no organization empty"); + Ok(()) +} + +#[laravel::test] +async fn stripe_setup_needs_stripe(app: Application) -> laravel::Result<()> { + app.command("stripe:setup").await.assert_failed().assert_error_output_contains("Stripe isn't configured"); + Ok(()) +} diff --git a/docs/deploy.md b/docs/deploy.md index 6c01a8ad..5494c1bb 100644 --- a/docs/deploy.md +++ b/docs/deploy.md @@ -133,5 +133,15 @@ Run in a web pod (`visualci-app `): - `retention:prune`, `groups:check`, `demo:reset`: what the scheduler runs daily, now. - `screenshots:seed`: fills an empty database with the fixed dataset VisualCI's own screenshots are taken against (CI and development). -The Loco server's staff tasks (`user:set-staff`, `org:add-member`, `org:delete`, `org:set-plan`, `stripe:setup`) have -no app/ command: until they do, staff make those changes in the database by hand. +- Staff commands (`app/src/console/staff.rs`), each safe to run again with the same arguments: + - `user:set-staff --email
--staff `: make someone staff (the admin MCP endpoint and the staff + pages), or not. + - `org:add-member --org --user [--role admin|member|read]`: add an existing user to an + organization, or change their role there (`member` by default), as staff: `memberships.source = staff`, which a + forge's sync never changes. Someone new to the organization gets the joined email. + - `org:set-plan --org --plan `: put an organization on a plan by hand. Team set here is + comped (nobody is billed); Staff is unlimited and only for DocSpring's own organizations. + - `org:delete --org `: delete an empty organization (a test or a mistake) and its Stripe customer. It refuses + one with projects, a subscription, or any Stripe subscription or invoice. + - `stripe:setup`: create or update the Stripe products, prices and customer portal configuration (the app also does + this the first time it needs them): for checking a new Stripe account, or a price change before anyone pays. From 91bb33f62e0f369223aa537d302f2eed8eaa9be8 Mon Sep 17 00:00:00 2001 From: Nathan Broadbent Date: Fri, 4 Dec 2026 07:33:56 +1300 Subject: [PATCH 2/2] app/: user:set-staff --staff false revokes the user's admin OAuth connections (sc-8900) Co-authored-by: Claude --- app/src/console/staff.rs | 54 +++++++++++++++++++++++++++++++------ app/tests/staff_commands.rs | 53 ++++++++++++++++++++++++++++++++++++ docs/deploy.md | 2 +- 3 files changed, 100 insertions(+), 9 deletions(-) diff --git a/app/src/console/staff.rs b/app/src/console/staff.rs index ab3db1a9..cf069626 100644 --- a/app/src/console/staff.rs +++ b/app/src/console/staff.rs @@ -35,7 +35,7 @@ fn stripe_key(why: &str) -> laravel::Result { /// `user:set-staff --email
--staff `: make a user staff, or not. Staff read every /// organization's data through the admin MCP server (`/mcp/admin`) and the staff pages. Only Nathan and DocSpring's own -/// agents. +/// agents. Taking staff away also revokes their admin connections ([`revoke_admin_connections`]). #[derive(clap::Parser)] #[command(name = "user:set-staff")] pub struct UserSetStaff { @@ -51,19 +51,57 @@ pub struct UserSetStaff { impl UserSetStaff { async fn handle(self, console: &mut Console) -> laravel::Result<()> { let (email, staff) = (self.email.trim().to_lowercase(), self.staff); - let updated: Option = db::query!( - "UPDATE users SET staff = {staff}, updated_at = now() WHERE lower(email) = {email} RETURNING id" + let updated: Option<(i64, String)> = db::query!( + "UPDATE users SET staff = {staff}, updated_at = now() WHERE lower(email) = {email} RETURNING id, pid::text" ) - .scalar() - .await?; - if updated.is_none() { - return Err(refuse(format!("no user {}", self.email))); + .select() + .await? + .first() + .map(|r| Ok::<_, laravel::Error>((r.try_get("id")?, r.try_get("pid")?))) + .transpose()?; + let Some((_, pid)) = updated else { return Err(refuse(format!("no user {}", self.email))) }; + if staff { + console.line(format!("{}: staff true", self.email)); + } else { + let revoked = revoke_admin_connections(&pid).await?; + console.line(format!("{}: staff false; {revoked} admin connections revoked", self.email)); } - console.line(format!("{}: staff {staff}", self.email)); Ok(()) } } +/// Ends every OAuth connection of someone's that holds the `admin` scope (the admin MCP endpoint): its access and +/// refresh tokens stop working, and a code not yet exchanged can't be. The endpoint also checks `users.staff` on +/// every call; this makes the tokens themselves useless. Their other connections (`mcp`) are left alone. Returns +/// how many connections it ended. +/// +/// # Errors +/// On a database error. +pub async fn revoke_admin_connections(subject: &str) -> laravel::Result { + let now = laravel::now().timestamp().as_microsecond(); + let families: Vec = db::query!( + "SELECT family_id FROM oauth_tokens WHERE subject = {subject} AND ' ' || scope || ' ' LIKE '% admin %' \ + AND revoked_at IS NULL \ + UNION SELECT family_id FROM oauth_codes WHERE subject = {subject} AND ' ' || scope || ' ' LIKE '% admin %' \ + AND used_at IS NULL AND NOT EXISTS (SELECT 1 FROM oauth_families f \ + WHERE f.family_id = oauth_codes.family_id AND f.revoked_at IS NOT NULL)" + ) + .select_as::() + .await?; + for family in &families { + db::query!( + "INSERT INTO oauth_families (family_id, revoked_at) VALUES ({family}, {now}) \ + ON CONFLICT (family_id) DO UPDATE SET revoked_at = COALESCE(oauth_families.revoked_at, excluded.revoked_at)" + ) + .insert() + .await?; + db::query!("UPDATE oauth_tokens SET revoked_at = {now} WHERE family_id = {family} AND revoked_at IS NULL") + .update() + .await?; + } + Ok(families.len() as u64) +} + /// `org:add-member --org --user [--role admin|member|read]`: add an existing user to an /// organization, or change their role there, as staff (`memberships.source = staff`, which the forge's sync never /// changes). For support: someone whose forge permission doesn't cover them. The role defaults to `member`. Someone new diff --git a/app/tests/staff_commands.rs b/app/tests/staff_commands.rs index 97c8e185..54d53894 100644 --- a/app/tests/staff_commands.rs +++ b/app/tests/staff_commands.rs @@ -34,6 +34,59 @@ async fn user_set_staff_turns_staff_on_and_off(app: Application) -> laravel::Res Ok(()) } +/// Taking staff away revokes their admin connections (tokens and a code not yet exchanged), and only those. +#[laravel::test] +async fn user_set_staff_false_revokes_admin_connections(app: Application) -> laravel::Result<()> { + let ada = person("Ada", "ada@example.com").await?; + let subject = ada.pid.to_string(); + let row = |family: &str, n: &str, scope: &str| { + let (family, scope, access, refresh) = + (family.to_string(), scope.to_string(), format!("access-{n}"), format!("refresh-{n}")); + let subject = subject.clone(); + async move { + db::query!( + "INSERT INTO oauth_tokens (family_id, client_key, client_id, subject, access_hash, refresh_hash, \ + resource, scope, created_at, access_expires_at, refresh_expires_at) \ + VALUES ({family}, 'k', 'c', {subject}, {access}, {refresh}, 'https://mcp.test/mcp', {scope}, 1, \ + 9999999999999999, 9999999999999999)" + ) + .insert() + .await + } + }; + row("fam-admin", "1", "admin").await?; + row("fam-mcp", "2", "mcp").await?; + db::query!( + "INSERT INTO oauth_codes (code_hash, family_id, client_key, client_id, subject, redirect_uri, code_challenge, \ + resource, scope, created_at, expires_at) \ + VALUES ('code-1', 'fam-code', 'k', 'c', {subject}, 'http://127.0.0.1/cb', 'x', 'https://mcp.test/mcp/admin', \ + 'admin', 1, 9999999999999999)" + ) + .insert() + .await?; + app.command("user:set-staff --email ada@example.com --staff true").await.assert_successful(); + app.command("user:set-staff --email ada@example.com --staff false") + .await + .assert_successful() + .assert_output_contains("2 admin connections revoked"); + let revoked = |family: &'static str| async move { + let at: Option> = + db::query!("SELECT revoked_at FROM oauth_families WHERE family_id = {family}").scalar().await?; + Ok::(at.flatten().is_some()) + }; + assert!(revoked("fam-admin").await? && revoked("fam-code").await?, "the admin token and the pending code"); + assert!(!revoked("fam-mcp").await?, "their mcp connection stays"); + let token_revoked: Option> = + db::query!("SELECT revoked_at FROM oauth_tokens WHERE family_id = 'fam-admin'").scalar().await?; + assert!(token_revoked.flatten().is_some()); + // Again: nothing left to revoke + app.command("user:set-staff --email ada@example.com --staff false") + .await + .assert_successful() + .assert_output_contains("0 admin connections revoked"); + Ok(()) +} + #[laravel::test] async fn org_add_member_adds_or_changes_a_role_as_staff(app: Application) -> laravel::Result<()> { let ada = person("Ada", "ada@example.com").await?; diff --git a/docs/deploy.md b/docs/deploy.md index 5494c1bb..15465949 100644 --- a/docs/deploy.md +++ b/docs/deploy.md @@ -135,7 +135,7 @@ Run in a web pod (`visualci-app `): - Staff commands (`app/src/console/staff.rs`), each safe to run again with the same arguments: - `user:set-staff --email
--staff `: make someone staff (the admin MCP endpoint and the staff - pages), or not. + pages), or not. Taking it away also revokes their OAuth connections that hold the `admin` scope. - `org:add-member --org --user [--role admin|member|read]`: add an existing user to an organization, or change their role there (`member` by default), as staff: `memberships.source = staff`, which a forge's sync never changes. Someone new to the organization gets the joined email.