chadtmiller.com/group-host
atmosphere group host
0
0
Moderation follows the proposal: mod methods, URI subjects, takedowns
crates/group-host/src/api.rs+10−0
| @@ -31,6 +31,16 @@ pub(crate) fn invalid(message: impl Into<String>) -> XrpcError { | ||
XrpcError::new(StatusCode::BAD_REQUEST, "InvalidRequest", message) | ||
} | ||
| ||
/// A cursor this host never gave, as a list whose lexicon names | ||
/// `InvalidCursor` refuses it. | ||
pub(crate) fn invalid_cursor() -> XrpcError { | ||
XrpcError::new( | ||
StatusCode::BAD_REQUEST, | ||
"InvalidCursor", | ||
"a cursor this host gave", | ||
) | ||
} | ||
| ||
/// The parameter `name`, which the method needs. | ||
pub(crate) fn param<'a>(params: &'a Params, name: &str) -> Result<&'a str, XrpcError> { | ||
params | ||
crates/group-host/src/group.rs+5−15
| @@ -49,24 +49,14 @@ pub fn rkey_did(rkey: &str) -> String { | ||
} | ||
| ||
/// What the labeler every group starts with says: the labels the host | ||
/// acts on, and reports about accounts and records, appeals among them. | ||
fn labeler(at: &str) -> Value { | ||
let reasons = [ | ||
"Spam", | ||
"Violation", | ||
"Misleading", | ||
"Sexual", | ||
"Rude", | ||
"Other", | ||
"Appeal", | ||
] | ||
.map(|r| format!("com.atproto.moderation.defs#reason{r}")); | ||
/// acts on, and reports about accounts and records, of every reason, | ||
/// appeals among them. | ||
fn labeler() -> Value { | ||
json!({ | ||
"$type": format!("{NS}.labeler"), | ||
"policies": {"labelValues": ["!hide", "!takedown"]}, | ||
"reasonTypes": reasons, | ||
"reasonTypes": ["spam", "violation", "misleading", "nsfw", "rude", "other", "appeal"], | ||
"subjectTypes": ["account", "record"], | ||
"createdAt": at, | ||
}) | ||
} | ||
| ||
| @@ -236,7 +226,7 @@ impl Host { | ||
} | ||
let meta_writes = [ | ||
put(&c("profile"), "self", profile), | ||
put(&c("labeler"), "self", labeler(&at)), | ||
put(&c("labeler"), "self", labeler()), | ||
put(&c("access"), "self", meta_access(readers)), | ||
]; | ||
self.space_write(&did, &meta, &meta_writes).await?; | ||
crates/group-host/src/group_join.rs+2−5
| @@ -10,7 +10,7 @@ | ||
//! ask again and the group need not say. | ||
| ||
use crate::Host; | ||
use crate::api::{Params, invalid, page, param}; | ||
use crate::api::{Params, invalid_cursor, page, param}; | ||
use crate::group::meta_space; | ||
use crate::group_api::{group_of, signed_in}; | ||
use crate::group_invites::invite_uri; | ||
| @@ -137,10 +137,7 @@ pub async fn list_join_requests( | ||
let limit = page(&p, 50, 100)?; | ||
let before = match p.get("cursor") { | ||
None => None, | ||
Some(c) => Some( | ||
c.parse::<i64>() | ||
.map_err(|_| invalid("a cursor this host gave"))?, | ||
), | ||
Some(c) => Some(c.parse::<i64>().map_err(|_| invalid_cursor())?), | ||
}; | ||
let waiting = host | ||
.store | ||
crates/group-host/src/index_api.rs+25−6
| @@ -1,13 +1,15 @@ | ||
//! The space index, served: what is in one of a group's spaces, and the | ||
//! pictures and files there, for whoever its access record lets read the | ||
//! space, signed in, asked on every call. The index holds copies; it | ||
//! never decides who sees them. | ||
//! never decides who sees them. What the group takes down with a | ||
//! `!takedown` label (`takedown.rs`) it serves to nobody. | ||
| ||
use crate::Host; | ||
use crate::api::{Params, invalid, page, param}; | ||
use crate::authority::Access::Write; | ||
use crate::group_api::{group_of, signed_in}; | ||
use crate::rbac::{Access, NS}; | ||
use crate::store::Indexed; | ||
use crate::time::iso; | ||
use crate::xrpc::XrpcError; | ||
use atproto::space::SpaceRef; | ||
| @@ -77,24 +79,30 @@ fn text_of(value: &Value) -> String { | ||
| ||
/// Records in one of a group's spaces, from the index: one collection or | ||
/// every one, newest first, a page at a time; only those whose `field` | ||
/// equals `equals`, if it says; or the one at `uri`. | ||
/// equals `equals`, if it says; or the one at `uri`. None the group has | ||
/// taken down (`takedown.rs`). | ||
pub async fn list_space_records( | ||
State(host): State<Arc<Host>>, | ||
Query(p): Query<Params>, | ||
headers: HeaderMap, | ||
) -> Result<Json<Value>, XrpcError> { | ||
let (_, space) = readable(&host, &p, &headers, "listSpaceRecords").await?; | ||
let (group, space) = readable(&host, &p, &headers, "listSpaceRecords").await?; | ||
// A space with writes the index has not read yet is read first. | ||
// Read at most a few seconds: past that, the index as it is. | ||
let synced = tokio::time::timeout(SYNC_AT_MOST, host.sync_space(&space)).await; | ||
tracing::debug!(space, ?synced, "read before listing"); | ||
let limit = page(&p, 50, 100)?; | ||
let view = |r: &crate::store::Indexed| { | ||
let down = host | ||
.taken_down(&group, &space) | ||
.map_err(XrpcError::internal)?; | ||
let uri_of = |r: &Indexed| format!("{space}/{}/{}/{}", r.did, r.collection, r.rkey); | ||
let hidden = |r: &Indexed| down.hides(&uri_of(r), &r.did, &r.cid.to_string()); | ||
let view = |r: &Indexed| { | ||
let value = drisl::decode(&r.value) | ||
.expect("a record the host indexed") | ||
.to_json(); | ||
json!({ | ||
"uri": format!("{space}/{}/{}/{}", r.did, r.collection, r.rkey), | ||
"uri": uri_of(r), | ||
"cid": r.cid.to_string(), | ||
"repo": r.did, | ||
"value": value, | ||
| @@ -111,7 +119,7 @@ pub async fn list_space_records( | ||
.store | ||
.indexed_one(&space, did, &format!("{collection}/{rkey}")) | ||
.map_err(XrpcError::internal)?; | ||
let records: Vec<Value> = one.iter().map(view).collect(); | ||
let records: Vec<Value> = one.iter().filter(|r| !hidden(r)).map(view).collect(); | ||
return Ok(Json(json!({ "records": records }))); | ||
} | ||
let collection = p.get("collection").map(String::as_str); | ||
| @@ -136,6 +144,9 @@ pub async fn list_space_records( | ||
let ended = batch.len() < limit as usize; | ||
for r in &batch { | ||
before = Some(r.seq); | ||
if hidden(r) { | ||
continue; | ||
} | ||
let shown = view(r); | ||
let matches = wanted.is_none_or(|(field, equals)| { | ||
at_path(&shown["value"], field).is_some_and(|v| text_of(v) == equals) | ||
| @@ -166,6 +177,14 @@ pub async fn get_space_blob( | ||
let (group, space) = readable(&host, &p, &headers, "getSpaceBlob").await?; | ||
let repo = param(&p, "repo")?; | ||
let cid = Cid::parse(param(&p, "cid")?).map_err(|e| invalid(format!("cid: {e}")))?; | ||
// One the group has taken down is not served, as though not there. | ||
let down = host | ||
.taken_down(&group, &space) | ||
.map_err(XrpcError::internal)?; | ||
let gone = host.file_taken_down(&down, &space, repo, &cid); | ||
if gone.map_err(XrpcError::internal)? { | ||
return Err(not_found("no such file in this space")); | ||
} | ||
let fetched = host.space_blob(&group, &space, repo, &cid).await; | ||
let (mime, bytes) = fetched.ok_or_else(|| not_found("no such file in this space"))?; | ||
let headers = [ | ||
crates/group-host/src/lexicons.rs+3−4
| @@ -67,9 +67,9 @@ pub const FILES: &[&str] = &[ | ||
lexicon!("fyi/opensocial/getGroupAuth"), | ||
lexicon!("fyi/opensocial/getJoinRequest"), | ||
lexicon!("fyi/opensocial/getLogs"), | ||
lexicon!("fyi/opensocial/getModSubjectHistory"), | ||
lexicon!("fyi/opensocial/getSpaceBlob"), | ||
lexicon!("fyi/opensocial/getStats"), | ||
lexicon!("fyi/opensocial/getSubjectHistory"), | ||
lexicon!("fyi/opensocial/getViewer"), | ||
lexicon!("fyi/opensocial/importAccount"), | ||
lexicon!("fyi/opensocial/importAccountSpace"), | ||
| @@ -83,9 +83,9 @@ pub const FILES: &[&str] = &[ | ||
lexicon!("fyi/opensocial/listInvites"), | ||
lexicon!("fyi/opensocial/listJoinRequests"), | ||
lexicon!("fyi/opensocial/listMembers"), | ||
lexicon!("fyi/opensocial/listModSubjects"), | ||
lexicon!("fyi/opensocial/listRecoveryKeys"), | ||
lexicon!("fyi/opensocial/listSpaceRecords"), | ||
lexicon!("fyi/opensocial/listSubjects"), | ||
lexicon!("fyi/opensocial/manageMembers"), | ||
lexicon!("fyi/opensocial/manageSpaces"), | ||
lexicon!("fyi/opensocial/members"), | ||
| @@ -105,7 +105,7 @@ pub const FILES: &[&str] = &[ | ||
lexicon!("fyi/opensocial/putSiteDomain"), | ||
lexicon!("fyi/opensocial/removeRecoveryKey"), | ||
lexicon!("fyi/opensocial/requestJoin"), | ||
lexicon!("fyi/opensocial/resolveSubject"), | ||
lexicon!("fyi/opensocial/resolveModSubject"), | ||
lexicon!("fyi/opensocial/revokeAppPassword"), | ||
lexicon!("fyi/opensocial/revokeConnectedApp"), | ||
lexicon!("fyi/opensocial/revokeGroupToken"), | ||
| @@ -122,7 +122,6 @@ pub const FILES: &[&str] = &[ | ||
lexicon!("upstream/com/atproto/identity/resolveHandle"), | ||
lexicon!("upstream/com/atproto/label/defs"), | ||
lexicon!("upstream/com/atproto/label/record"), | ||
lexicon!("upstream/com/atproto/moderation/defs"), | ||
lexicon!("upstream/com/atproto/repo/strongRef"), | ||
lexicon!("upstream/com/atproto/server/defs"), | ||
lexicon!("upstream/com/atproto/server/describeServer"), | ||
crates/group-host/src/lib.rs+7−6
| @@ -61,6 +61,7 @@ pub mod space; | ||
pub mod space_api; | ||
pub mod stats; | ||
pub mod store; | ||
pub mod takedown; | ||
pub mod time; | ||
pub mod token_writes; | ||
pub mod xrpc; | ||
| @@ -352,16 +353,16 @@ pub(crate) fn routes(host: Arc<Host>) -> Router { | ||
post(moderation::delete_label_definition), | ||
) | ||
.route( | ||
"/xrpc/fyi.opensocial.listSubjects", | ||
get(moderation::list_subjects), | ||
"/xrpc/fyi.opensocial.listModSubjects", | ||
get(moderation::list_mod_subjects), | ||
) | ||
.route( | ||
"/xrpc/fyi.opensocial.getSubjectHistory", | ||
get(moderation::get_subject_history), | ||
"/xrpc/fyi.opensocial.getModSubjectHistory", | ||
get(moderation::get_mod_subject_history), | ||
) | ||
.route( | ||
"/xrpc/fyi.opensocial.resolveSubject", | ||
post(moderation::resolve_subject), | ||
"/xrpc/fyi.opensocial.resolveModSubject", | ||
post(moderation::resolve_mod_subject), | ||
) | ||
.route( | ||
"/xrpc/fyi.opensocial.createReport", | ||
crates/group-host/src/moderation.rs+33−60
| @@ -13,7 +13,7 @@ | ||
//! of its spaces here, or a member's record in their public repo. | ||
| ||
use crate::Host; | ||
use crate::api::{Params, invalid, page, param}; | ||
use crate::api::{Params, invalid, invalid_cursor, page, param}; | ||
use crate::authority::Access; | ||
use crate::group::{members_space, meta_space}; | ||
use crate::group_api::{group_of, signed_in}; | ||
| @@ -34,11 +34,6 @@ use std::sync::Arc; | ||
| ||
type Answer = Result<Json<Value>, XrpcError>; | ||
| ||
/// An account, as a subject is sent and answered. | ||
const ACCOUNT: &str = "fyi.opensocial.defs#accountSubject"; | ||
/// A record, as a subject is sent and answered. | ||
const RECORD: &str = "fyi.opensocial.defs#recordSubject"; | ||
| ||
/// A subject in a group's queue: an account's DID, or a record's URI. | ||
#[derive(Debug, Clone, PartialEq)] | ||
pub struct Subject { | ||
| @@ -226,12 +221,8 @@ pub fn space_of(uri: &str) -> Option<(String, String)> { | ||
}) | ||
} | ||
| ||
/// The longest reason type a report gives: one of the known ones, or | ||
/// 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"; | ||
const APPEAL: &str = "appeal"; | ||
| ||
/// 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. | ||
| @@ -256,29 +247,22 @@ fn record_in(group: &str, uri: &str) -> Result<(), XrpcError> { | ||
Ok(()) | ||
} | ||
| ||
/// A subject as the queue keys it (an account's DID, or a record's URI in | ||
/// one of `group`'s spaces or in a public repo) and the version of a | ||
/// record it names, from the union a caller sends. | ||
fn subject_in(group: &str, asked: &Value) -> Result<(String, Option<String>), XrpcError> { | ||
let field = |key: &str| asked[key].as_str().map(String::from); | ||
match asked["$type"].as_str() { | ||
Some(ACCOUNT) => Ok((field("did").expect("its lexicon requires it"), None)), | ||
Some(RECORD) => { | ||
let uri = field("uri").expect("its lexicon requires it"); | ||
record_in(group, &uri)?; | ||
Ok((uri, field("cid"))) | ||
} | ||
_ => Err(invalid_subject("a subject is an account or a record")), | ||
/// Refuses a subject that is neither an account's DID nor a record's URI | ||
/// in one of `group`'s spaces or in a public repo. | ||
fn subject_of(group: &str, subject: &str) -> Result<(), XrpcError> { | ||
match syntax::is_did(subject) { | ||
true => Ok(()), | ||
false => record_in(group, subject), | ||
} | ||
} | ||
| ||
/// A subject as the queue keys it, answered as the union it was sent as. | ||
fn subject_ref(key: &str) -> Value { | ||
if key.starts_with("at://") { | ||
json!({"$type": RECORD, "uri": key}) | ||
} else { | ||
json!({"$type": ACCOUNT, "did": key}) | ||
} | ||
/// A subject as the queue keys it, from the `subject` a caller sends, and | ||
/// the version of a record it names in `cid`: an account has none. | ||
fn subject_in(group: &str, asked: &Value) -> Result<(String, Option<String>), XrpcError> { | ||
let subject = asked["subject"].as_str().expect("its lexicon requires it"); | ||
subject_of(group, subject)?; | ||
let cid = asked["cid"].as_str().filter(|_| !syntax::is_did(subject)); | ||
Ok((subject.to_string(), cid.map(String::from))) | ||
} | ||
| ||
impl Host { | ||
| @@ -417,11 +401,11 @@ fn account_of(key: &str) -> &str { | ||
if parts.len() == 3 { parts[0] } else { parts[4] } | ||
} | ||
| ||
/// A subject as the queue answers it, with `actors`, the people it names | ||
/// as a view names them. | ||
/// A subject as the queue answers it (`defs#modSubjectView`), with | ||
/// `actors`, the people it names as a view names them. | ||
fn subject_view(s: &Subject, actors: &HashMap<String, Value>) -> Value { | ||
json!({ | ||
"subject": subject_ref(&s.subject), | ||
"subject": s.subject, | ||
"actor": actors[account_of(&s.subject)], | ||
"status": s.status, | ||
"reportCount": s.reports, | ||
| @@ -466,13 +450,13 @@ fn event_view(e: &Event, actors: &HashMap<String, Value>) -> Value { | ||
| ||
/// The group's queue, of a status (`open` unless asked), the latest | ||
/// changed first. | ||
pub async fn list_subjects( | ||
pub async fn list_mod_subjects( | ||
State(host): State<Arc<Host>>, | ||
Query(p): Query<Params>, | ||
headers: HeaderMap, | ||
) -> Answer { | ||
let group = param(&p, "group")?; | ||
host.moderator(&headers, "listSubjects", group, "mod.read") | ||
host.moderator(&headers, "listModSubjects", group, "mod.read") | ||
.await?; | ||
let limit = page(&p, 50, 100)?; | ||
let cursor = p | ||
| @@ -480,11 +464,10 @@ pub async fn list_subjects( | ||
.map(|c| c.split_once(':').unwrap_or((c, ""))); | ||
let before = match cursor { | ||
None => None, | ||
Some((at, subject)) => Some(( | ||
at.parse::<i64>() | ||
.map_err(|_| invalid("a cursor this host gave"))?, | ||
subject, | ||
)), | ||
Some((at, subject)) => { | ||
let at = at.parse::<i64>().map_err(|_| invalid_cursor())?; | ||
Some((at, subject)) | ||
} | ||
}; | ||
let status = p.get("status").map_or("open", String::as_str); | ||
let subjects = host | ||
| @@ -505,24 +488,20 @@ pub async fn list_subjects( | ||
| ||
/// What happened to a subject in the group's queue, oldest first, a page | ||
/// at a time. | ||
pub async fn get_subject_history( | ||
pub async fn get_mod_subject_history( | ||
State(host): State<Arc<Host>>, | ||
Query(p): Query<Params>, | ||
headers: HeaderMap, | ||
) -> Answer { | ||
let group = param(&p, "group")?; | ||
host.moderator(&headers, "getSubjectHistory", group, "mod.read") | ||
host.moderator(&headers, "getModSubjectHistory", group, "mod.read") | ||
.await?; | ||
let subject = param(&p, "subject")?; | ||
if !syntax::is_did(subject) { | ||
record_in(group, subject)?; | ||
} | ||
subject_of(group, subject)?; | ||
let limit = page(&p, 50, 100)?; | ||
let after = match p.get("cursor") { | ||
None => 0, | ||
Some(c) => c | ||
.parse::<i64>() | ||
.map_err(|_| invalid("a cursor this host gave"))?, | ||
Some(c) => c.parse::<i64>().map_err(|_| invalid_cursor())?, | ||
}; | ||
let cid = p.get("cid").map(String::as_str); | ||
let events = host | ||
| @@ -543,16 +522,16 @@ pub async fn get_subject_history( | ||
| ||
/// Resolves or escalates a subject, with a note if one is given; setting | ||
/// the status it has keeps the note. | ||
pub async fn resolve_subject( | ||
pub async fn resolve_mod_subject( | ||
State(host): State<Arc<Host>>, | ||
headers: HeaderMap, | ||
Json(body): Json<Value>, | ||
) -> Answer { | ||
let group = body["group"].as_str().expect("its lexicon requires it"); | ||
let me = host | ||
.moderator(&headers, "resolveSubject", group, "mod.resolve") | ||
.moderator(&headers, "resolveModSubject", group, "mod.resolve") | ||
.await?; | ||
let (subject, cid) = subject_in(group, &body["subject"])?; | ||
let (subject, cid) = subject_in(group, &body)?; | ||
let status = body["status"].as_str().expect("its lexicon requires it"); | ||
let found = host.store.subject(group, &subject); | ||
if found.map_err(XrpcError::internal)?.is_none() { | ||
| @@ -600,20 +579,14 @@ pub async fn create_report( | ||
let reason_type = body["reasonType"] | ||
.as_str() | ||
.expect("its lexicon requires it"); | ||
if reason_type.len() > REASON_TYPE_MAX { | ||
return Err(invalid(format!( | ||
"reasonType is {REASON_TYPE_MAX} bytes at most" | ||
))); | ||
} | ||
// A rule is cited by its URI, a record's in the group's meta space. | ||
let rule = body["rule"].as_str(); | ||
let meta = meta_space(group); | ||
if rule.is_some_and(|r| space_of(r).is_none_or(|(space, _)| space != meta)) { | ||
return Err(invalid("rule is a rule in the group's meta space")); | ||
} | ||
let (subject, cid) = subject_in(group, &body["subject"])?; | ||
let labeler = host.group_record(group, &meta, &format!("{NS}.labeler"), "self"); | ||
let labeler = labeler.map_err(XrpcError::internal)?.unwrap_or_default(); | ||
let (subject, cid) = subject_in(group, &body)?; | ||
let labeler = host.labeler_of(group)?; | ||
if !accepts(&labeler, "reasonTypes", reason_type) { | ||
return Err(invalid(format!( | ||
"the group takes no reports of {reason_type}" | ||
crates/group-host/src/rbac.rs+4−4
| @@ -179,8 +179,8 @@ fn query_of(scope: &str, name: &str) -> Vec<String> { | ||
| ||
/// The actions a host method's `rpc:` scope grants, by method. | ||
const BY_METHOD: [(&str, &str); 2] = [ | ||
("listSubjects", "mod.read"), | ||
("resolveSubject", "mod.resolve"), | ||
("listModSubjects", "mod.read"), | ||
("resolveModSubject", "mod.resolve"), | ||
]; | ||
| ||
/// The scope that grants each action. | ||
| @@ -198,8 +198,8 @@ pub fn scope_of(action: &str) -> Option<String> { | ||
"role.assign" => membership("update"), | ||
"eject" => membership("delete"), | ||
"invite" => format!("space:{NS}.invites?authority=*&collection={NS}.invite"), | ||
"mod.read" => rpc("listSubjects"), | ||
"mod.resolve" => rpc("resolveSubject"), | ||
"mod.read" => rpc("listModSubjects"), | ||
"mod.resolve" => rpc("resolveModSubject"), | ||
"label" => format!("space:*?collection={LABEL}"), | ||
_ => return None, | ||
}) | ||
crates/group-host/src/takedown.rsnew+108−0
| @@ -0,0 +1,108 @@ | ||
//! Takedowns: a `!takedown` label the group writes takes what it labels | ||
//! out of the group's spaces as the host serves them, from its index | ||
//! (`listSpaceRecords`) and the files there (`getSpaceBlob`), as the | ||
//! spaces convention has a space's authority take content down. | ||
//! | ||
//! A takedown of a record, written in the space the record is in, takes | ||
//! that record out (only the version it names, if it names one) and the | ||
//! files it holds. A takedown of an account takes out all the account | ||
//! wrote in the space it is written in; written in the members space, | ||
//! where an account's labels go, in every space of the group. Deleting | ||
//! the label, or its lapsing (`exp`), puts it all back. Only the group's | ||
//! own labels count: one anyone else writes takes nothing down. What is | ||
//! taken down stays in its writer's repo; the host only stops serving it. | ||
| ||
use crate::Host; | ||
use crate::blobs::blob_refs; | ||
use crate::group::members_space; | ||
use crate::group_invites::millis_of; | ||
use crate::rbac::LABEL; | ||
use crate::time::now_millis; | ||
use anyhow::Result; | ||
use atproto::{Cid, drisl, syntax}; | ||
use std::collections::HashSet; | ||
| ||
/// The label that takes content down. | ||
pub const TAKEDOWN: &str = "!takedown"; | ||
| ||
/// What the group's takedowns take out of one of its spaces. | ||
#[derive(Debug, Default)] | ||
pub struct TakenDown { | ||
/// Records, by URI, each with the version taken down if only one is. | ||
records: Vec<(String, Option<String>)>, | ||
/// Accounts everything of whose is. | ||
accounts: HashSet<String>, | ||
} | ||
| ||
impl TakenDown { | ||
/// Whether the record at `uri`, `repo`'s, as it is at `cid`, is taken | ||
/// down. | ||
pub fn hides(&self, uri: &str, repo: &str, cid: &str) -> bool { | ||
let named = |(at, version): &(String, Option<String>)| { | ||
at == uri && version.as_deref().is_none_or(|v| v == cid) | ||
}; | ||
self.accounts.contains(repo) || self.records.iter().any(named) | ||
} | ||
} | ||
| ||
impl Host { | ||
/// What the group's takedowns take out of `space`, one of `group`'s: | ||
/// its `!takedown` labels there, and those on accounts in the members | ||
/// space, each still in force. | ||
pub fn taken_down(&self, group: &str, space: &str) -> Result<TakenDown> { | ||
let here = self.group_records(group, space, LABEL)?; | ||
let members = members_space(group); | ||
let everywhere = match space == members { | ||
true => Vec::new(), | ||
false => self.group_records(group, &members, LABEL)?, | ||
}; | ||
let now = now_millis(); | ||
let lapsed = |exp: Option<&str>| exp.and_then(millis_of).is_some_and(|at| at <= now); | ||
let labels = here.iter().chain(&everywhere).map(|(_, label)| label); | ||
let mut down = TakenDown::default(); | ||
for label in labels.filter(|l| l["val"] == TAKEDOWN && !lapsed(l["exp"].as_str())) { | ||
let uri = label["uri"].as_str().unwrap_or_default().to_string(); | ||
// An account's label in the members space covers every space; | ||
// a record's covers only records in its own. | ||
if syntax::is_did(&uri) { | ||
down.accounts.insert(uri); | ||
} else { | ||
down.records | ||
.push((uri, label["cid"].as_str().map(String::from))); | ||
} | ||
} | ||
Ok(down) | ||
} | ||
| ||
/// Whether `down` takes `repo`'s file `cid` out of `space`: everything | ||
/// of theirs is taken down there, or a record of theirs taken down, as | ||
/// the index holds it, holds the file. | ||
pub fn file_taken_down( | ||
&self, | ||
down: &TakenDown, | ||
space: &str, | ||
repo: &str, | ||
cid: &Cid, | ||
) -> Result<bool> { | ||
if down.accounts.contains(repo) { | ||
return Ok(true); | ||
} | ||
let theirs = format!("{space}/{repo}/"); | ||
let paths = down | ||
.records | ||
.iter() | ||
.filter_map(|(uri, _)| Some((uri, uri.strip_prefix(&theirs)?))); | ||
for (uri, path) in paths { | ||
let found = self.store.indexed_one(space, repo, path)?; | ||
let holds = found.is_some_and(|r| { | ||
let value = drisl::decode(&r.value).expect("a record the host indexed"); | ||
down.hides(uri, repo, &r.cid.to_string()) | ||
&& blob_refs(&value.to_json()).contains(cid) | ||
}); | ||
if holds { | ||
return Ok(true); | ||
} | ||
} | ||
Ok(false) | ||
} | ||
} | ||
crates/group-host/tests/authorization.rs+1−1
| @@ -324,7 +324,7 @@ async fn gives_each_permission_set_as_the_scopes_it_lists() { | ||
assert!(!scope.contains("include:"), "{scope}"); | ||
assert!(scope.contains(&format!("space:fyi.opensocial.meta?authority={riders}&skey=self&collection=fyi.opensocial.profile")), "{scope}"); | ||
assert!( | ||
scope.contains("rpc:fyi.opensocial.listSubjects?aud=*"), | ||
scope.contains("rpc:fyi.opensocial.listModSubjects?aud=*"), | ||
"{scope}" | ||
); | ||
} | ||
crates/group-host/tests/joining.rs+1−1
crates/group-host/tests/moderation.rs+272−116
crates/group-host/tests/oauth_scope.rs+4−4
crates/group-host/tests/provision.rs+2−2
crates/group-host/tests/rbac.rs+12−0
crates/group-host-mcp/src/lib.rs+7−41
crates/group-host-mcp/tests/protocol.rs+7−19
crates/opensocial/src/lib.rs+2−2
crates/opensocial/tests/commands.rs+2−2
docs/design/moderation.md+29−18
docs/guides/shots/moderating-found-dark.png+0−0
A binary file, not shown.
docs/guides/shots/moderating-found.png+0−0
A binary file, not shown.
docs/guides/shots/moderating-found.txt+1−1
docs/guides/shots/moderating-label-dialog-dark.png+0−0
A binary file, not shown.
docs/guides/shots/moderating-label-dialog.png+0−0
A binary file, not shown.