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

A group takes appeals from those its moderators acted on

Merged chadtmiller.com asked to merge into main from chadtmiller.com/group-host:appeals
crates/group-host/src/group.rs+11−3
@@ -33,10 +33,18 @@ pub fn did_rkey(did: &str) -> String {
}
/// What the labeler every group starts with says: the labels the host
/// acts on, and reports about accounts and records.
/// acts on, and reports about accounts and records, appeals among them.
fn labeler(at: &str) -> Value {
let reasons = ["Spam", "Violation", "Misleading", "Sexual", "Rude", "Other"]
.map(|r| format!("com.atproto.moderation.defs#reason{r}"));
let reasons = [
"Spam",
"Violation",
"Misleading",
"Sexual",
"Rude",
"Other",
"Appeal",
]
.map(|r| format!("com.atproto.moderation.defs#reason{r}"));
json!({
"$type": format!("{NS}.labeler"),
"policies": {"labelValues": ["!hide", "!takedown"]},
crates/group-host/src/moderation.rs+15−3
@@ -230,6 +230,9 @@ pub fn space_of(uri: &str) -> Option<(String, String)> {
/// another as long.
const REASON_TYPE_MAX: usize = 256;
/// The reason of a report that appeals what the group did to its subject.
const APPEAL: &str = "com.atproto.moderation.defs#reasonAppeal";
/// The account a public record's URI is in, `at://<did>/<collection>/<rkey>`,
/// a record in no space, each of its parts what it says.
fn public_of(uri: &str) -> Option<&str> {
@@ -584,7 +587,8 @@ fn accepts(labeler: &Value, key: &str, value: &str) -> bool {
/// A report, from one who can read its subject: an account in a group
/// here, a record in one of its spaces, or a member's public record, into
/// that group's queue.
/// that group's queue. An appeal is a report only its subject files: the
/// account, or the record's author, who may have been put out since.
pub async fn create_report(
State(host): State<Arc<Host>>,
headers: HeaderMap,
@@ -615,6 +619,14 @@ pub async fn create_report(
"the group takes no reports of {reason_type}"
)));
}
let appeal = reason_type == APPEAL;
if appeal && account_of(&subject) != me {
return Err(invalid("only its subject may appeal"));
}
// What the queue already has of someone is theirs to appeal, though
// they no longer hold a role, nor read where it is.
let queued = host.store.subject(group, &subject);
let appealed = appeal && queued.map_err(XrpcError::internal)?.is_some();
// A record in a space is reported in its own; an account, or a
// member's public record, in the members space, where its labels go.
let collection = subject
@@ -630,7 +642,7 @@ pub async fn create_report(
None => {
let account = public_of(&subject).unwrap_or(&subject);
let roles = host.roles(group, account).map_err(XrpcError::internal)?;
if roles.is_empty() {
if roles.is_empty() && !appealed {
return Err(invalid_subject("not a member of this group"));
}
members_space(group)
@@ -644,7 +656,7 @@ pub async fn create_report(
let hosted = host.store.space(&space).map_err(XrpcError::internal)?;
let hosted = hosted.ok_or_else(|| invalid_subject("not in a space hosted here"))?;
let reads = host.may(&space, &hosted, Some(me.as_str()), Access::Read);
if !reads.map_err(XrpcError::internal)? {
if !appealed && !reads.map_err(XrpcError::internal)? {
return Err(invalid_subject("not in a space you can read"));
}
let now = now_millis();
crates/group-host/tests/moderation.rs+101−0
@@ -61,6 +61,14 @@ async fn report(h: &Running, who: &Authority, group: &str, subject: Json) -> (u1
call(h, who, "createReport", body).await
}
const APPEAL: &str = "com.atproto.moderation.defs#reasonAppeal";
/// `who` appeals what the group did to `subject`, as a report of it.
async fn appeal(h: &Running, who: &Authority, group: &str, subject: Json) -> (u16, Json) {
let body = json!({"group": group, "reasonType": APPEAL, "reason": "it was a joke", "subject": subject});
call(h, who, "createReport", body).await
}
fn error(said: &(u16, Json)) -> (u16, &str) {
(said.0, said.1["error"].as_str().unwrap_or_default())
}
@@ -264,6 +272,99 @@ async fn takes_only_the_reports_its_labeler_does() {
"{subject}"
);
}
// An appeal is a reason like any other, and this labeler takes none.
assert_eq!(
error(&appeal(&h, &bob, &did, record(uri)).await),
(400, "InvalidRequest")
);
}
#[tokio::test]
async fn takes_an_appeal_only_from_its_subject() {
let h = start(&[], false).await;
let (did, _, post, [alice, bob, carol]) = group(&h).await;
// A new group's labeler takes appeals.
let labeler = h
.host
.group_record(&did, &meta_space(&did), &format!("{NS}.labeler"), "self")
.unwrap()
.unwrap();
let reasons = labeler["reasonTypes"].as_array().unwrap();
assert!(reasons.contains(&json!(APPEAL)), "{labeler}");
// Bob appeals his post in the calendar, and his public one: each a
// report in the queue, its reason an appeal.
let in_space = post["uri"].as_str().unwrap().to_string();
let public = format!("at://{}/app.bsky.feed.post/3mzjdd6rnfise", bob.did);
for uri in [&in_space, &public] {
let (status, said) = appeal(&h, &bob, &did, record(uri)).await;
assert_eq!(status, 200, "{said}");
let q = format!("group={did}&subject={uri}");
let (_, history) = query(&h, &alice, "getSubjectHistory", &q).await;
assert_eq!(kinds(&history), ["reportEvent"]);
assert_eq!(history["events"][0]["event"]["reasonType"], APPEAL);
assert_eq!(history["events"][0]["createdBy"], bob.did.as_str());
// Alice reads it, but it is not hers to appeal.
let said = appeal(&h, &alice, &did, record(uri)).await;
assert_eq!(error(&said), (400, "InvalidRequest"), "{uri}");
let message = said.1["message"].as_str().unwrap();
assert!(message.contains("only its subject may appeal"), "{message}");
}
let resolve = json!({"group": did, "subject": record(&public), "status": "resolved"});
assert_eq!(call(&h, &alice, "resolveSubject", resolve).await.0, 200);
// Bob appeals for his own account; no one else may for him.
let (status, said) = appeal(&h, &bob, &did, account(&bob.did)).await;
assert_eq!(status, 200, "{said}");
let said = appeal(&h, &alice, &did, account(&bob.did)).await;
assert_eq!(error(&said), (400, "InvalidRequest"));
// Carol was never in the group, and the queue has nothing of hers.
let said = appeal(&h, &carol, &did, account(&carol.did)).await;
assert_eq!(error(&said), (400, "InvalidSubject"));
// Put out, Bob still appeals what the queue has of his.
let app = App::new("console");
let members = members_space(&did);
let token = app.token_for(&h, &alice, &did, &members).await;
let body = json!({"repo": did, "space": members, "collection": format!("{NS}.membership"), "rkey": bob.did});
let said = app
.call(&h, "com.atproto.space.deleteRecord", &token, Some(&body))
.await;
assert_eq!(said.status, 200, "{}", said.body);
for subject in [account(&bob.did), record(&in_space), record(&public)] {
let (status, said) = appeal(&h, &bob, &did, subject.clone()).await;
assert_eq!(status, 200, "{subject} {said}");
}
let q = format!("group={did}&subject={}", bob.did);
let (_, history) = query(&h, &alice, "getSubjectHistory", &q).await;
assert_eq!(
kinds(&history),
["reportEvent", "ejectEvent", "reportEvent"]
);
// The appeal reopened what was resolved.
let (_, queue) = query(&h, &alice, "listSubjects", &format!("group={did}")).await;
let open = queue["subjects"].as_array().unwrap();
assert!(
open.iter().any(|s| s["subject"] == record(&public)),
"{queue}"
);
// But not a post of his the queue never had, nor in a group where it
// has nothing of his.
let other = start_group(
&h,
&alice,
json!({"handle": "hikers.groups.test", "displayName": "Hikers"}),
)
.await;
let unseen = format!("at://{}/app.bsky.feed.post/3mzjdd6rnfisf", bob.did);
for (group, subject) in [
(&did, record(&unseen)),
(&other, account(&bob.did)),
(&other, record(&public)),
] {
let said = appeal(&h, &bob, group, subject.clone()).await;
assert_eq!(error(&said), (400, "InvalidSubject"), "{group} {subject}");
}
}
/// A label on `subject` of `val`, as the group writes it.
docs/design/moderation.md+26−4
@@ -113,7 +113,8 @@ version of a record it is about as `cid` when it names one, and one of
four kinds as `event`:
- `reportEvent`: someone reported it, with a `reasonType`, an optional
`reason` and the `rule` it cites, if any.
`reason` and the `rule` it cites, if any. An appeal is one, its
`reasonType` `com.atproto.moderation.defs#reasonAppeal`.
- `statusEvent`: a moderator set its `status`, with an optional `note`.
- `labelEvent`: a label was written, by the label record's `uri` and its
`val`; or, with `deleted: true`, deleted, which takes it back.
@@ -171,7 +172,26 @@ of its lists, when present, limits them: `reasonTypes` the reasons,
`subjectTypes` the kinds of subject (`account`, `record`), and
`subjectCollections` the collections a reported record may be in. A new
group's labeler takes reports of accounts and records, for the common
reasons, of any collection.
reasons and appeals, of any collection.
## Appeals
Someone a group moderated should be able to answer it, and the
moderators should hear it where they hear everything else. So an appeal
is a report, its `reasonType` `com.atproto.moderation.defs#reasonAppeal`,
filed by its subject: an account for itself, or a record's author for
the record, the DID its URI is in. Anyone else appealing is refused
`InvalidRequest`, saying only its subject may appeal. It goes into the
queue as a `reportEvent` like any report, reopening a resolved subject,
and keeps its reason, so a moderator reads it as an appeal.
Whoever was put out of the group no longer holds a role, nor reads the
members space, yet what was done to them is theirs to answer. So an
appeal of a subject the queue already has, by any event (a report, a
label, an ejection), is taken though its author is no longer a member
and cannot read the space it is in. Any other appeal is held to the
rules of any report. The labeler still decides: a group whose
`reasonTypes` leave appeals out takes none.
## The group's own labels
@@ -197,8 +217,10 @@ Details:
- A group not hosted here is `GroupNotFound`. A subject the reporter
cannot read, that is not in the group, a public record of someone not
a member, or of a kind or collection the labeler does not take, is
`InvalidSubject`; a reason it does not take is `InvalidRequest`. A
member's public record is a `record`, of its collection.
`InvalidSubject`; a reason it does not take, or an appeal by anyone but
its subject, is `InvalidRequest`. An appeal of a subject already in the
queue is taken though it is no longer in the group or readable by its
author. A member's public record is a `record`, of its collection.
- A `rule` must be a record's URI in the group's meta space.
- The host does not check that the reported record exists or that its
CID matches.
docs/design/README.md+1−1
@@ -60,7 +60,7 @@ accounts on their own PDSes, anywhere on the network.
- [Membership](membership.md): roles, joining, invites, and leaving.
- [Signing in](signing-in.md): people, apps and MCP clients, and what a
token may do.
- [Moderation](moderation.md): labels, the queue, and reports.
- [Moderation](moderation.md): labels, the queue, reports and appeals.
- [Sites](sites.md): a group's website, published whole and served
sandboxed at its address or on its own domain, and the live data a
visitor sees once signed in on it.
docs/guides/moderating.md+5−0
@@ -38,6 +38,11 @@ the console. Each report lands on this page, with the reason the member
chose and what they wrote. A member can report an account only while it
is in the group, and a post only in a part of the group they can read.
Someone can also appeal what you did to them: their account, or a post
of theirs. An appeal is a report whose reason is Appeal, and only the
one it is about can send it. Someone you removed from the group can
still appeal anything of theirs already on this page.
## What is on the Moderation page?
1. Look at the **Open** tab. Each row is one subject: an account, or a
docs/reference/api.md+1−1
@@ -206,7 +206,7 @@ its tools are in [MCP tools](mcp.md).
| Method | What it does |
| --- | --- |
| `POST fyi.opensocial.createReport` | reports a member, a record in one of the group's spaces here, or a member's record in their public repo, from one who can read its space (the members space for a member or their public record) and as the group's labeler takes reports; answers the report's `id` and `createdAt`. A reason or note is 2,000 characters (20,000 bytes) at most |
| `POST fyi.opensocial.createReport` | reports a member, a record in one of the group's spaces here, or a member's record in their public repo, from one who can read its space (the members space for a member or their public record) and as the group's labeler takes reports; answers the report's `id` and `createdAt`. With `reasonType` `com.atproto.moderation.defs#reasonAppeal` it is an appeal, which only its subject files (the account itself, or the record's author; anyone else is `InvalidRequest`), taken though they were put out when the queue already has the subject. A reason or note is 2,000 characters (20,000 bytes) at most |
| `GET fyi.opensocial.listSubjects` | the moderation queue of one status, `open` unless asked |
| `GET fyi.opensocial.getSubjectHistory` | a subject's events, oldest first, a page at a time; with a `cid`, those about that version |
| `POST fyi.opensocial.resolveSubject` | sets a subject `resolved` or `escalated`, with an optional note; answers the subject |
lexicons/fyi/opensocial/createReport.json+1−1
@@ -4,7 +4,7 @@
"defs": {
"main": {
"type": "procedure",
"description": "Report an account or record in a group, or a member's record in their public repo, opening or reopening it in the moderation queue. Uses service auth from the caller, who must be able to read the subject's space: a record's own, or the members space for an account or a public record.",
"description": "Report an account or record in a group, or a member's record in their public repo, opening or reopening it in the moderation queue. Uses service auth from the caller, who must be able to read the subject's space: a record's own, or the members space for an account or a public record. A report whose reasonType is com.atproto.moderation.defs#reasonAppeal is an appeal, which only its subject may file: the account itself, or the record's author; one the queue already has is taken though its author is no longer in the group.",
"input": {
"encoding": "application/json",
"schema": {
lexicons/fyi/opensocial/defs.json+1−1
@@ -949,7 +949,7 @@
},
"reportEvent": {
"type": "object",
"description": "Someone reported the subject.",
"description": "Someone reported the subject; with reasonType com.atproto.moderation.defs#reasonAppeal, the subject appealed.",
"required": [
"reasonType"
],
web/src/routes/g/[handle]/moderation/+page.server.ts+1−1
@@ -15,7 +15,7 @@ type Did = `did:${string}:${string}`;
type Event = { fetch: typeof fetch; params: { handle?: string } };
type Status = 'open' | 'escalated' | 'resolved';
const STATUSES: string[] = ['open', 'escalated', 'resolved'];
/** The reasons a report gives, as a new group's labeler takes them. */
/** The reasons a moderator's report gives: a new group's labeler's, but an appeal, only its subject's. */
const REASONS = ['Spam', 'Misleading', 'Rude', 'Sexual', 'Violation', 'Other'].map(
(r) => `com.atproto.moderation.defs#reason${r}`
);