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

A group's settings are changed from the console

Merged chadtmiller.com asked to merge into main from chadtmiller.com/group-host:host/group-settings
crates/group-host/src/group_api.rs+22−15
@@ -252,14 +252,17 @@ pub async fn get_group(
host.group_records(group, &members, &format!("{NS}.{collection}"))
.map_err(XrpcError::internal)
};
let mut people = Vec::new();
for (_, m) in records("membership")? {
let actor = host
.actor_view(m["member"].as_str().unwrap_or_default())
.await;
people.push(json!({"actor": actor, "roles": objects("role", listed(&m, "roles", "role"))}));
}
out["members"] = json!(people);
// Each named by their document, read at once rather than in turn.
let memberships = records("membership")?;
let actors = memberships
.iter()
.map(|(_, m)| host.actor_view(m["member"].as_str().unwrap_or_default()));
let actors = futures::future::join_all(actors).await;
out["members"] = memberships
.iter()
.zip(actors)
.map(|((_, m), actor)| json!({"actor": actor, "roles": objects("role", listed(m, "roles", "role"))}))
.collect();
out["roles"] = records("role")?
.into_iter()
.map(|(key, r)| {
@@ -317,13 +320,17 @@ pub async fn get_group(
.store
.asking(group, None, 100)
.map_err(XrpcError::internal)?;
let mut asking = Vec::new();
for r in &waiting {
let mut view = crate::group_join::request_view(r);
view["actor"] = host.actor_view(&r.did).await;
asking.push(view);
}
out["joinRequests"] = json!(asking);
let actors = waiting.iter().map(|r| host.actor_view(&r.did));
let actors = futures::future::join_all(actors).await;
out["joinRequests"] = waiting
.iter()
.zip(actors)
.map(|(r, actor)| {
let mut view = crate::group_join::request_view(r);
view["actor"] = actor;
view
})
.collect();
}
Ok(Json(out))
}
crates/group-host/Cargo.toml+1−0
@@ -10,6 +10,7 @@ rust-version.workspace = true
atproto.workspace = true
anyhow.workspace = true
axum.workspace = true
futures.workspace = true
hmac.workspace = true
rand_core.workspace = true
reqwest.workspace = true
docs/design/README.md+3−2
@@ -114,8 +114,9 @@ says otherwise.
profile and rules, joining and leaving, its members, and admitting
those asking; done); its members run from its page (roles given and
taken, people put out, invites by handle, and invitations taken up or
turned down on home; done); then its settings (profile, rules, its
apps and app passwords): the console's pages in
turned down on home; done); and its settings (`/g/<handle>/settings`:
profile, rules, roles, the apps acting as it with their log, and app
passwords; done): the console's pages in
`apps/web/src/pages`. Each is used end to end in `harness/e2e`.
8. **Moderation, recovery and moving.** Reports, labels, subjects and
history; recovery keys; importing an account; migrating a group to
harness/e2e/flows.spec.mjs+52−0
@@ -105,6 +105,58 @@ test('being told why the host refused', async () => {
await expect(page.getByText('You are a member.')).toBeVisible()
})
test("changing a group's profile", async () => {
await page.goto(url('/g/hikers.groups.test'))
await page.getByRole('link', { name: 'Settings' }).click()
await page.getByRole('textbox', { name: 'Name', exact: true }).fill('Hikers of the Hills')
await page.getByRole('button', { name: 'Save the profile' }).click()
await page.goto(url('/g/hikers.groups.test'))
await expect(page.getByRole('heading', { name: 'Hikers of the Hills' })).toBeVisible()
await expect(page.getByText('Walks on Sundays.')).toBeVisible()
})
test('adding a rule, and taking it away', async () => {
await page.goto(url('/g/hikers.groups.test/settings'))
await page.getByRole('textbox', { name: 'Rule' }).fill('Leave no trace')
await page.getByRole('button', { name: 'Add the rule' }).click()
await expect(page.locator('.rules', { hasText: 'Leave no trace' })).toBeVisible()
await page.goto(url('/g/hikers.groups.test'))
await expect(page.getByText('Leave no trace')).toBeVisible()
await page.goto(url('/g/hikers.groups.test/settings'))
await page.getByRole('button', { name: 'Take away “Leave no trace”' }).click()
await expect(page.locator('.rules')).toHaveCount(0)
})
test('defining a role', async () => {
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('button', { name: 'Define the role' }).click()
await expect(page.locator('.roles li', { hasText: 'Ride leader' })).toContainText('invite')
await page.getByRole('button', { name: 'Take away Ride leader' }).click()
await expect(page.locator('.roles li', { hasText: 'Ride leader' })).toHaveCount(0)
})
test('making an app password, and ending what it signed in', async () => {
await page.getByRole('textbox', { name: 'Where it is used' }).fill('Phone')
await page.getByRole('button', { name: 'Make an app password' }).click()
const password = (await page.locator('code.password').textContent()).trim()
const signIn = () =>
fetch(`${world.host}/xrpc/com.atproto.server.createSession`, {
method: 'POST',
headers: { 'content-type': 'application/json' },
body: JSON.stringify({ identifier: 'hikers.groups.test', password }),
})
expect((await signIn()).status).toBe(200)
await page.goto(url('/g/hikers.groups.test/settings'))
await expect(page.locator('.passwords', { hasText: 'Phone' })).toBeVisible()
await page.getByRole('button', { name: "End app-password:Phone's access" }).click()
await expect(page.locator('.sessions')).toHaveCount(0)
await page.getByRole('button', { name: 'Revoke “Phone”' }).click()
await expect(page.locator('.passwords')).toHaveCount(0)
expect((await signIn()).status).toBe(401)
})
test('signing an app in as her group', async () => {
const app = await new App('atproto repo:app.bsky.feed.post').listen()
await page.goto(await app.push())
web/src/lib/organisms/AppPasswords.sveltenew+32−0
@@ -0,0 +1,32 @@
<script lang="ts">
import Empty from '#lib/molecules/Empty.svelte';
/**
* The group's app passwords, never the passwords, each to revoke; and a
* new one to make, shown once (`made`).
*/
type Password = { name: string; member: string; privileged: boolean; lastUsedAt?: string };
let { passwords, made }: { passwords: Password[]; made?: { name: string; password: string } } = $props();
</script>
<div class="stack">
{#if made}
<p class="made">The app password “{made.name}” is <code class="password">{made.password}</code>. Copy it now: it is not shown again.</p>
{/if}
{#if passwords.length}
<ul class="passwords">
{#each passwords as p (p.name)}
<li>
<strong>{p.name}</strong> <span class="mute">by {p.member}{p.privileged ? ', with chat' : ''}{p.lastUsedAt ? `, last used ${p.lastUsedAt}` : ''}</span>
<form method="post" action="?/unpassword"><input type="hidden" name="name" value={p.name} /><button type="submit">Revoke “{p.name}”</button></form>
</li>
{/each}
</ul>
{:else}
<Empty title="No app passwords">An app that signs in with a handle and a password, as the Bluesky app does, signs in to the group with one.</Empty>
{/if}
<form class="stack" method="post" action="?/password">
<label class="field">Where it is used <input name="name" required maxlength="64" placeholder="My phone" /></label>
<label><input type="checkbox" name="privileged" /> It may use chat</label>
<button type="submit">Make an app password</button>
</form>
</div>
web/src/lib/organisms/GroupApps.sveltenew+27−0
@@ -0,0 +1,27 @@
<script lang="ts">
import Empty from '#lib/molecules/Empty.svelte';
/** What acts as the group: each grant, whose it is, to end; and what grants did lately. */
type Session = { tokenId: string; clientId: string; member: string; source: string; scope?: string; lastUsedAt?: string };
let { sessions, activity }: { sessions: Session[]; activity: { member: string; clientId?: string; action: string; at: string }[] } = $props();
</script>
<div class="stack">
{#if sessions.length}
<ul class="sessions">
{#each sessions as s (s.tokenId)}
<li>
<span class="mono">{s.clientId}</span> <span class="mute">{s.source}, by {s.member}{s.lastUsedAt ? `, last used ${s.lastUsedAt}` : ''}</span>
<form method="post" action="?/revoke"><input type="hidden" name="tokenId" value={s.tokenId} /><button type="submit">End {s.clientId}'s access</button></form>
</li>
{/each}
</ul>
{:else}
<Empty title="No app acts as this group" />
{/if}
{#if activity.length}
<h3>Lately</h3>
<ul class="activity">
{#each activity as a, i (i)}<li><span class="mute">{a.at}</span> {a.action}</li>{/each}
</ul>
{/if}
</div>
web/src/lib/organisms/ProfileForm.sveltenew+25−0
@@ -0,0 +1,25 @@
<script lang="ts">
/** A group's profile, to change: its name, its words, how people join, and its own site. */
let {
displayName,
description,
joinPolicy,
url
}: { displayName?: string; description?: string; joinPolicy?: string; url?: string } = $props();
const policy = $derived(joinPolicy?.split('#').pop() ?? 'approval');
</script>
<form class="stack" method="post" action="?/profile">
<label class="field">Name <input name="displayName" required maxlength="64" value={displayName ?? ''} /></label>
<label class="field">What it is for <textarea name="description" maxlength="300">{description ?? ''}</textarea></label>
<label class="field">
How people join
<select name="joinPolicy" value={policy}>
<option value="approval">They ask, and a member who may admits them</option>
<option value="open">Anyone signed in, at once</option>
<option value="invite">Only by invitation</option>
</select>
</label>
<label class="field">Its own site <input name="url" type="url" value={url ?? ''} /></label>
<button type="submit">Save the profile</button>
</form>
web/src/lib/organisms/RolesEditor.sveltenew+37−0
@@ -0,0 +1,37 @@
<script lang="ts">
/**
* A group's roles: each, what it may do, to take away; and a new one to
* define, with what it may do, the roles its holders may give, and
* whether members get it on joining.
*/
type Role = { key: string; name?: string; description?: string };
type Binding = { role: string; actions: string[] };
let { roles = [], bindings = [], actions }: { roles?: Role[]; bindings?: Binding[]; actions: string[] } = $props();
const may = (key: string) => bindings.find((b) => b.role === key)?.actions ?? [];
</script>
<div class="stack">
<ul class="roles">
{#each roles as r (r.key)}
<li>
<strong>{r.name ?? r.key}</strong> <span class="mute mono">{r.key}</span>
<p class="mute">{may(r.key).join(', ') || 'Nothing beyond being a member'}</p>
<form method="post" action="?/unrole"><input type="hidden" name="role" value={r.key} /><button type="submit">Take away {r.name ?? r.key}</button></form>
</li>
{/each}
</ul>
<form class="stack" method="post" action="?/role">
<label class="field">Its key <input name="role" required pattern="[a-z0-9-]+" maxlength="64" /></label>
<label class="field">Its name <input name="name" required maxlength="64" /></label>
<fieldset>
<legend>It may</legend>
{#each actions as a (a)}<label><input type="checkbox" name="action" value={a} /> {a}</label>{/each}
</fieldset>
<fieldset>
<legend>Its holders may give</legend>
{#each roles as r (r.key)}<label><input type="checkbox" name="assignable" value={r.key} /> {r.name ?? r.key}</label>{/each}
</fieldset>
<label><input type="checkbox" name="default" /> Every new member gets it</label>
<button type="submit">Define the role</button>
</form>
</div>
web/src/lib/organisms/RulesEditor.sveltenew+25−0
@@ -0,0 +1,25 @@
<script lang="ts">
import Empty from '#lib/molecules/Empty.svelte';
/** A group's rules, each to take away, and a new one to add. */
let { rules = [] }: { rules?: { rkey: string; title: string; text?: string }[] } = $props();
</script>
<div class="stack">
{#if rules.length}
<ol class="rules">
{#each rules as r (r.rkey)}
<li>
<strong>{r.title}</strong>{#if r.text}<p class="mute">{r.text}</p>{/if}
<form method="post" action="?/unrule"><input type="hidden" name="rkey" value={r.rkey} /><button type="submit">Take away “{r.title}”</button></form>
</li>
{/each}
</ol>
{:else}
<Empty title="No rules yet" />
{/if}
<form class="stack" method="post" action="?/rule">
<label class="field">Rule <input name="title" required maxlength="100" /></label>
<label class="field">What it means <textarea name="text" maxlength="1000"></textarea></label>
<button type="submit">Add the rule</button>
</form>
</div>
web/src/lib/actions.tsnew+16−0
@@ -0,0 +1,16 @@
// What a role may do, as the host's methods ask (fyi.opensocial.defs#action).
export const ACTIONS = [
'mod.read',
'mod.resolve',
'label',
'takedown',
'invite',
'admit',
'eject',
'role.assign',
'space.create',
'space.configure',
'space.delete',
'group.configure'
];
web/src/routes/g/[handle]/settings/+page.server.tsnew+96−0
web/src/routes/g/[handle]/settings/+page.sveltenew+35−0
web/src/routes/g/[handle]/+page.server.ts+1−6
web/src/routes/g/[handle]/+page.svelte+1−0