~ knotless Search/
↑↓ move↵ open⇧↵ all results
0
0

A group is switched off, back on, and deleted from the console and the command

Merged chadtmiller.com asked to merge into main from chadtmiller.com/group-host:host/group-lifecycle-everywhere
crates/group-host/src/group_api.rs+6−2
@@ -209,10 +209,14 @@ pub async fn get_group(
return Ok(Json(json!({ "group": signed_out(group, handle) })));
};
// Switched off: nothing in it is read, by members either. Still
// answered, so a steward can find the switch.
if host.deactivation(group)?.is_some() {
// answered, telling a steward of when it went off so, to find the
// switch.
if let Some(off) = host.deactivation(group)? {
let mut view = base(&host, group, &handle)?;
view["deactivated"] = json!(true);
let steward = off.stewards.contains(&me);
let viewer = json!({"member": false, "roles": [], "actions": [], "steward": steward});
view["viewer"] = viewer;
return Ok(Json(json!({ "group": view })));
}
let record = |space: &str, collection: &str, rkey: &str| {
crates/group-host/tests/lifecycle.rs+7−0
@@ -153,6 +153,13 @@ async fn a_group_switched_off_is_read_by_nobody() {
let (_, shown) = get(&h, &lxm, &format!("group={did}"), &[auth(&h, &alice, &lxm)]).await;
assert_eq!(shown["group"]["deactivated"], true);
assert_eq!(shown["group"].get("displayName"), None);
// Its stewards of then are told they are, to find the switch; a plain
// member of then is not, nor is anything of their standing read.
let viewer = json!({"member": false, "roles": [], "actions": [], "steward": true});
assert_eq!(shown["group"]["viewer"], viewer);
let (_, shown) = get(&h, &lxm, &format!("group={did}"), &[auth(&h, &carol, &lxm)]).await;
let viewer = json!({"member": false, "roles": [], "actions": [], "steward": false});
assert_eq!(shown["group"]["viewer"], viewer);
// To no one signed in, as any other: its DID and handle.
let (_, shown) = get(&h, &format!("{NS}.getGroup"), &format!("group={did}"), &[]).await;
assert_eq!(shown["group"].get("deactivated"), None);
crates/group-host/tests/mcp.rs+24−0
@@ -508,6 +508,30 @@ async fn writes_the_groups_profile_and_rules_as_the_group() {
assert_eq!(by["member"], alice.did.as_str());
}
#[tokio::test]
async fn switches_the_group_off_and_back_on() {
let h = start(&[], false).await;
let [alice, bob, _] = people(&h).await;
let body = json!({"handle": RIDERS, "displayName": "Riders"});
let group = start_group(&h, &alice, body).await;
make_member(&h, &group, &bob.did).await;
// A plain member may not.
let (_, tokens) = connect(&h, &bob, &group).await;
let access = tokens["access_token"].as_str().unwrap();
let got = tool(&h, access, "group_deactivate", json!({})).await;
assert_eq!(got["isError"], true, "{got}");
assert!(h.host.deactivation(&group).unwrap().is_none());
// One who runs it may, and with undo, switch it back on.
let (_, tokens) = connect(&h, &alice, &group).await;
let access = tokens["access_token"].as_str().unwrap();
let got = tool(&h, access, "group_deactivate", json!({})).await;
assert!(got.get("isError").is_none(), "{got}");
assert!(h.host.deactivation(&group).unwrap().is_some());
let got = tool(&h, access, "group_deactivate", json!({"undo": true})).await;
assert!(got.get("isError").is_none(), "{got}");
assert!(h.host.deactivation(&group).unwrap().is_none());
}
#[tokio::test]
async fn does_only_what_the_members_roles_allow() {
let h = start(&[], false).await;
crates/group-host-mcp/src/lib.rs+9−0
@@ -39,6 +39,8 @@ macro_rules! lexicon {
/// and atproto's.
const LEXICONS: &[(&str, &str)] = &[
lexicon!("getGroup"),
lexicon!("deactivateGroup"),
lexicon!("activateGroup"),
lexicon!("listMembers"),
lexicon!("listJoinRequests"),
lexicon!("denyJoinRequest"),
@@ -310,6 +312,13 @@ const TOOLS: &[(&str, &[&str], &str, Made)] = &[
"The group as the member may see it.",
Made::Method("getGroup", None),
),
(
"group_deactivate",
&[],
"Switches the group off: nobody can read its spaces or write as it until one who \
could switch it off switches it back on. With undo, switches it back on.",
Made::Method("deactivateGroup", Some("activateGroup")),
),
(
"profile_set",
&[],
crates/group-host-mcp/tests/protocol.rs+10−0
@@ -30,6 +30,7 @@ fn names_each_tool_for_its_command() {
names,
[
"group_show",
"group_deactivate",
"profile_set",
"rule_set",
"rule_delete",
@@ -189,6 +190,15 @@ fn plans_a_method_asked_with_its_arguments() {
input: json!({}),
})
);
// Its opposite, with undo, which takes nothing but the group.
let off = |undo: bool| planned("group_deactivate", json!({"undo": undo}));
let call = |nsid: &str| Plan::Call {
nsid: format!("fyi.opensocial.{nsid}"),
procedure: true,
input: json!({}),
};
assert_eq!(off(false), Ok(call("deactivateGroup")));
assert_eq!(off(true), Ok(call("activateGroup")));
let Ok(Plan::Call { input, .. }) = planned("join_list", json!({"limit": 5})) else {
panic!()
};
crates/opensocial/src/lib.rs+23−3
@@ -1,6 +1,6 @@
//! A client for opensocial group hosts, and what the `opensocial` command
//! does with it. Each command is `opensocial <group> <action>`; all but
//! those that make or move a group or an account are the twins of the
//! those that make, move or delete a group or an account are the twins of the
//! host's MCP tools, made from the same `group_host_mcp::Tool`s and
//! carried out from the same `Plan`s.
//!
@@ -30,6 +30,10 @@ group
invite for each handle in OPENSOCIAL_SEED_INVITE
group move <group> --to <address> [--to-did <did>]
move a group, whole, from this host to the one at <address>
group deactivate <group> [--undo]
switch a group off, so nothing reads or writes it, or with
--undo switch it back on
group delete <group> delete a group, its spaces and its identity, for good
profile
profile set <group> [--display-name <name>] [--join-policy <policy>] [--description <words>] …
change the group's profile in what is given; \"\" takes a field away
@@ -86,8 +90,8 @@ account
A group or person is a handle or a DID; a subject an account's DID or a
record's at:// URI. A flag is a field of what the command writes or asks,
in kebab case; a list is comma-separated, and anything more than text or
a number is JSON. Every command but group create, seed and move and
account import is also the MCP tool <group>_<action> (member_assign),
a number is JSON. Every command but group create, seed, move and
delete and account import is also the MCP tool <group>_<action> (member_assign),
which an MCP client connected to a group calls there.
You sign in as OPENSOCIAL_AS (a handle) with OPENSOCIAL_PASSWORD, at
@@ -573,6 +577,10 @@ pub async fn run(args: &[String], env: &Env) -> Result<String> {
};
migrate(&signed_in(env).await?, &host, &dest, group).await
}
["group", "delete", rest @ ..] => {
let [group] = parse(rest, &[])?.take()?;
delete(&signed_in(env).await?, &host, group).await
}
["account", "import", rest @ ..] => {
let a = parse(rest, &["address", "code"])?;
let [account] = a.take()?;
@@ -834,6 +842,18 @@ fn members_of(group: &str) -> String {
format!("at://{group}/space/{NS}.members/self")
}
/// Deletes `group`, for good: what went.
async fn delete(me: &Client, host: &Host, group: &str) -> Result<String> {
let group = me.resolve(host, group).await?;
let body = json!({"group": group});
let done = me.call(host, &m("deleteGroup"), &body).await?;
let identity = match done["tombstoned"].as_bool() {
Some(true) => "its DID is ended",
_ => "its DID is left to the holders of its recovery keys",
};
Ok(format!("deleted {group}\n{identity}\n"))
}
async fn migrate(me: &Client, from: &Host, to: &Host, group: &str) -> Result<String> {
let group = me.resolve(from, group).await?;
let mut out = format!("moving {group}\n from {}\n to {}\n", from.url, to.url);
crates/opensocial/tests/commands.rs+45−1
@@ -5,10 +5,11 @@
#[allow(dead_code)]
mod net;
use atproto::keys::{Curve, Keypair};
use group_host::Host;
use group_host::config::Config;
use net::net;
use opensocial::{Env, did_web, run};
use opensocial::{Client, Env, Host as HostAt, did_web, run};
use serde_json::{Value, json};
use std::collections::HashMap;
use std::sync::Arc;
@@ -372,6 +373,48 @@ async fn writes_the_groups_rules_roles_and_profile() {
assert_eq!(resolved["subject"]["did"], bob.as_str(), "{resolved}");
}
#[tokio::test]
async fn switches_a_group_off_and_on_and_deletes_it() {
let h = host().await;
let (alice, bob) = (env(&h, 0), env(&h, 1));
let made = ok(&alice, &["group", "create", "riders.groups.test"]).await;
let did = made.split_whitespace().nth(2).unwrap().to_string();
// Only one who runs it, switching it off once.
let said_so = fails(&bob, &["group", "deactivate", &did]).await;
assert!(said_so.contains("403"), "{said_so}");
assert_eq!(ok(&alice, &["group", "deactivate", &did]).await, "{}\n");
let said_so = fails(&alice, &["group", "deactivate", &did]).await;
assert!(said_so.contains("AlreadyDeactivated"), "{said_so}");
assert!(h.host.deactivation(&did).unwrap().is_some());
ok(&alice, &["group", "deactivate", &did, "--undo"]).await;
assert!(h.host.deactivation(&did).unwrap().is_none());
let said_so = fails(&bob, &["group", "delete", &did]).await;
assert!(said_so.contains("403"), "{said_so}");
let gone = ok(&alice, &["group", "delete", "riders.groups.test"]).await;
assert_eq!(gone, format!("deleted {did}\nits DID is ended\n"));
let said_so = fails(&alice, &["group", "show", &did]).await;
assert!(said_so.contains("GroupNotFound"), "{said_so}");
// One whose steward holds a recovery key keeps its DID, for them.
let made = ok(&alice, &["group", "create", "tandem.groups.test"]).await;
let did = made.split_whitespace().nth(2).unwrap().to_string();
let person = &net().accounts[0];
let me = Client::sign_in(&net().pds, &person.handle, &person.password);
let me = me.await.unwrap();
let at = HostAt {
url: h.url.clone(),
did: did_web(&h.url),
};
let key = Keypair::generate(Curve::K256).public().did_key();
let body = json!({"group": did, "key": key});
let added = me.call(&at, "fyi.opensocial.addRecoveryKey", &body).await;
added.unwrap();
let gone = ok(&alice, &["group", "delete", &did]).await;
let left = "its DID is left to the holders of its recovery keys";
assert_eq!(gone, format!("deleted {did}\n{left}\n"));
}
#[tokio::test]
async fn seeds_a_group_to_try_things_on() {
let h = host().await;
@@ -637,6 +680,7 @@ async fn says_what_is_wrong_with_what_it_is_asked() {
&["group", "create"][..],
&["group", "show", "a", "b"],
&["group", "move", "riders.groups.test"],
&["group", "delete"],
&["member", "assign", "g"],
&["member", "eject", "g", "m", "extra"],
&["member"],
docs/design/groups.md+9−1
@@ -130,7 +130,9 @@ anything yet. Whoever may read `members` gets how many members it has
(`listMembers` names them, a page at a time), the roles and what each
may do, and the spaces, with a space's access shown only to
those who may read it. A holder of `admit` also gets the join requests. A
switched-off group shows only the first part and `deactivated: true`.
switched-off group shows only the first part and `deactivated: true`,
and to one signed in, `viewer.steward`: whether they may switch it back
on, as nothing else of their standing is read.
A group that wants to be found says so with its declaration, a
`fyi.opensocial.declaration` record in its public repo pointing at
@@ -251,6 +253,12 @@ A switched-off group's roles cannot decide who may switch it back on, so
the host keeps who held `group.configure` when it was switched off.
`activateGroup` is for one of those stewards.
In the console, the profile page of a group's settings switches it off
or deletes it, each asked to be sure of. Switched off, the group's page
says so, and to its stewards offers to switch it back on or delete it.
The commands are `group deactivate` (`--undo` switches it back on) and
`group delete`; an MCP client can switch the group off, never delete it.
`deleteGroup` is for a holder of `group.configure`, or for a kept steward
while the group is off. It tells the syncers of each space, ends the
DID, then deletes the account, repos, spaces, address, invites, join requests, tokens,
docs/design/mcp.md+2−1
@@ -121,7 +121,8 @@ Some of what the host does is not a tool. An MCP client cannot list or
end connections, so it cannot hide itself or end another client's. It
cannot make a group, move one, or bring an account here, which are
commands only, nor change the group's recovery keys or delete it (see
[recovery](recovery.md)); those stay with the member.
[recovery](recovery.md)); those stay with the member. It can switch the
group off, as `group_deactivate`, which a steward undoes.
Details:
docs/reference/cli.md+6−2
@@ -38,8 +38,10 @@ replaces the record whole, a field not given dropped, but `profile set`,
which changes only the fields given (`""` takes one away), and `role
grant`, which adds to a role's grant or with `--undo` takes from it.
The commands with no tool make or move a group or an account: `group
create`, `group seed`, `group move` and `account import`.
The commands with no tool make, move or delete a group or an account:
`group create`, `group seed`, `group move`, `group delete` and `account
import`. A client connected to a group can switch it off, which its
stewards undo, but never delete it.
### group
@@ -49,6 +51,8 @@ create`, `group seed`, `group move` and `account import`.
| `group show <group>` | the group as you may see it: its roles, its first hundred members and its spaces |
| `group seed <handle>` | a group to try things on, joined by approval: two rules, a moderator role (`mod.read`, `mod.resolve`, `label`) that the founder may give, written as the group, and an invite for each of `OPENSOCIAL_SEED_INVITE` |
| `group move <group> --to <address> [--to-did <did>]` | moves a group, whole, from this host to another, making the four calls in turn; run again after a run that handed it over but could not switch it on, it switches it on; `--to-did` is the did:web of `--to` if not given ([moving](../design/moving.md)) |
| `group deactivate <group> [--undo]` | switches the group off, so nothing reads its spaces or writes as it; with `--undo`, switches it back on, for one who held `group.configure` when it went off ([switching off](../design/groups.md#switching-off-on-and-deleting)) |
| `group delete <group>` | deletes the group, its spaces and its account here, for good, and prints whether its DID was ended or left to the holders of its recovery keys |
### profile
docs/reference/mcp.md+5−2
harness/e2e/flows.spec.mjs+32−0
lexicons/fyi/opensocial/defs.json+5−1
web/src/lib/molecules/ConfirmDialog.svelte+6−3
web/src/lib/molecules/DeleteGroup.sveltenew+12−0
web/src/lib/molecules/SwitchedOff.sveltenew+27−0
web/src/lib/organisms/NewGroupForm.svelte+9−1
web/src/lib/organisms/SwitchOff.sveltenew+17−0
web/src/lib/server/settings.ts+18−2
web/src/routes/g/[handle]/settings/+page.svelte+5−0
web/src/routes/g/[handle]/+page.server.ts+3−2
web/src/routes/g/[handle]/+page.svelte+5−4
web/src/app.css+1−0
AGENTS.md+4−3