chadtmiller.com/group-host
atmosphere group host
0
0
The console's role editor shows what a permission set gives
crates/group-host/src/group_api.rs+23−2
| @@ -7,7 +7,11 @@ | ||
use crate::Host; | ||
use crate::api::{Params, page, param}; | ||
use crate::group::{Made, NewGroup, members_space, meta_space, rkey_did}; | ||
use crate::rbac::{NS, actions_for, listed, repo_collections_for, roles_of}; | ||
use crate::member_writes::{expanded, held}; | ||
use crate::rbac::{ | ||
ACTIONS, Grant, NS, actions_for, actions_of, listed, repo_collections_for, roles_of, scope_of, | ||
}; | ||
use crate::scopes::covers; | ||
use crate::space_api::{service_caller, unauthorized}; | ||
use crate::xrpc::XrpcError; | ||
use axum::Json; | ||
| @@ -192,6 +196,19 @@ fn objects(field: &str, items: impl IntoIterator<Item = impl Into<String>>) -> V | ||
.collect() | ||
} | ||
| ||
/// The scopes a role's editor offers that holders of `roles` hold enough | ||
/// of to give, as a role write asks: each action's, then the group's | ||
/// permission sets but `authManageGroup`, which is `group.configure`'s. | ||
fn grantable(grants: &[Grant], roles: &[String], group: &str) -> Vec<Value> { | ||
let held = held(grants, roles); | ||
let sets = ["authManageProfile", "authModerate"].map(|s| format!("include:{NS}.{s}")); | ||
let offered = ACTIONS.iter().filter_map(|a| scope_of(a)).chain(sets); | ||
offered | ||
.filter(|s| expanded(s).iter().all(|x| covers(&held, x, group))) | ||
.map(|s| json!({ "scope": s })) | ||
.collect() | ||
} | ||
| ||
/// A group as someone not signed in sees it: what anyone can learn of it | ||
/// already, its DID and handle. | ||
fn signed_out(did: &str, handle: String) -> Value { | ||
| @@ -258,6 +275,7 @@ pub async fn get_group( | ||
}); | ||
if member { | ||
viewer["accepted"] = json!(accepted(&host, &members, &me).map_err(XrpcError::internal)?); | ||
viewer["grantable"] = json!(grantable(&granted, &roles, group)); | ||
} | ||
// Their own request, while it waits. | ||
let asked = host.store.asked(group, &me).map_err(XrpcError::internal)?; | ||
| @@ -300,7 +318,10 @@ pub async fn get_group( | ||
"actions": actions_for(&granted, one), | ||
"assignable": objects("role", g.assignable.clone()), | ||
"repoCollections": objects("collection", repo_collections_for(&granted, one)), | ||
"scopes": objects("scope", g.scopes.clone()), | ||
"scopes": g.scopes.iter().map(|s| json!({ | ||
"scope": s, | ||
"actions": actions_of(std::slice::from_ref(s)), | ||
})).collect::<Vec<_>>(), | ||
}) | ||
}) | ||
.collect(); | ||
crates/group-host/tests/groups.rs+85−1
| @@ -10,7 +10,7 @@ use common::spaces::*; | ||
use common::start; | ||
use group_host::authority::Access; | ||
use group_host::group::{members_space, meta_space}; | ||
use group_host::rbac::ACTIONS; | ||
use group_host::rbac::{ACTIONS, scope_of}; | ||
use group_host::repo::Write; | ||
use serde_json::{Value as Json, json}; | ||
| ||
| @@ -174,6 +174,43 @@ async fn shows_a_group_as_each_viewer_may_see_it() { | ||
assert_eq!(admin["actions"], json!(every)); | ||
assert_eq!(admin["assignable"], json!([{"role": "*"}])); | ||
assert_eq!(admin["repoCollections"], json!([{"collection": "*"}])); | ||
// Each of its scopes with the actions the host reads it as granting. | ||
let moderates = [ | ||
"admit", | ||
"eject", | ||
"invite", | ||
"label", | ||
"mod.read", | ||
"mod.resolve", | ||
"role.assign", | ||
]; | ||
let mut configures = moderates.to_vec(); | ||
configures.insert(2, "group.configure"); | ||
assert_eq!( | ||
admin["scopes"][0], | ||
json!({"scope": format!("include:{NS}.authManageGroup"), "actions": configures}) | ||
); | ||
assert_eq!( | ||
admin["scopes"][5], | ||
json!({"scope": "repo:*", "actions": []}) | ||
); | ||
// She holds enough to give a role each action, and each of the | ||
// group's permission sets. | ||
let sets = [ | ||
format!("include:{NS}.authManageProfile"), | ||
format!("include:{NS}.authModerate"), | ||
]; | ||
let mut offered: Vec<String> = ACTIONS.iter().map(|a| scope_of(a).unwrap()).collect(); | ||
offered.extend(sets.clone()); | ||
assert_eq!( | ||
viewer["grantable"], | ||
json!( | ||
offered | ||
.iter() | ||
.map(|s| json!({"scope": s})) | ||
.collect::<Vec<_>>() | ||
) | ||
); | ||
// Each role's grant in its own record: the founders administer the | ||
// group, label, make, change and end spaces, write any record as the | ||
// group in its repo and its spaces, and give every role; and the | ||
| @@ -247,6 +284,7 @@ async fn shows_a_group_as_each_viewer_may_see_it() { | ||
let board = spaces.iter().find(|s| s["uri"] == admins).unwrap(); | ||
assert_eq!(board.get("policy"), None); | ||
assert_eq!(hers["group"]["viewer"]["actions"], json!([])); | ||
assert_eq!(hers["group"]["viewer"]["grantable"], json!([])); | ||
let theirs = spaces | ||
.iter() | ||
.find(|s| s["uri"] == members_space(&did)) | ||
| @@ -266,6 +304,52 @@ async fn shows_a_group_as_each_viewer_may_see_it() { | ||
assert!(!shown(&hers)); | ||
assert!(shown(&view(&h, &did, Some(&alice)).await)); | ||
| ||
// A moderator may give what moderating holds, and no more: not the | ||
// labels in every space, nor the profile, nor running the group. | ||
let moderator = json!({"$type": format!("{NS}.role"), "scopes": [&sets[1]], "createdAt": "2026-11-03T00:00:00Z"}); | ||
let theirs = json!({"$type": format!("{NS}.membership"), "roles": ["member", "moderator"], "createdAt": "2026-11-03T00:00:00Z"}); | ||
h.host | ||
.space_write( | ||
&did, | ||
&members_space(&did), | ||
&[ | ||
Write::Create { | ||
collection: format!("{NS}.role"), | ||
rkey: "moderator".into(), | ||
value: moderator, | ||
}, | ||
Write::Update { | ||
collection: format!("{NS}.membership"), | ||
rkey: carol.did.clone(), | ||
value: theirs, | ||
}, | ||
], | ||
) | ||
.await | ||
.unwrap(); | ||
let hers = view(&h, &did, Some(&carol)).await; | ||
let gives: Vec<String> = [ | ||
"mod.read", | ||
"mod.resolve", | ||
"invite", | ||
"admit", | ||
"eject", | ||
"role.assign", | ||
] | ||
.iter() | ||
.map(|a| scope_of(a).unwrap()) | ||
.chain([sets[1].clone()]) | ||
.collect(); | ||
assert_eq!( | ||
hers["group"]["viewer"]["grantable"], | ||
json!( | ||
gives | ||
.iter() | ||
.map(|s| json!({"scope": s})) | ||
.collect::<Vec<_>>() | ||
) | ||
); | ||
| ||
// Once they write their acceptance, they have accepted. | ||
h.host | ||
.store | ||
docs/design/membership.md+19−0
| @@ -138,6 +138,25 @@ every role can make a role and give it at once. One who can't may make a | ||
role and grant it what they hold, but nobody can give it until someone | ||
who may assign it adds it to a role's `assignable`. | ||
| ||
`getGroup` says beforehand what a member may give. In each role's | ||
binding, each scope comes with the actions the host reads it as | ||
granting. The viewer's `grantable` lists, of each action's scope and the | ||
`authManageProfile` and `authModerate` sets, those their roles hold | ||
enough of to add, by the same check. `authManageGroup` is | ||
`group.configure`'s scope, so it's among the actions'. | ||
| ||
The console's role editor shows those and no more, beside what the role | ||
has already, which it may take away. It offers the three permission sets | ||
as parts in running the group (profile and rules, moderation, the whole | ||
group), each its own choice. An action a ticked set gives shows ticked | ||
and can't be unticked while the set is, saying which set it comes with. | ||
Taking it away means choosing a smaller set, or none, and ticking the | ||
actions to keep one by one. The editor saves what it shows: the sets | ||
and actions ticked, and any other scope of the role as it was, whose | ||
actions it shows as coming with those. It changes only roles the | ||
editing member may assign, and lists among the roles a role may give | ||
only those they may assign, beside those it lists already. | ||
| ||
A membership (`fyi.opensocial.membership`) is kept at its member's DID, | ||
holds `member` (`MemberRole`), and names only roles the group defines. | ||
| ||
docs/guides/shots/rules-change-role-dark.pngnew+0−0
A binary file, not shown.
docs/guides/shots/rules-change-role.pngnew+0−0
A binary file, not shown.
docs/guides/shots/rules-change-role.txtnew+50−0
| @@ -0,0 +1,50 @@ | ||
- dialog "Change this role": | ||
- heading "Change this role" [level=2] | ||
- button "Close": × | ||
- paragraph: People with Ride leader get the changes as soon as you save. To remove something that comes with Moderation or The whole group, untick that first. | ||
- text: Its name | ||
- textbox "Its name": Ride leader | ||
- group "Running the group": | ||
- text: Running the group | ||
- checkbox "Profile and rules Change the group's profile and rules." | ||
- text: Profile and rules Change the group's profile and rules. | ||
- checkbox "Moderation Approve, invite, label and remove members, change their roles, and review reports." [checked] | ||
- text: Moderation Approve, invite, label and remove members, change their roles, and review reports. | ||
- checkbox "The whole group Everything above, and the group's settings and roles." | ||
- text: The whole group Everything above, and the group's settings and roles. | ||
- group "It may": | ||
- text: It may | ||
- checkbox "mod.read Comes with moderation" [checked] [disabled] | ||
- text: mod.read Comes with moderation | ||
- checkbox "mod.resolve Comes with moderation" [checked] [disabled] | ||
- text: mod.resolve Comes with moderation | ||
- checkbox "label Comes with moderation" [checked] [disabled] | ||
- text: label Comes with moderation | ||
- checkbox "invite Comes with moderation" [checked] [disabled] | ||
- text: invite Comes with moderation | ||
- checkbox "admit Comes with moderation" [checked] [disabled] | ||
- text: admit Comes with moderation | ||
- checkbox "eject Comes with moderation" [checked] [disabled] | ||
- text: eject Comes with moderation | ||
- checkbox "role.assign Comes with moderation" [checked] [disabled] | ||
- text: role.assign Comes with moderation | ||
- checkbox "space.create" | ||
- text: space.create | ||
- checkbox "space.configure" | ||
- text: space.configure | ||
- checkbox "space.delete" | ||
- text: space.delete | ||
- group "People with it can give": | ||
- text: People with it can give | ||
- checkbox "Admin" | ||
- text: Admin | ||
- checkbox "Member" [checked] | ||
- text: Member | ||
- checkbox "Ride leader" | ||
- text: Ride leader | ||
- checkbox "Any role, even ones made later" | ||
- text: Any role, even ones made later | ||
- checkbox "Every new member gets it" | ||
- text: Every new member gets it | ||
- button "Cancel" | ||
- button "Save" | ||
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+8−2
| @@ -10,6 +10,14 @@ | ||
- textbox "Its name": | ||
- /placeholder: Moderator | ||
- text: Ride leader | ||
- group "Running the group": | ||
- text: Running the group | ||
- checkbox "Profile and rules Change the group's profile and rules." | ||
- text: Profile and rules Change the group's profile and rules. | ||
- checkbox "Moderation Approve, invite, label and remove members, change their roles, and review reports." | ||
- text: Moderation Approve, invite, label and remove members, change their roles, and review reports. | ||
- checkbox "The whole group Everything above, and the group's settings and roles." | ||
- text: The whole group Everything above, and the group's settings and roles. | ||
- group "It may": | ||
- text: It may | ||
- checkbox "mod.read" [checked] | ||
| @@ -32,8 +40,6 @@ | ||
- text: space.configure | ||
- checkbox "space.delete" | ||
- text: space.delete | ||
- checkbox "group.configure" | ||
- text: group.configure | ||
- group "People with it can give": | ||
- text: People with it can give | ||
- checkbox "Admin" | ||
docs/guides/shots/rules-give-dark.png+0−0
A binary file, not shown.
docs/guides/shots/rules-give.png+0−0
A binary file, not shown.
docs/guides/shots/rules-given-dark.png+0−0
A binary file, not shown.
docs/guides/shots/rules-given.png+0−0
A binary file, not shown.
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+3−2
| @@ -5,11 +5,12 @@ | ||
- listitem: | ||
- strong: Admin | ||
- text: admin Can admit eject group.configure invite label mod.read mod.resolve role.assign space.configure space.create space.delete | ||
- button "Delete Admin": Delete | ||
- group | ||
- listitem: | ||
- strong: Member | ||
- text: member Nothing more than a member | ||
- group | ||
- listitem: | ||
- strong: Ride leader | ||
- text: ride-leader Can admit invite mod.read | ||
- button "Delete Ride leader": Delete | ||
- group | ||
docs/guides/rules-and-roles.md+49−10
| @@ -89,6 +89,16 @@ each. They show by their short names: | ||
| `space.create`, `space.configure`, `space.delete` | Make a space (a part of the group with its own say over who reads and writes in it), change who can read and write one, and delete one. | | ||
| `group.configure` | Change the group's settings: its profile, rules, roles, apps and recovery keys. | | ||
| ||
Three parts in running the group bring several permissions at once, | ||
under **Running the group** when you create or change a role: | ||
| ||
- **Profile and rules** lets them change the group's profile and rules. | ||
It adds none of the permissions above. | ||
- **Moderation** brings `mod.read`, `mod.resolve`, `label`, `invite`, | ||
`admit`, `eject` and `role.assign`. Its `label` reaches the group's | ||
members and profile, not every space. | ||
- **The whole group** brings all of that, and `group.configure`. | ||
| ||
A role also says which roles its members can give. That list limits | ||
three things. They can change only the roles on it. They can remove only | ||
members whose roles are all on it. Everyone they let in gets Member, so | ||
| @@ -101,8 +111,10 @@ every role, even ones made later, so admins can give any role. | ||
2. In **Its key**, type a short name for the role, such as | ||
"ride-leader". Use lowercase letters, digits and hyphens. | ||
3. In **Its name**, type the name people see, such as "Ride leader". | ||
4. Under **It may**, tick what the role lets its members do. A ride | ||
leader here gets `mod.read`, `invite` and `admit`. | ||
4. Under **Running the group**, tick a part if the role should bring | ||
all it gives. A ride leader needs none. Under **It may**, tick what | ||
else the role lets its members do. A ride leader here gets | ||
`mod.read`, `invite` and `admit`. | ||
5. Under **People with it can give**, tick the roles its members can | ||
give. Here, **Member**. If you can give every role yourself, **Any | ||
role, even ones made later** lets its members give every role too. | ||
| @@ -116,11 +128,37 @@ every role, even ones made later, so admins can give any role. | ||
permissions. | ||
| ||
<!-- look /g/riders.groups.test/settings/roles --as alice --click 'button[popovertarget=define-role]' --type '#define-role [name=role]=ride-leader' --type '#define-role [name=name]=Ride leader' --click '#define-role input[value=invite]' --click '#define-role input[value=admit]' --click '#define-role input[value="mod.read"]' --click '#define-role input[name=assignable][value=member]' --click '#define-role button[type=submit]' --element section --> | ||
 | ||
 | ||
| ||
You can give a role only permissions your own roles hold, and the | ||
dialog offers only those. | ||
| ||
## How do I change a role? | ||
| ||
1. On the **Roles** tab, press the ⋯ at the end of the role's row. A | ||
menu opens. | ||
| ||
<!-- look /g/riders.groups.test/settings/roles --as alice --click '.roles > li:has(strong:text-is("Ride leader")) .action-menu summary' --element '.action-menu[open] .menu' --> | ||
 | ||
| ||
2. Press **Change**. The **Change this role** dialog opens, with what the | ||
role has ticked. | ||
3. Tick or untick what it lets its members do. A permission that comes | ||
with a part in running the group shows ticked and greyed, saying | ||
which part it comes with, as when **Moderation** is ticked here. To | ||
remove one of those, untick the part, then tick the permissions the | ||
role keeps one by one. | ||
| ||
<!-- look /g/riders.groups.test/settings/roles --as alice --click '.roles > li:has(strong:text-is("Ride leader")) .action-menu summary' --click '.action-menu[open] .menu button:has-text("Change")' --click ':popover-open input[name=set][value=moderate]' --element ':popover-open' --> | ||
 | ||
| ||
4. Press **Save**. The dialog closes, and the role's row shows what it | ||
lets its members do now. | ||
| ||
You can give a role only permissions your own roles have. The console | ||
can't edit a role. To change one, take it off everyone who holds it, | ||
delete it, and create it again. | ||
A permission a role has from a scope the dialog doesn't show, such as | ||
Admin's making and deleting spaces, says "Comes with its other | ||
permissions". The dialog keeps those as they are. Change them from a | ||
terminal. | ||
| ||
## How do I give a role to a member? | ||
| ||
| @@ -156,8 +194,8 @@ can't change roles or remove members. | ||
| ||
1. To take a role off, press the ⋯ on the member's row, then **Change | ||
roles**, untick the role, and press **Save**. The tag goes from their row. | ||
2. To delete a role, press **Delete** beside it on the **Roles** tab. | ||
The console asks you to confirm. | ||
2. To delete a role, press the ⋯ at the end of its row on the **Roles** | ||
tab, then **Delete**. The console asks you to confirm. | ||
3. Press **Delete**. The role goes from the list. | ||
| ||
People with a role lose what it lets them do when it goes. You can only | ||
| @@ -166,8 +204,9 @@ turns down a delete while anyone holds the role. | ||
| ||
## What can't be changed? | ||
| ||
Everyone in the group keeps the Member role, and it has no **Delete**. | ||
Admin shows a **Delete**, but you hold Admin, so the host turns it down. | ||
Everyone in the group keeps the Member role, and its menu has no | ||
**Delete**. Admin's menu has one, but you hold Admin, so the host turns | ||
it down. | ||
Leave Admin as it is. | ||
You can give and take only the roles your own roles can give, and a role | ||
you make can have only permissions you hold. Only members whose roles | ||
docs/reference/api.md+1−1
| @@ -58,7 +58,7 @@ spaces through the atproto methods below. | ||
| Method | What it does | | ||
| --------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | ||
| `POST fyi.opensocial.createGroup` | starts a group, with the caller as its founder and first admin. `metaPublicRead: false` keeps its `meta` space from anyone but its members | | ||
| `GET fyi.opensocial.getGroup` | shows a group as the caller may see it. Someone signed in who may read `meta` gets its profile and rules, and one who may read `members` also gets its member count, roles and spaces. Someone not signed in gets only its DID and handle | | ||
| `GET fyi.opensocial.getGroup` | shows a group as the caller may see it. Someone signed in who may read `meta` gets its profile and rules, and one who may read `members` also gets its member count, roles and spaces. A member is told, as `grantable`, which actions' scopes and permission sets they hold enough of to give a role. Someone not signed in gets only its DID and handle | | ||
| `GET fyi.opensocial.checkAddress` | says whether an address (one label under `HANDLE_DOMAIN`) is free for a new group. Anyone may ask | | ||
| `GET fyi.opensocial.checkGroupHandle` | says whether a domain names the group yet, so it can be its handle | | ||
| `POST fyi.opensocial.updateGroupHandle` | gives the group a handle on its own domain, or gives its address back | | ||
harness/e2e/flows.spec.mjs+32−10
| @@ -934,18 +934,40 @@ test('adding a rule, and taking it away', async () => { | ||
await expect(page.locator('.rule-rows')).toHaveCount(0); | ||
}); | ||
| ||
test('defining a role', async () => { | ||
test('defining a role, then giving it less', async () => { | ||
await page.goto(url('/g/hikers.groups.test/settings/roles')); | ||
await page.getByRole('button', { name: 'Create a role' }).click(); | ||
await page.getByRole('textbox', { name: 'Its key' }).fill('leader'); | ||
await page.getByRole('textbox', { name: 'Its name' }).fill('Ride leader'); | ||
await page.getByRole('checkbox', { name: 'invite' }).check(); | ||
await page | ||
.getByRole('dialog', { name: 'Create a role' }) | ||
.getByRole('button', { name: 'Create', exact: true }) | ||
.click(); | ||
await expect(page.locator('.roles li', { hasText: 'Ride leader' })).toContainText('invite'); | ||
await page.getByRole('button', { name: 'Delete Ride leader' }).click(); | ||
const create = page.getByRole('dialog', { name: 'Create a role' }); | ||
await create.getByRole('textbox', { name: 'Its key' }).fill('leader'); | ||
await create.getByRole('textbox', { name: 'Its name' }).fill('Ride leader'); | ||
// Moderation, a part in running the group: what comes with it shows | ||
// ticked, and can't be unticked while it is. | ||
await create.locator('input[name=set][value=moderate]').check(); | ||
const admit = create.locator('input[name=action][value=admit]'); | ||
await expect(admit).toBeChecked(); | ||
await expect(admit).toBeDisabled(); | ||
await create.getByRole('button', { name: 'Create', exact: true }).click(); | ||
const row = page.locator('.roles > li', { | ||
has: page.locator('strong', { hasText: 'Ride leader' }) | ||
}); | ||
await expect(row.locator('.tags')).toContainText('admit'); | ||
await expect(row.locator('.tags')).toContainText('mod.read'); | ||
// To take some of that away: no part, and only invite, ticked alone. | ||
await row.locator('.action-menu summary').click(); | ||
await row.getByRole('button', { name: 'Change', exact: true }).click(); | ||
const change = page.getByRole('dialog', { name: 'Change this role' }).filter({ visible: true }); | ||
const moderate = change.locator('input[name=set][value=moderate]'); | ||
await expect(moderate).toBeChecked(); | ||
await expect(change.locator('input[name=action][value=invite]')).toBeDisabled(); | ||
await moderate.uncheck(); | ||
await expect(change.locator('input[name=action][value=admit]')).not.toBeChecked(); | ||
await change.getByRole('checkbox', { name: 'invite', exact: true }).check(); | ||
await change.getByRole('button', { name: 'Save', exact: true }).click(); | ||
await expect(change).toBeHidden(); | ||
// Saved as shown: invite, and nothing moderation gave. | ||
await expect(row.locator('.tags')).toHaveText('invite'); | ||
await row.locator('.action-menu summary').click(); | ||
await row.getByRole('button', { name: 'Delete', exact: true }).click(); | ||
await page | ||
.getByRole('dialog', { name: 'Delete this role?' }) | ||
.filter({ visible: true }) | ||