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

Labels are the proposal's com.atproto.label.label, written as the group

Merged chadtmiller.com asked to merge into main from chadtmiller.com/group-host:moderation/label-record
crates/group-host/src/group_tokens.rs+16−4
@@ -18,9 +18,10 @@ use crate::group_api::{group_of, signed_in};
use crate::group_invites::{inviting_scope, is_inbox};
use crate::member_writes::own_scopes;
use crate::oauth_resource::Refusal;
use crate::oauth_scope::writes_in;
use crate::oauth_scope::WRITES;
use crate::oauth_scope::{labels_in, may_write, with_labels, writes_in};
use crate::oauth_store::{Grant, Tokens};
use crate::rbac::{Access, NS};
use crate::rbac::{Access, LABEL, NS};
use crate::time::{iso, now_millis};
use crate::xrpc::XrpcError;
use atproto::jose;
@@ -152,11 +153,22 @@ impl Host {
let access = self.group_record(group, uri, &format!("{NS}.access"), "self");
let access = access.map_err(XrpcError::internal)?.unwrap_or_default();
let everything = self.may_issue(group, member)?;
let writes = writes_in(&Access::of(&access, uri), &roles, member, everything);
let own = match uri == members_space(group) {
let access = Access::of(&access, uri);
let writes = writes_in(&access, &roles, member, everything);
let mut own = match uri == members_space(group) {
true => self.members_writes_of(group, &roles)?,
false => BTreeMap::new(),
};
// Labels, unless what the space grants holds them already.
let labels = labels_in(
&access,
&roles,
member,
self.may_do(group, member, "label")?,
);
if !WRITES.iter().all(|w| may_write(&writes, LABEL, w)) {
with_labels(&mut own, labels);
}
if writes.is_empty() && own.is_empty() {
let none = "no role of yours may act as the group in this space";
return Err(forbidden(none));
crates/group-host/src/lexicons.rs+7−8
@@ -34,7 +34,6 @@ pub const FILES: &[&str] = &[
lexicon!("fyi/opensocial/access"),
lexicon!("fyi/opensocial/activateGroup"),
lexicon!("fyi/opensocial/addRecoveryKey"),
lexicon!("fyi/opensocial/applyLabel"),
lexicon!("fyi/opensocial/approveAuthorization"),
lexicon!("fyi/opensocial/cancelAccountMove"),
lexicon!("fyi/opensocial/cancelJoinRequest"),
@@ -75,7 +74,6 @@ pub const FILES: &[&str] = &[
lexicon!("fyi/opensocial/importAccountSpace"),
lexicon!("fyi/opensocial/invite"),
lexicon!("fyi/opensocial/invites"),
lexicon!("fyi/opensocial/label"),
lexicon!("fyi/opensocial/labeler"),
lexicon!("fyi/opensocial/leaveGroup"),
lexicon!("fyi/opensocial/listAppPasswords"),
@@ -98,7 +96,6 @@ pub const FILES: &[&str] = &[
lexicon!("fyi/opensocial/migratePrepare"),
lexicon!("fyi/opensocial/migrateReceive"),
lexicon!("fyi/opensocial/moderate"),
lexicon!("fyi/opensocial/negateLabel"),
lexicon!("fyi/opensocial/participate"),
lexicon!("fyi/opensocial/permissions"),
lexicon!("fyi/opensocial/profile"),
@@ -122,6 +119,7 @@ pub const FILES: &[&str] = &[
lexicon!("upstream/com/atproto/admin/defs"),
lexicon!("upstream/com/atproto/identity/resolveHandle"),
lexicon!("upstream/com/atproto/label/defs"),
lexicon!("upstream/com/atproto/label/label"),
lexicon!("upstream/com/atproto/managedspace/checkUserAccess"),
lexicon!("upstream/com/atproto/managedspace/policy"),
lexicon!("upstream/com/atproto/moderation/defs"),
@@ -204,18 +202,19 @@ pub async fn check(State(host): State<Arc<Host>>, request: Request, next: Next)
}
/// What `validationStatus` says of a record of `collection`: `valid` for
/// one of our own collections, which [`check_record`] checks against its
/// lexicon before it is kept, `unknown` for any other.
/// one of our own collections, or a label, which [`check_record`] checks
/// against its lexicon before it is kept, `unknown` for any other.
pub fn validation(collection: &str) -> &'static str {
let ours = collection.starts_with("fyi.opensocial.");
let ours = collection.starts_with("fyi.opensocial.") || collection == crate::rbac::LABEL;
match lexicons().def(collection) {
Some(def) if ours && def["type"] == "record" => "valid",
_ => "unknown",
}
}
/// Refuses a record of one of our own collections that is not what its
/// lexicon describes; a record of any other collection passes unread.
/// Refuses a record of one of our own collections, or a label, that is
/// not what its lexicon describes; a record of any other collection
/// passes unread.
pub fn check_record(collection: &str, record: &Value) -> Result<(), XrpcError> {
if validation(collection) == "unknown" {
return Ok(());
crates/group-host/src/lib.rs+0−8
@@ -363,14 +363,6 @@ pub(crate) fn routes(host: Arc<Host>) -> Router {
"/xrpc/fyi.opensocial.getActorGroups",
get(actors::get_actor_groups),
)
.route(
"/xrpc/fyi.opensocial.applyLabel",
post(moderation::apply_label),
)
.route(
"/xrpc/fyi.opensocial.negateLabel",
post(moderation::negate_label),
)
.route(
"/xrpc/fyi.opensocial.putLabelDefinition",
post(moderation::put_label_definition),
crates/group-host/src/mcp.rs+58−10
@@ -20,7 +20,7 @@
//! can do nothing there, and its grants end.
use crate::Host;
use crate::api::{Params, param};
use crate::api::{Params, invalid, param};
use crate::group_api::{group_of, signed_in};
use crate::oauth_resource::Acting;
use crate::oauth_store::Grant;
@@ -700,21 +700,20 @@ fn query_of(args: &Value) -> Vec<(String, String)> {
impl Host {
/// Writes a record of `who`'s group as the group, as `Plan::Write`
/// says: `record` at `rkey`, or at a new key, or with none deletes the
/// one at `rkey`, in its space of the type `space`. What a group
/// session `who`'s member approved for that space would write, its
/// scope what their roles there grant now, kept to the same rules.
/// one at `rkey`, in its space at `uri`. What a group session `who`'s
/// member approved for that space would write, its scope what their
/// roles there grant now, kept to the same rules.
async fn record_as(
&self,
who: &McpGrant,
space: &str,
uri: &str,
collection: String,
rkey: Option<String>,
record: Option<Value>,
) -> Result<Value, XrpcError> {
let group = &who.group;
let uri = format!("at://{group}/space/{space}/self");
let space = SpaceRef::parse(&uri).expect("a group's own space is a space");
let (_, _, scope) = self.group_scope(group, &who.member, &uri, &space)?;
let space = SpaceRef::parse(uri).map_err(|e| invalid(e.to_string()))?;
let (_, _, scope) = self.group_scope(group, &who.member, uri, &space)?;
let now = now_millis();
let grant = Grant {
id: who.id.clone(),
@@ -744,7 +743,7 @@ impl Host {
},
};
let writes = std::slice::from_ref(&write);
let written = self.write_as(&acting, &uri, &space, writes, true);
let written = self.write_as(&acting, uri, &space, writes, true);
written.await?;
let (collection, rkey) = write.path();
let mut out = json!({"uri": format!("{uri}/{group}/{collection}/{rkey}")});
@@ -754,6 +753,45 @@ impl Host {
Ok(out)
}
/// Labels `subject` with `val` as `who`'s group, beside it, as
/// `Plan::Label` says; with `undo`, deletes each label of that value
/// on it there.
async fn label_as(
&self,
who: &McpGrant,
subject: &str,
cid: Option<&str>,
val: &str,
undo: bool,
) -> Result<Value, XrpcError> {
let group = &who.group;
let space = group_host_mcp::label_space(group, subject);
let space = space.ok_or_else(|| {
invalid("subject is an account's DID, or a record's URI in one of the group's spaces")
})?;
let collection = || group_host_mcp::LABEL.to_string();
if !undo {
let record = group_host_mcp::label_record(subject, cid, val, &iso(now_millis()));
return self
.record_as(who, &space, collection(), None, Some(record))
.await;
}
let kept = self.group_records(group, &space, group_host_mcp::LABEL);
let kept = kept.map_err(XrpcError::internal)?;
let mut uris = Vec::new();
for (rkey, _) in kept
.iter()
.filter(|(_, r)| group_host_mcp::labels(r, subject, val))
{
let gone = self.record_as(who, &space, collection(), Some(rkey.clone()), None);
uris.push(gone.await?["uri"].clone());
}
if uris.is_empty() {
return Err(invalid(format!("no {val} label on {subject} to take back")));
}
Ok(json!({ "uris": uris }))
}
/// Carries out `plan` as `who`, in their group: a method asked as the
/// console asks it, a record written as their own session for the
/// group would.
@@ -774,9 +812,19 @@ impl Host {
rkey,
record,
} => {
let written = self.record_as(who, &space, collection, rkey, record);
let uri = format!("at://{}/space/{space}/self", who.group);
let written = self.record_as(who, &uri, collection, rkey, record);
written.await.map_err(said)
}
Plan::Label {
subject,
cid,
val,
undo,
} => {
let labelled = self.label_as(who, &subject, cid.as_deref(), &val, undo);
labelled.await.map_err(said)
}
Plan::Invite { person, record } => {
let written = self.invite_as(who, &person, record).await;
written.map_err(said)
crates/group-host/src/member_writes.rs+3−2
@@ -328,7 +328,8 @@ impl Host {
roles,
grants,
};
for w in writes {
// A label is held to the rules of every space (`moderation`).
for w in writes.iter().filter(|w| kind(w).is_some()) {
let (_, rkey) = w.path();
match (kind(w), w) {
(Some("role"), Write::Delete { .. }) => {
@@ -358,7 +359,7 @@ impl Host {
book.grants = now;
}
// The rest are memberships: the members space takes no other
// record (`guard`).
// record of ours (`guard`).
(_, Write::Delete { .. }) => {
let (_, theirs) = book.members.remove(rkey).unwrap_or_default();
writer.may_give(&theirs, "eject")?;
crates/group-host/src/moderation.rs+82−111
@@ -1,10 +1,10 @@
//! Moderation, a group's own: reports in, labels out, a queue between.
//!
//! - **Labels** are records the group writes into the space its subject
//! lives in, so whoever reads the content reads its labels. An account
//! has no content to sit beside: its labels go in the members space. A
//! label is taken back by a second record that negates it, not by
//! deleting the first: that it was applied is part of the record.
//! - **Labels** are `com.atproto.label.label` records the group writes,
//! as any record of its own, beside their subject: a record's in the
//! space it is in, an account's in the members space by custom. Whoever
//! reads the content reads its labels. Deleting a label takes it back;
//! the queue keeps that it was written, and by whom.
//! - **The queue** (subjects, their status, what happened to each) is the
//! host's to keep, not the group's to publish.
//! - **Reports** come through `fyi.opensocial.createReport`, from whoever
@@ -16,13 +16,13 @@ use crate::api::{Params, invalid, page, param};
use crate::authority::Access;
use crate::group::{members_space, meta_space};
use crate::group_api::{group_of, signed_in};
use crate::rbac::NS;
use crate::repo::{Write, record_cid};
use crate::rbac::{LABEL, NS};
use crate::repo::Write;
use crate::store::Store;
use crate::time::{iso, now_millis};
use crate::xrpc::XrpcError;
use anyhow::Result;
use atproto::{Cid, syntax};
use atproto::syntax;
use axum::Json;
use axum::extract::{Query, State};
use axum::http::{HeaderMap, StatusCode};
@@ -33,9 +33,6 @@ use std::sync::Arc;
type Answer = Result<Json<Value>, XrpcError>;
/// The values that remove content, for a role holding `takedown`.
const TAKEDOWN_VALS: [&str; 2] = ["!hide", "!takedown"];
/// 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.
@@ -52,7 +49,7 @@ pub struct Subject {
}
/// Something that happened to a subject: a `report`, a `status` set, a
/// `label` or its negation (`negate`), or an `eject`ion.
/// `label` written or taken back (`negate`), or an `eject`ion.
#[derive(Debug, Clone, Default, PartialEq)]
pub struct Event {
/// Its place in the host's history, once kept.
@@ -264,30 +261,24 @@ fn subject_ref(key: &str) -> Value {
}
}
/// A label's subject, as the label record holds it, and as the queue keys
/// it: an account's DID, or a record's URI.
fn subject_of(asked: &Value) -> Result<(Value, String), XrpcError> {
if let Some(did) = asked["did"].as_str() {
if !syntax::is_did(did) {
return Err(invalid("subject.did is not a DID"));
/// Refuses a label among `writes` in `space` whose subject is neither an
/// account nor a record in that same space: a label sits beside what it
/// is about, so exactly those who read the one read the other.
pub(crate) fn beside(space: &str, writes: &[Write]) -> Result<(), XrpcError> {
for write in writes {
let (collection, _) = write.path();
let Some(value) = write.value().filter(|_| collection == LABEL) else {
continue;
};
let subject = value["uri"].as_str().unwrap_or_default();
let here = space_of(subject).is_some_and(|(s, _)| s == space);
if !here && !syntax::is_did(subject) {
return Err(invalid(
"a label's uri is an account's DID, or a record's in the space it is written in",
));
}
return Ok((
json!({"$type": "com.atproto.admin.defs#repoRef", "did": did}),
did.to_string(),
));
}
let (Some(uri), Some(cid)) = (asked["uri"].as_str(), asked["cid"].as_str()) else {
return Err(invalid(
"a subject is an account's did, or a record's uri and cid",
));
};
if Cid::parse(cid).is_err() {
return Err(invalid("subject.cid is not a CID"));
}
Ok((
json!({"$type": "com.atproto.repo.strongRef", "uri": uri, "cid": cid}),
uri.to_string(),
))
Ok(())
}
impl Host {
@@ -307,87 +298,67 @@ impl Host {
Ok(me)
}
/// Writes a label (or its negation) on `subject` as `group`, in the
/// space it lives in, and notes it in the queue.
async fn label(&self, headers: &HeaderMap, lxm: &str, body: &Value, neg: bool) -> Answer {
let group = body["group"].as_str().expect("its lexicon requires it");
let val = body["val"].as_str().filter(|v| !v.is_empty());
let val = val.ok_or_else(|| invalid("val is required"))?;
// A rule is cited by its URI, a record's in the group's meta.
let rule = body["rule"].as_str();
if rule.is_some_and(|r| space_of(r).is_none()) {
return Err(invalid("rule is the URI of a rule"));
}
let action = if TAKEDOWN_VALS.contains(&val) {
"takedown"
} else {
"label"
};
let me = self.moderator(headers, lxm, group, action).await?;
let (subject, key) = subject_of(&body["subject"])?;
let space = match subject["uri"].as_str() {
None => members_space(group),
Some(uri) => {
let space = space_of(uri);
let space = space.ok_or_else(|| {
invalid("a record subject is one in a space, for its label to sit beside it")
})?;
// Another group's content is that group's to moderate.
if space.1 != group {
return Err(forbidden("subject is not in this group's spaces"));
}
space.0
/// The labels among `writes` that delete one, as they are before the
/// writes are made in `space`, by key: what a deletion takes back.
pub(crate) fn labels_going(
&self,
group: &str,
space: &str,
writes: &[Write],
) -> Result<Vec<(String, Value)>, XrpcError> {
let mut out = Vec::new();
for write in writes {
let (collection, rkey) = write.path();
if collection != LABEL || !matches!(write, Write::Delete { .. }) {
continue;
}
let found = self.group_record(group, space, LABEL, rkey);
if let Some(label) = found.map_err(XrpcError::internal)? {
out.push((rkey.to_string(), label));
}
};
let collection = format!("{NS}.label");
let mut value = json!({"$type": collection, "subject": subject, "val": val, "createdAt": iso(now_millis())});
if neg {
value["neg"] = json!(true);
}
if let Some(rule) = rule {
value["rule"] = json!(rule);
}
let rkey = self.clock.next();
let cid = record_cid(&collection, &value)?;
let write = Write::Create {
collection: collection.clone(),
rkey: rkey.clone(),
value,
};
self.space_write(group, &space, &[write]).await?;
let uri = format!("{space}/{group}/{collection}/{rkey}");
let event = Event {
kind: if neg { "negate" } else { "label" }.into(),
actor: Some(me),
cid: subject["cid"].as_str().map(String::from),
val: Some(val.into()),
uri: Some(uri.clone()),
created_at: now_millis(),
..Event::default()
};
self.store
.moderate(group, &key, &event)
.map_err(XrpcError::internal)?;
Ok(Json(json!({"uri": uri, "cid": cid.to_string()})))
Ok(out)
}
}
/// Labels a subject in one of the group's spaces, or an account.
pub async fn apply_label(
State(host): State<Arc<Host>>,
headers: HeaderMap,
Json(body): Json<Value>,
) -> Answer {
host.label(&headers, "applyLabel", &body, false).await
}
/// Negates a label, with a second record.
pub async fn negate_label(
State(host): State<Arc<Host>>,
headers: HeaderMap,
Json(body): Json<Value>,
) -> Answer {
host.label(&headers, "negateLabel", &body, true).await
/// Notes each label among `made` in `group`'s queue, as `member` wrote
/// it in `space`: a label written, or one taken back by deleting it,
/// as `going` had it.
pub(crate) fn labelled(
&self,
group: &str,
space: &str,
member: &str,
made: &[Write],
going: &[(String, Value)],
) -> Result<(), XrpcError> {
// A deletion is of a label there: one where there is none is left
// out of what is made.
let labels = made.iter().filter(|w| w.path().0 == LABEL).filter_map(|w| {
let gone = going.iter().find(|(k, _)| k == w.path().1);
Some((w, w.value().or(gone.map(|(_, l)| l))?))
});
for (write, label) in labels {
let kind = match write {
Write::Delete { .. } => "negate",
_ => "label",
};
let rkey = write.path().1;
let text = |key: &str| label[key].as_str().map(String::from);
let event = Event {
kind: kind.into(),
actor: Some(member.into()),
cid: text("cid"),
val: text("val"),
uri: Some(format!("{space}/{group}/{LABEL}/{rkey}")),
created_at: now_millis(),
..Event::default()
};
let subject = text("uri").unwrap_or_default();
let kept = self.store.moderate(group, &subject, &event);
kept.map_err(XrpcError::internal)?;
}
Ok(())
}
}
/// `value`, an object, without the fields it has no value for.
crates/group-host/src/oauth_scope.rs+21−3
@@ -12,7 +12,7 @@
use crate::Host;
use crate::group::members_space;
use crate::lexicons::lexicons;
use crate::rbac::{self, Access, NS, actions_for, grants, repo_collections_for};
use crate::rbac::{self, Access, LABEL, NS, actions_for, grants, repo_collections_for};
use crate::scopes::{decoded, is_blob, repo_collections};
use crate::xrpc::XrpcError;
use atproto::space::SpaceRef;
@@ -122,6 +122,21 @@ pub fn writes_in(
}
}
/// Whether a holder of `roles`, `member`, labelling (`labels`), writes
/// labels as the group in a space of `access`: in any of the group's
/// spaces, but one for chosen people only as one of them.
pub fn labels_in(access: &Access, roles: &[String], member: &str, labels: bool) -> bool {
labels && (access.people.is_none() || access.can_read(roles, member))
}
/// `writable` with labels, if `labels` and it does not hold every write
/// of them already.
pub fn with_labels(writable: &mut BTreeMap<String, BTreeSet<String>>, labels: bool) {
if labels && !WRITES.iter().all(|w| may_write(writable, LABEL, w)) {
writable.insert(LABEL.into(), WRITES.map(String::from).into());
}
}
/// Whether those writes include `action` on `collection`.
pub(crate) fn may_write(
writes: &BTreeMap<String, BTreeSet<String>>,
@@ -157,6 +172,7 @@ impl Host {
roles: &[String],
member: &str,
everything: bool,
labels: bool,
) -> Result<Vec<Room>, XrpcError> {
let entries = self
.group_records(group, &members_space(group), &format!("{NS}.space"))
@@ -177,6 +193,7 @@ impl Host {
if uri == members_space(group) {
writable.extend(self.members_writes_of(group, roles)?);
}
with_labels(&mut writable, labels_in(&access, roles, member, labels));
rooms.push(Room {
kind: space.kind,
skey: space.skey,
@@ -200,7 +217,8 @@ impl Host {
if !repo.is_empty() || actions_for(grants, roles).contains("group.configure") {
return Ok(true);
}
let rooms = self.rooms(group, roles, member, false)?;
let labels = actions_for(grants, roles).contains("label");
let rooms = self.rooms(group, roles, member, false, labels)?;
Ok(rooms.iter().any(|r| !r.writable.is_empty()))
}
@@ -243,7 +261,7 @@ impl Host {
let repo = repo_collections_for(&grants, roles);
let everything = repo.contains("*");
let held = actions_for(&grants, roles);
let rooms = self.rooms(group, roles, member, everything)?;
let rooms = self.rooms(group, roles, member, everything, held.contains("label"))?;
let invite = format!("{NS}.invite");
let (mut kept, mut made) = (Vec::new(), Vec::new());
for s in requested {
crates/group-host/src/rbac.rs+6−8
@@ -14,15 +14,16 @@ use serde_json::Value;
use std::collections::{BTreeMap, BTreeSet};
pub const NS: &str = "fyi.opensocial";
/// A label, as a record the group writes beside its subject.
pub const LABEL: &str = "com.atproto.label.label";
/// Anyone signed in, as an audience.
pub const PUBLIC: &str = "public";
/// The actions the host's methods ask about.
pub const ACTIONS: [&str; 12] = [
pub const ACTIONS: [&str; 11] = [
"mod.read",
"mod.resolve",
"label",
"takedown",
"invite",
"admit",
"eject",
@@ -177,10 +178,9 @@ 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); 3] = [
const BY_METHOD: [(&str, &str); 2] = [
("listSubjects", "mod.read"),
("resolveSubject", "mod.resolve"),
("applyLabel", "label"),
];
/// The scope that grants each action.
@@ -200,8 +200,7 @@ pub fn scope_of(action: &str) -> Option<String> {
"invite" => format!("space:{NS}.invites?authority=*&collection={NS}.invite"),
"mod.read" => rpc("listSubjects"),
"mod.resolve" => rpc("resolveSubject"),
"label" => rpc("applyLabel"),
"takedown" => format!("space:*?collection={NS}.label"),
"label" => format!("space:*?collection={LABEL}"),
_ => return None,
})
}
@@ -286,9 +285,8 @@ pub fn actions_of(scopes: &[String]) -> BTreeSet<&'static str> {
if every || collections.contains(&format!("{NS}.access").as_str()) {
out.insert("space.configure");
}
if every || collections.contains(&format!("{NS}.label").as_str()) {
if every || collections.contains(&LABEL) {
out.insert("label");
out.insert("takedown");
}
}
}
crates/group-host/src/token_writes.rs+14−6
@@ -21,9 +21,10 @@ use crate::group::{members_space, meta_space};
use crate::group_invites::is_inbox;
use crate::lexicons::{check_record, validation};
use crate::member_writes::members_writes;
use crate::moderation;
use crate::oauth_resource::{Acting, Refusal};
use crate::oauth_scope::{may_write, writes_in};
use crate::rbac::{self, Access, NS, actions_for, grants, repo_collections_for};
use crate::oauth_scope::{labels_in, may_write, writes_in};
use crate::rbac::{self, Access, LABEL, NS, actions_for, grants, repo_collections_for};
use crate::repo::{Asked, Write, record_cid};
use crate::xrpc::XrpcError;
use atproto::space::SpaceRef;
@@ -89,10 +90,11 @@ impl Host {
/// host would not make itself, and to any space's access record.
fn guard(&self, group: &str, space: &str, writes: &[Write]) -> Result<(), XrpcError> {
let c = |name: &str| format!("{NS}.{name}");
let label = LABEL.to_string();
let allowed = if space == meta_space(group) {
Some([c("profile"), c("rule"), c("labeler")].to_vec())
Some([c("profile"), c("rule"), c("labeler"), label].to_vec())
} else if space == members_space(group) {
Some([c("role"), c("permissions"), c("membership")].to_vec())
Some([c("role"), c("permissions"), c("membership"), label].to_vec())
} else {
None
};
@@ -118,7 +120,7 @@ impl Host {
self.face(group, write)?;
}
}
Ok(())
moderation::beside(space, writes)
}
}
@@ -458,12 +460,15 @@ impl Host {
let group = &acting.grant.group;
let (roles, grants) = self.standing(acting)?;
let own = uri == meta_space(group) || uri == members_space(group);
let configures = actions_for(&grants, &roles).contains("group.configure");
let held = actions_for(&grants, &roles);
let configures = held.contains("group.configure");
let access = self.group_record(group, uri, &format!("{NS}.access"), "self");
let access = access.map_err(XrpcError::internal)?.unwrap_or_default();
let everything = repo_collections_for(&grants, &roles).contains("*");
let access = Access::of(&access, uri);
let writable = writes_in(&access, &roles, &acting.grant.member, everything);
let labelling = held.contains("label");
let labels = labels_in(&access, &roles, &acting.grant.member, labelling);
for w in writes {
let (collection, _) = w.path();
if !acting.permissions.space(space, Some(collection), action(w)) {
@@ -474,6 +479,7 @@ impl Host {
)));
}
let still = match own {
_ if collection == LABEL => labels,
_ if uri == members_space(group) => {
may_write(&members_writes(&grants, &roles), collection, action(w))
}
@@ -515,6 +521,7 @@ impl Host {
true => self.leaving(acting, uri, space, writes).await?,
false => Default::default(),
};
let going = self.labels_going(group, uri, writes)?;
let allow = |w: &[Write]| self.may_space(acting, uri, space, w);
let asked = Asked {
put,
@@ -526,6 +533,7 @@ impl Host {
return Ok(false);
};
self.wrote(acting, Some(uri), &made)?;
self.labelled(group, uri, &acting.grant.member, &made, &going)?;
// In the members space, what a write means is done too.
if members {
self.members_written(acting, &made, &leaving).await?;
crates/group-host/tests/group_tokens.rs+12−4
@@ -13,6 +13,7 @@ use serde_json::{Value as Json, json};
const CALENDAR: &str = "com.example.calendar";
const EVENT: &str = "com.example.event";
const LABEL: &str = "com.atproto.label.label";
const GET_GROUP_AUTH: &str = "fyi.opensocial.getGroupAuth";
async fn membership(h: &Running, did: &str, who: &str, roles: &[&str]) {
@@ -127,13 +128,18 @@ async fn gives_a_member_a_token_for_what_their_roles_write_in_a_space() {
.await;
assert_eq!(said.error(), (403, "ScopeMissing"));
// An admin's is for anything there, and any file.
// An admin's is for anything there, labels too, and any file.
let said = group_auth(&h, &app, &alice, &json!({"group": did, "space": calendar})).await;
assert_eq!(
said.body["collections"],
json!([{"collection": "*"}, {"collection": EVENT}])
);
assert!(said.body["scope"].as_str().unwrap().ends_with("blob:*/*"));
assert_eq!(
said.body["repoCollections"],
json!([{"collection": "*"}, {"collection": EVENT}])
);
let scope = said.body["scope"].as_str().unwrap();
assert!(scope.split(' ').any(|s| s == "blob:*/*"), "{scope}");
}
#[tokio::test]
@@ -144,12 +150,14 @@ async fn gives_a_member_a_token_for_the_members_space_as_the_group_grants_them()
let app = App::new("console");
let said = group_auth(&h, &app, &alice, &json!({"group": did, "space": members})).await;
assert_eq!(said.status, 200, "{}", said.body);
// Roles, the permissions record and memberships, kept there alone.
// Labels, roles, the permissions record and memberships, kept there
// alone.
let c = |n: &str| format!("{NS}.{n}");
let names: Vec<Json> = ["membership", "permissions", "role"]
let mut names: Vec<Json> = ["membership", "permissions", "role"]
.iter()
.map(|n| json!({"collection": c(n)}))
.collect();
names.insert(0, json!({"collection": LABEL}));
assert_eq!(said.body["collections"], json!(names));
assert_eq!(said.body["repoCollections"], json!([]));
let scope = said.body["scope"].as_str().unwrap();
crates/group-host/tests/mcp.rs+87−0
crates/group-host/tests/moderation.rs+121−182
crates/group-host/tests/oauth_scope.rs+2−2
crates/group-host/tests/rbac.rs+14−12
crates/group-host-mcp/src/lib.rs+72−7
crates/group-host-mcp/tests/protocol.rs+72−20
crates/opensocial/src/lib.rs+65−8
crates/opensocial/tests/commands.rs+12−1
docs/design/groups.md+1−1
docs/design/membership.md+1−1
docs/design/moderation.md+36−43
docs/guides/shots/rules-create-role-dark.png+0−0
A binary file, not shown.
docs/guides/shots/rules-create-role.png+0−0
A binary file, not shown.
docs/guides/shots/rules-create-role.txt+0−2
docs/guides/shots/rules-role-made-dark.png+0−0
A binary file, not shown.
docs/guides/shots/rules-role-made.png+0−0
A binary file, not shown.
docs/guides/shots/rules-role-made.txt+1−1
docs/guides/moderating.md+5−4
docs/guides/rules-and-roles.md+1−2
docs/reference/api.md+1−3
docs/reference/cli.md+1−1
docs/reference/mcp.md+1−1
harness/lexicons.mjs+7−3
lexicons/fyi/opensocial/applyLabel.jsondeleted+0−60
lexicons/fyi/opensocial/defs.json+2−3
lexicons/fyi/opensocial/label.jsondeleted+0−40
lexicons/fyi/opensocial/members.json+1−0
lexicons/fyi/opensocial/meta.json+1−0
lexicons/fyi/opensocial/moderate.json+2−2
lexicons/fyi/opensocial/negateLabel.jsondeleted+0−59
lexicons/upstream/com/atproto/label/label.jsonnew+46−0
web/src/lib/organisms/ModerationQueue.svelte+2−2
web/src/lib/organisms/ReviewDialog.svelte+43−49
web/src/lib/actions.ts+1−3
web/src/lib/activity.ts+1−1
web/src/lib/moderation.ts+1−1
web/src/routes/g/[handle]/moderation/+page.server.ts+37−10
web/src/routes/g/[handle]/moderation/+page.svelte+1−2