chadtmiller.com/group-host
atmosphere group host
0
0
The command finishes a move it was stopped in
crates/opensocial/src/lib.rs+22−3
| @@ -465,7 +465,15 @@ async fn migrate(me: &Client, from: &Host, to: &Host, group: &str) -> Result<Str | ||
let group = me.resolve(from, group).await?; | ||
let mut out = format!("moving {group}\n from {}\n to {}\n", from.url, to.url); | ||
let body = json!({"group": group, "destDid": to.did}); | ||
let prepared = me.call(from, &m("migratePrepare"), &body).await?; | ||
let prepared = match me.call(from, &m("migratePrepare"), &body).await { | ||
Ok(prepared) => prepared, | ||
// Handed over by a run that stopped before switching it on: that | ||
// is the step left. | ||
Err(e) if e.to_string().contains("NotController") => { | ||
return activate(me, to, &group, out + "handed over already\n").await; | ||
} | ||
Err(e) => return Err(e), | ||
}; | ||
let spaces = prepared["snapshot"]["spaces"] | ||
.as_array() | ||
.map_or(0, Vec::len); | ||
| @@ -484,8 +492,16 @@ async fn migrate(me: &Client, from: &Host, to: &Host, group: &str) -> Result<Str | ||
let body = json!({"group": group, "recommendedCreds": received["recommendedCreds"]}); | ||
let done = me.call(from, &m("migrateComplete"), &body).await?; | ||
out += &format!("handed over to {}\n", text(&done["movedTo"])); | ||
activate(me, to, &group, out).await | ||
} | ||
| ||
/// Switches `group` on at `to`, once handed over: what was done, or, if it | ||
/// could not be yet, that the same command run again does it. | ||
async fn activate(me: &Client, to: &Host, group: &str, mut out: String) -> Result<String> { | ||
let body = json!({"did": group}); | ||
me.call(to, &m("migrateActivate"), &body).await?; | ||
if let Err(e) = me.call(to, &m("migrateActivate"), &body).await { | ||
bail!("{out}not switched on yet: {e}\nrun the same command again to switch it on"); | ||
} | ||
out += "switched on\n"; | ||
Ok(out) | ||
} | ||
| @@ -510,7 +526,10 @@ async fn import( | ||
let mut asked = vec![("did", did.as_str())]; | ||
asked.extend(a.flags.get("address").map(|l| ("address", *l))); | ||
let plan = me.query(host, &m("checkImport"), &asked).await?; | ||
if let Some(no) = plan.get("refused") { | ||
// A move of yours already pending is finished, whatever the address | ||
// would be now. | ||
let pending = plan.get("recommendedCreds").is_some(); | ||
if let Some(no) = plan.get("refused").filter(|_| !pending) { | ||
bail!("{} can't move here: {}", account, text(&no["message"])); | ||
} | ||
let Some(password) = &env.import_password else { | ||
crates/opensocial/tests/commands.rs+21−2
| @@ -174,6 +174,11 @@ async fn moves_a_group_to_another_host() { | ||
let (a, b) = (host().await, host().await); | ||
let alice = env(&a, 0); | ||
ok(&alice, &["create-group", "riders.groups.test"]).await; | ||
// Only one who runs it may move it. | ||
let bob = env(&a, 1); | ||
let to = format!("{}/", b.url); | ||
let said = fails(&bob, &["migrate", "riders.groups.test", "--to", &to]).await; | ||
assert!(said.contains("fyi.opensocial.migratePrepare"), "{said}"); | ||
let said = ok( | ||
&alice, | ||
&[ | ||
| @@ -194,7 +199,16 @@ async fn moves_a_group_to_another_host() { | ||
.unwrap() | ||
.did; | ||
assert!(b.host.deactivation(&did).unwrap().is_none()); | ||
// Named by its DID, to a host that is not there. | ||
// Run again, it picks up at switching it on, which is done. | ||
let again = ["migrate", "riders.groups.test", "--to", &b.url]; | ||
let said = ok(&alice, &again).await; | ||
assert_eq!(said.lines().nth(3), Some("handed over already"), "{said}"); | ||
assert!(said.ends_with("switched on\n"), "{said}"); | ||
// Towards a host that never took it in, it says it is not on yet. | ||
let c = host().await; | ||
let said = fails(&alice, &["migrate", "riders.groups.test", "--to", &c.url]).await; | ||
assert!(said.contains("not switched on yet"), "{said}"); | ||
// Named by its DID, to a host that is not there: not on yet. | ||
let said = fails( | ||
&alice, | ||
&[ | ||
| @@ -207,7 +221,7 @@ async fn moves_a_group_to_another_host() { | ||
], | ||
) | ||
.await; | ||
assert!(said.contains("fyi.opensocial.migratePrepare"), "{said}"); | ||
assert!(said.contains("reaching http://127.0.0.1:1"), "{said}"); | ||
} | ||
| ||
/// `nsid` of the reference PDS, as `bearer`: a query with `query`, or a | ||
| @@ -314,6 +328,11 @@ async fn moves_an_account_and_its_spaces_here_to_become_a_group() { | ||
assert!(said.contains("can't move here"), "{said}"); | ||
let said = fails(&mover, &["import", &handle, "--code", "nothing-sent"]).await; | ||
assert!(said.contains("no move of"), "{said}"); | ||
// Its own label taken here, it is brought under another, and finished | ||
// with the code alone. | ||
ok(&plain, &["create-group", &format!("{name}.groups.test")]).await; | ||
let said = fails(&mover, &["import", &handle]).await; | ||
assert!(said.contains("can't move here"), "{said}"); | ||
let club = format!("{name}-club"); | ||
let said = ok(&mover, &["import", &handle, "--address", &club]).await; | ||
assert!(said.contains(&format!("as {club}.groups.test")), "{said}"); | ||
docs/design/moving.md+2−1
| @@ -116,7 +116,8 @@ the host it leaves controls it, and a failed receive left nothing at the | ||
new one. After it, the new host holds it, switched off until activated. | ||
| ||
The `opensocial migrate` command makes the four calls in order | ||
([cli](../reference/cli.md)). The console has no page for this move. | ||
([cli](../reference/cli.md)). Run again after it handed the group over | ||
but could not switch it on, it does only that. The console has no page for this move. | ||
| ||
## Bringing an account here as a group | ||
| ||
docs/reference/cli.md+2−2
| @@ -23,9 +23,9 @@ any PDS may run it against any host. | ||
| `membership assign <group> <member> <role,role…>` | gives a member these roles, in place of theirs (`member` among them) | | ||
| `membership eject <group> <member> [--reason]` | puts a member out | | ||
| `membership invite <group> <person> [--message]` | invites someone in | | ||
| `migrate <group> --to <address> [--to-did <did>]` | moves a group, whole, from this host to another, making the four calls in turn; `--to-did` is the did:web of `--to` if not given ([moving](../design/moving.md)) | | ||
| `migrate <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)) | | ||
| `import <account> [--address <label>]` | moves an account from its server here, its spaces with it, to become a group run by you; its server emails a code ([moving](../design/moving.md#bringing-an-account-here-as-a-group)) | | ||
| `import <account> --code <code>` | with that code, has its server sign its identity over, and finishes | | ||
| `import <account> --code <code>` | with that code, has its server sign its identity over, and finishes, whatever `--address` the start was given | | ||
| `seed <handle>` | a group to try things on, joined by approval: two rules, a moderator role (`mod.read`, `mod.resolve`, `label`), and an invite for each of `OPENSOCIAL_SEED_INVITE` | | ||
| ||
A group or person is a handle or a DID, resolved by the host's | ||