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

The console moves an account here, on its own page

Merged chadtmiller.com asked to merge into main from chadtmiller.com/group-host:web/move
docs/design/moving.md+1−1
@@ -106,7 +106,7 @@ DID names this host, the network reads the account here.
## Moving one from the console
`account_move.rs` walks through the same steps for someone signed in to
the console. They sign in to the account at its own server too
the console, on its page `/move` (linked from starting a group). They sign in to the account at its own server too
([signing in](signing-in.md#signing-in-to-an-account-being-moved)), and
the host, holding its tokens for them, does each step itself:
docs/design/README.md+2−2
@@ -126,8 +126,8 @@ says otherwise.
(`migration.rs`; done, see [moving](moving.md)); an account on
another server becoming a group, its spaces with it (`import.rs`,
`import_space.rs`; done, see [moving](moving.md#an-account-becoming-a-group)),
moved from the console by the host signed in to it (`account_move.rs`;
done, its page next); and
moved from the console by the host signed in to it (`account_move.rs`
and the console's `/move`; done); and
moving the host itself (`move_host.rs`; done, see
[moving](moving.md#moving-the-host)):
`methods/{moderation,recovery,importAccount,migration}.ts`,
harness/e2e/flows.spec.mjs+22−1
@@ -3,7 +3,7 @@
// and what the app then does as the group, read back from the host.
import { expect, test } from '@playwright/test'
import { App, Assistant, didKey, signIn, signedInAs, url, who, world } from './pages.mjs'
import { App, Assistant, approve, didKey, signIn, signedInAs, url, who, world } from './pages.mjs'
test.describe.configure({ mode: 'serial' })
@@ -256,6 +256,27 @@ test('coming to a request that has lapsed', async () => {
await expect(page.getByText('This sign-in request has expired')).toBeVisible()
})
test('moving an account here to become a group', async () => {
await page.goto(url('/new'))
await page.getByRole('link', { name: 'move an account you already have' }).click()
await page.getByRole('textbox', { name: 'The account to move' }).fill(who.harbor.handle)
await page.getByRole('button', { name: 'Sign in to it' }).click()
// At its own server, as itself; then back, still alice.
await approve(page, 'harbor')
await page.waitForURL(url('/move'))
await expect.poll(() => signedInAs(page)).toBe('@alice.test')
await expect(page.getByText('Here it will be')).toContainText('@harbor.groups.test')
await page.getByRole('button', { name: 'Copy it here' }).click()
const code = page.getByRole('textbox', { name: 'The code' })
await expect(code).toBeVisible()
// The code its server emailed, from its inbox.
const mail = await fetch(`${world.mail}?to=harbor@test.com`).then((r) => r.json())
await code.fill(mail.code)
await page.getByRole('button', { name: 'Finish moving it' }).click()
await page.waitForURL(url('/g/harbor.groups.test'))
await expect(page.getByRole('heading', { level: 1 })).toBeVisible()
})
test('signing out', async () => {
await page.goto(url('/'))
await page.getByRole('button', { name: 'Sign out' }).click()
harness/e2e/setup.mjs+3−2
@@ -54,7 +54,8 @@ export default async function setup() {
const children = []
const stop = () => children.reverse().forEach((c) => c.kill('SIGTERM'))
try {
const pds = spawn('node', [join(root, 'harness/pds.mjs'), '--accounts', 'alice,bob'], { stdio: ['pipe', 'pipe', 'inherit'] })
// harbor is an account of its own, which alice moves here to become a group.
const pds = spawn('node', [join(root, 'harness/pds.mjs'), '--accounts', 'alice,bob,harbor'], { stdio: ['pipe', 'pipe', 'inherit'] })
children.push(pds)
const net = JSON.parse(await line(pds, (l) => l.startsWith('{"pds"')))
@@ -103,7 +104,7 @@ export default async function setup() {
if (!made.ok) throw new Error(`createGroup: ${await made.text()}`)
const riders = await made.json()
process.env.E2E_WORLD = JSON.stringify({ base, host, pds: net.pds, accounts: net.accounts, riders: riders.did })
process.env.E2E_WORLD = JSON.stringify({ base, host, pds: net.pds, mail: net.mail, accounts: net.accounts, riders: riders.did })
return stop
} catch (e) {
stop()
web/src/lib/molecules/MoveSignIn.sveltenew+18−0
@@ -0,0 +1,18 @@
<script lang="ts">
/**
* Signing in to an account to move here, at its own server: its handle,
* sent to the group host's `/console/move/login`, which goes there and
* back to `back`.
*/
let { back = '/move' }: { back?: string } = $props();
</script>
<form class="stack" method="get" action="/console/move/login">
<input type="hidden" name="back" value={back} />
<label class="field">
The account to move
<input name="handle" required autocomplete="off" placeholder="riders.bsky.social" />
</label>
<p>Its server asks you to sign in to it, and to let this host move it.</p>
<button type="submit">Sign in to it</button>
</form>
web/src/lib/organisms/AccountMove.sveltenew+46−0
@@ -0,0 +1,46 @@
<script lang="ts">
/**
* An account signed in to move here: before its move starts, what
* moving it would make of it, and its address here to choose; once
* started, the code its server emailed, to finish. `failed` is what
* the host said of the last try, if it refused it.
*/
type Moving = { did: string; handle?: string; pds?: string };
type Plan = { handle: string; label: string; keeps: boolean; refused?: unknown };
let { moving, plan, failed }: { moving: Moving; plan: Plan | null; failed?: string } = $props();
const name = $derived(moving.handle ?? moving.did);
</script>
<div class="stack">
{#if failed}<p class="danger">{failed}</p>{/if}
{#if plan}
<p>Moving <span class="mono">@{name}</span>, from <span class="mono">{moving.pds}</span>.</p>
{#if plan.refused}
<p class="danger">It can't have that address here: choose another.</p>
{/if}
<p>
Here it will be <span class="mono">@{plan.handle}</span>{#if plan.keeps}, its own handle{/if}.
</p>
<form class="stack" method="get">
<label class="field">
Its address here
<input name="address" value={plan.label} maxlength="63" pattern="[A-Za-z0-9\-]+" />
</label>
<button type="submit">Check that address</button>
</form>
<form class="stack" method="post" action="?/start">
<input type="hidden" name="address" value={plan.label} />
<p>Its posts, files and spaces are copied here, and its server emails you a code that lets it move.</p>
<button type="submit" disabled={!!plan.refused}>Copy it here</button>
</form>
{:else}
<p><span class="mono">@{name}</span> is copied here. Its server has emailed a code to the address the account has there.</p>
<form class="stack" method="post" action="?/finish">
<label class="field">The code <input name="code" required autocomplete="one-time-code" maxlength="64" /></label>
<button type="submit">Finish moving it</button>
</form>
{/if}
<form method="post" action="?/cancel">
<button type="submit">Stop, and sign out of it</button>
</form>
</div>
web/src/routes/move/+page.server.tsnew+48−0
@@ -0,0 +1,48 @@
import type * as getViewer from '#lib/lexicons/fyi/opensocial/getViewer.ts';
import type * as getAccountMove from '#lib/lexicons/fyi/opensocial/getAccountMove.ts';
import type * as checkImport from '#lib/lexicons/fyi/opensocial/checkImport.ts';
import type { Actions, PageServerLoad } from './$types';
import { fail, redirect } from '@sveltejs/kit';
import { act, xrpc } from '#lib/data.ts';
type Did = `did:${string}:${string}`;
/**
* Who is moving an account here, the account they signed in to move if
* any, and, until its move starts, what moving it would make of it.
*/
export const load: PageServerLoad = async (event) => {
const { actor } = await xrpc<typeof getViewer.main>(event, 'fyi.opensocial.getViewer', {});
if (!actor?.canCreateGroup) return { actor: actor ?? null, moving: null, plan: null };
const moving = await xrpc<typeof getAccountMove.main>(event, 'fyi.opensocial.getAccountMove', {});
if (!moving.did) return { actor, moving: null, plan: null };
const did = moving.did as Did;
const address = event.url.searchParams.get('address')?.trim() || undefined;
const plan = moving.started ? null : await xrpc<typeof checkImport.main>(event, 'fyi.opensocial.checkImport', { did, address });
return { actor, moving: { did, handle: moving.handle, pds: moving.pds }, plan };
};
const text = (form: FormData, key: string) => String(form.get(key) ?? '').trim();
/** Starting the move, finishing it with the emailed code, and stopping. */
export const actions: Actions = {
start: async (event) => {
const form = await event.request.formData();
return act(event, 'fyi.opensocial.startAccountMove', { address: text(form, 'address') || undefined });
},
finish: async (event) => {
const form = await event.request.formData();
const res = await event.fetch('/xrpc/fyi.opensocial.finishAccountMove', {
method: 'POST',
headers: { 'content-type': 'application/json' },
body: JSON.stringify({ code: text(form, 'code') })
});
if (!res.ok) {
const failure = await res.json().catch(() => null);
return fail(res.status, { failed: failure?.message ?? res.statusText });
}
const done: { handle: string } = await res.json();
redirect(303, `/g/${done.handle}`);
},
cancel: async (event) => act(event, 'fyi.opensocial.cancelAccountMove', {})
};
web/src/routes/move/+page.sveltenew+23−0
@@ -0,0 +1,23 @@
<script lang="ts">
import MoveSignIn from '#lib/molecules/MoveSignIn.svelte';
import AccountMove from '#lib/organisms/AccountMove.svelte';
import SignIn from '#lib/molecules/SignIn.svelte';
import Page from '#lib/templates/Page.svelte';
let { data, form } = $props();
</script>
<svelte:head><title>Move an account here · opensocial</title></svelte:head>
<Page title="Move an account here">
{#if !data.actor}
<p>Sign in first, as yourself: you will run the group it becomes.</p>
<SignIn back="/move" />
{:else if !data.actor.canCreateGroup}
<p>This host starts groups only for the people it names.</p>
{:else if !data.moving}
<p>An account you already have, on any server, can move here to become a group you run. It keeps its DID, so whoever follows it still does, and its spaces come with it.</p>
<MoveSignIn back="/move" />
{:else}
<AccountMove moving={data.moving} plan={data.plan} failed={form?.failed} />
{/if}
</Page>
web/src/routes/new/+page.svelte+1−0
@@ -15,5 +15,6 @@
<p>This host starts groups only for the people it names.</p>
{:else}
<NewGroupForm failed={form?.failed} />
<p>Or <a href="/move">move an account you already have</a> here, to become a group.</p>
{/if}
</Page>