chadtmiller.com/group-host
atmosphere group host
0
0
The lexicons say what the host answers, and an ejection is kept
crates/group-host/src/group_members.rs+17−1
| @@ -15,6 +15,7 @@ use crate::api::{at_most, invalid}; | ||
use crate::group::{did_rkey, members_space}; | ||
use crate::group_api::{group_of, signed_in}; | ||
use crate::group_config::put_in; | ||
use crate::moderation::Event; | ||
use crate::rbac::{ACTIONS, Grant, NS, actions_for, actions_of, grants, listed, scope_of}; | ||
use crate::repo::Write; | ||
use crate::time::{iso, now_millis}; | ||
| @@ -488,10 +489,15 @@ pub async fn eject_member( | ||
headers: HeaderMap, | ||
Json(body): Json<Value>, | ||
) -> Answer { | ||
let (members, _, mine) = acting(&host, &headers, &body, "ejectMember", Some("eject")).await?; | ||
let (members, me, mine) = acting(&host, &headers, &body, "ejectMember", Some("eject")).await?; | ||
let member = body["member"] | ||
.as_str() | ||
.ok_or_else(|| invalid("member is required"))?; | ||
let reason = body["reason"].as_str(); | ||
// As the lexicon has it: 300 graphemes, 3000 bytes, at most. | ||
if reason.is_some_and(|r| r.len() > 3000 || r.chars().count() > 300) { | ||
return Err(invalid("a reason is 300 characters at most")); | ||
} | ||
let theirs = members | ||
.membership(member)? | ||
.ok_or_else(|| bad("NotAMember", format!("{member} is not a member")))?; | ||
| @@ -505,6 +511,16 @@ pub async fn eject_member( | ||
} | ||
members.keeps_a_configurer(member, &[])?; | ||
host.put_out(&members.group, member).await?; | ||
// Kept in the group's queue, on them, for its moderators to read. | ||
let event = Event { | ||
kind: "eject".into(), | ||
actor: Some(me), | ||
reason: reason.map(str::to_string), | ||
created_at: now_millis(), | ||
..Event::default() | ||
}; | ||
let noted = host.store.moderate(&members.group, member, &event); | ||
noted.map_err(XrpcError::internal)?; | ||
Ok(Json(json!({}))) | ||
} | ||
| ||
crates/group-host/src/migration.rs+1−2
| @@ -11,8 +11,7 @@ | ||
//! keeps who writes, so it reads them on without waiting for them to write | ||
//! again, and their PDSes find the new authority by the group's DID. | ||
//! | ||
//! The steps, each a method, which the `opensocial` command or the console | ||
//! walks through: | ||
//! The steps, each a method, which the `opensocial` command walks through: | ||
//! | ||
//! 1. `migratePrepare`, at the source: a service token the group signs, for | ||
//! the destination; the group's handle and spaces; and a token, good for | ||
crates/group-host/src/moderation.rs+1−3
| @@ -315,9 +315,7 @@ pub async fn negate_label( | ||
headers: HeaderMap, | ||
Json(body): Json<Value>, | ||
) -> Answer { | ||
// Its record is not the answer: a negation answers nothing. | ||
let _negation = host.label(&headers, "negateLabel", &body, true).await?; | ||
Ok(Json(json!({}))) | ||
host.label(&headers, "negateLabel", &body, true).await | ||
} | ||
| ||
fn subject_view(s: &Subject) -> Value { | ||
crates/group-host/src/repo.rs+1−1
| @@ -594,7 +594,7 @@ fn walk<'a>( | ||
| ||
/// The CID a record's JSON is kept under, once it is a record of | ||
/// `collection`. | ||
pub(crate) fn record_cid(collection: &str, value: &serde_json::Value) -> Result<Cid, XrpcError> { | ||
pub fn record_cid(collection: &str, value: &serde_json::Value) -> Result<Cid, XrpcError> { | ||
Ok(record(collection, value)?.0) | ||
} | ||
| ||
crates/group-host/tests/members.rs+12−1
| @@ -420,12 +420,18 @@ async fn one_put_out_reads_no_more() { | ||
&h, | ||
&dave, | ||
"ejectMember", | ||
json!({"group": did, "member": bob.did}) | ||
json!({"group": did, "member": bob.did, "reason": "kept posting spam"}) | ||
) | ||
.await, | ||
(200, json!({})) | ||
); | ||
assert_eq!(record(&h, &did, "membership", &bob.did), None); | ||
// The ejection stays in the group's queue, on him, with its reason. | ||
let events = h.host.store.events(&did, &bob.did).unwrap(); | ||
assert_eq!(events.len(), 1); | ||
assert_eq!(events[0].kind, "eject"); | ||
assert_eq!(events[0].actor.as_deref(), Some(dave.did.as_str())); | ||
assert_eq!(events[0].reason.as_deref(), Some("kept posting spam")); | ||
assert!( | ||
h.host | ||
.store | ||
| @@ -454,6 +460,11 @@ async fn one_put_out_reads_no_more() { | ||
(403, "Forbidden"), | ||
), | ||
(&dave, json!({"group": did}), (400, "InvalidRequest")), | ||
( | ||
&dave, | ||
json!({"group": did, "member": dave.did, "reason": "x".repeat(301)}), | ||
(400, "InvalidRequest"), | ||
), | ||
] { | ||
let said = call(&h, who, "ejectMember", body.clone()).await; | ||
assert_eq!(error(&said), refused, "{body}"); | ||
crates/group-host/tests/moderation.rs+19−3
| @@ -8,7 +8,7 @@ use common::spaces::*; | ||
use common::{Running, start}; | ||
use group_host::group::{members_space, meta_space}; | ||
use group_host::moderation::space_of; | ||
use group_host::repo::Write; | ||
use group_host::repo::{Write, record_cid}; | ||
use serde_json::{Value as Json, json}; | ||
| ||
const CALENDAR: &str = "com.example.calendar"; | ||
| @@ -184,14 +184,30 @@ async fn writes_a_label_beside_what_it_labels() { | ||
assert_eq!(queue["subjects"][0]["reportCount"], 0); | ||
| ||
// Taken back with a second record, not by deleting the first. | ||
let (status, _) = call( | ||
let (status, negated) = call( | ||
&h, | ||
&alice, | ||
"negateLabel", | ||
json!({"group": did, "subject": record, "val": "spam"}), | ||
) | ||
.await; | ||
assert_eq!(status, 200); | ||
assert_eq!(status, 200, "{negated}"); | ||
// Answered as a label is: the negation is a record of its own. | ||
let uri = negated["uri"].as_str().unwrap(); | ||
assert!( | ||
uri.starts_with(&format!("{space}/{did}/{NS}.label/")), | ||
"{uri}" | ||
); | ||
assert_ne!(negated["uri"], made["uri"]); | ||
let rkey = uri.rsplit('/').next().unwrap(); | ||
let negation = h | ||
.host | ||
.group_record(&did, &space, &format!("{NS}.label"), rkey) | ||
.unwrap() | ||
.unwrap(); | ||
assert_eq!(negation["neg"], true); | ||
let cid = record_cid(&format!("{NS}.label"), &negation).unwrap(); | ||
assert_eq!(negated["cid"], cid.to_string()); | ||
let labels = h | ||
.host | ||
.group_records(&did, &space, &format!("{NS}.label")) | ||
docs/design/membership.md+4−0
| @@ -152,6 +152,10 @@ PDSes it sends `com.atproto.space.notifyCredentialRevoked`, best effort. | ||
With no membership they hold no roles, so the access records grant them | ||
nothing. | ||
| ||
An ejection is then kept in the group's [moderation](moderation.md) | ||
queue, as an `eject` event on the member's DID: who put them out, and the | ||
`reason`, if `ejectMember` was given one. Leaving keeps nothing there. | ||
| ||
What they wrote stays in their own repos at their own PDSes. The group's | ||
index forgets it at once, and drops on each sync any writer a space no | ||
longer lets write. | ||
docs/design/moderation.md+7−5
| @@ -77,7 +77,7 @@ Details: | ||
- A record's URI must be a record in a space: | ||
`at://<authority>/space/<type>/<skey>/<repo>/<collection>/<rkey>`. | ||
- The record key is a TID from the host's clock. `applyLabel` answers | ||
the label's `uri` and `cid`. | ||
the label's `uri` and `cid`, and `negateLabel` the negation's. | ||
- A label's value is 128 bytes at most. A subject's CID must parse as | ||
one, and a `rule` cited must be a record's URI in a space, as a rule's | ||
is. | ||
| @@ -95,8 +95,10 @@ those with `mod.read` see it. | ||
A subject in the queue is a record, by its URI, or an account, by its | ||
DID. It has a status: `open`, `escalated` or `resolved`. Its events are | ||
kept in order, each with a kind (`report`, `label`, `negate`, `resolve`, | ||
`escalate`, `note`), the actor, and what applies of a reason, value and | ||
note. A subject enters the queue with its first report or label, opened. | ||
`escalate`, `note`, `eject`), the actor, and what applies of a reason, | ||
value and note. A subject enters the queue with its first report, label | ||
or ejection, opened. An ejection is kept on the member's DID, with who | ||
put them out and the reason `ejectMember` was given. | ||
| ||
`listSubjects` lists the queue, latest changed first, filtered by status | ||
if asked. Every event moves a subject to the top. `getSubjectHistory` | ||
| @@ -109,8 +111,8 @@ is told. | ||
| ||
A resolved subject should come back when someone reports it again. A | ||
label is a moderator's own act, so it should not undo a resolution. So | ||
only a report reopens a resolved subject; a label opens a subject nobody | ||
reported, and leaves a resolved one resolved. An escalated subject stays | ||
only a report reopens a resolved subject; a label or an ejection opens a | ||
subject nobody reported, and leaves a resolved one resolved. An escalated subject stays | ||
escalated through new reports. | ||
| ||
Deleting a group deletes its queue. | ||
docs/reference/api.md+3−3
| @@ -76,12 +76,12 @@ spaces through the atproto methods below. | ||
| `GET fyi.opensocial.listJoinRequests` | the requests waiting, for those who admit | | ||
| `POST fyi.opensocial.admitMember` | lets a request in | | ||
| `POST fyi.opensocial.denyJoinRequest` | turns a request down | | ||
| `POST fyi.opensocial.createInvite` | invites someone, into their own invites space | | ||
| `POST fyi.opensocial.createInvite` | invites someone, into their own inbox | | ||
| `GET fyi.opensocial.listInvites` | the group's invites still waiting | | ||
| `POST fyi.opensocial.revokeInvite` | takes an invite back | | ||
| `GET fyi.opensocial.getActorInvites` | the caller's own invites from groups here | | ||
| `POST fyi.opensocial.declineInvite` | turns an invite down | | ||
| `GET com.atproto.managedspace.checkUserAccess` | whether someone may read or write an invites space the host keeps, asked by its authority | | ||
| `GET com.atproto.managedspace.checkUserAccess` | whether someone may read or write an inbox the host keeps, asked by its authority | | ||
| ||
## People | ||
| ||
| @@ -172,7 +172,7 @@ its tools are in [MCP tools](mcp.md). | ||
| `GET fyi.opensocial.getSubjectHistory` | every event on one subject | | ||
| `POST fyi.opensocial.resolveSubject` | resolves or escalates a subject | | ||
| `POST fyi.opensocial.applyLabel` | labels a subject | | ||
| `POST fyi.opensocial.negateLabel` | takes a label back | | ||
| `POST fyi.opensocial.negateLabel` | takes a label back, with a record of its own | | ||
| ||
## Recovery | ||
| ||
harness/e2e/flows.spec.mjs+4−1
| @@ -237,7 +237,10 @@ test('adding a recovery key, and taking it off', async () => { | ||
test('moderating: a label, and the queue', async () => { | ||
await page.goto(url('/g/hikers.groups.test')) | ||
await page.getByRole('link', { name: 'Moderation' }).click() | ||
await expect(page.getByText('Nothing to look at')).toBeVisible() | ||
// Putting him out is already in the queue, on him. | ||
const ejected = page.locator('.subject', { hasText: who.bob.did }) | ||
await expect(ejected.locator('.status')).toHaveText('open') | ||
await expect(ejected.locator('.events')).toContainText('eject') | ||
await page.getByRole('textbox', { name: 'Their handle' }).fill('bob.test') | ||
await page.getByRole('textbox', { name: 'Label' }).fill('troll') | ||
await page.getByRole('button', { name: 'Label them' }).click() | ||