Skip to content

Commit 65579e8

Browse files
tellahoCarl
andauthored
feat(channels): administer channel members and roles (#453)
Signed-off-by: Taylor Ho <[email protected]> Signed-off-by: Carl <acda9e433d19dcd0e6b6840f7f4b98f3a56f1fab98049d444c087019e6d36560@buzz.block.builderlab.xyz> Co-authored-by: Carl <acda9e433d19dcd0e6b6840f7f4b98f3a56f1fab98049d444c087019e6d36560@buzz.block.builderlab.xyz>
1 parent 327ee68 commit 65579e8

42 files changed

Lines changed: 7626 additions & 370 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎dev/relay-broker-api.test.mjs‎

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2894,3 +2894,105 @@ test("details routes are narrow, require the live owner, and do not widen lifecy
28942894
await h.close();
28952895
}
28962896
});
2897+
2898+
test("member administration uses isolated shape-limited routes and the current community socket", async () => {
2899+
const h = await harness(success);
2900+
let live;
2901+
try {
2902+
const transport = await connectBrokerTransport(h.base);
2903+
const id = "11111111-1111-4111-8111-111111111111";
2904+
const target = getPublicKey(new Uint8Array(32).fill(5));
2905+
const signal = new AbortController().signal;
2906+
const template = {
2907+
kind: 9000,
2908+
created_at: 1700000000,
2909+
content: "",
2910+
tags: [
2911+
["h", id],
2912+
["p", target],
2913+
["role", "admin"],
2914+
],
2915+
};
2916+
const invalid = [
2917+
{ ...template, kind: 9002 },
2918+
{ ...template, content: "metadata" },
2919+
{
2920+
...template,
2921+
tags: [
2922+
["h", id],
2923+
["p", target],
2924+
["role", "owner"],
2925+
],
2926+
},
2927+
{
2928+
...template,
2929+
tags: [
2930+
["h", id],
2931+
["p", target],
2932+
["role", "bot"],
2933+
],
2934+
},
2935+
{
2936+
...template,
2937+
tags: [
2938+
["h", id],
2939+
["p", transport.viewer],
2940+
["role", "member"],
2941+
],
2942+
},
2943+
{
2944+
...template,
2945+
kind: 9001,
2946+
tags: [
2947+
["h", id],
2948+
["p", transport.viewer],
2949+
],
2950+
},
2951+
{ ...template, tags: [...template.tags, ["h", id]] },
2952+
{ ...template, tags: null },
2953+
{ ...template, tags: [null] },
2954+
];
2955+
for (const event of invalid)
2956+
for (const route of [
2957+
"member-administration-sign",
2958+
"member-administration-publish",
2959+
])
2960+
expect((await h.post(route, event)).status).toBe(400);
2961+
expect((await h.post("sign", template)).status).toBe(400);
2962+
const signed = await transport.memberAdministration.sign(template, signal);
2963+
expect(verifyEvent(signed)).toBe(true);
2964+
expect(signed).toMatchObject(template);
2965+
expect((await h.post("publish", signed)).status).toBe(400);
2966+
await expect(
2967+
transport.memberAdministration.publish(signed, signal),
2968+
).rejects.toBeInstanceOf(PublishRejected);
2969+
expect(h.publications).toHaveLength(0);
2970+
live = await openBrokerSocket(transport);
2971+
await transport.memberAdministration.publish(signed, signal);
2972+
const removal = await transport.memberAdministration.sign(
2973+
{ ...template, kind: 9001, tags: template.tags.slice(0, 2) },
2974+
signal,
2975+
);
2976+
expect(
2977+
(
2978+
await h.post("sign", {
2979+
...template,
2980+
kind: 9001,
2981+
tags: template.tags.slice(0, 2),
2982+
})
2983+
).status,
2984+
).toBe(400);
2985+
await transport.memberAdministration.publish(removal, signal);
2986+
const foreign = finalizeEvent(
2987+
structuredClone(template),
2988+
new Uint8Array(32).fill(5),
2989+
);
2990+
expect(
2991+
(await h.post("member-administration-publish", foreign)).status,
2992+
).toBe(400);
2993+
expect(h.publications).toHaveLength(2);
2994+
} finally {
2995+
live?.dispose();
2996+
await h.close();
2997+
}
2998+
});

‎dev/relay-broker.mjs‎

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { prepareMedia } from "./media-preparation.mjs";
1313
import { assertSidebarSortIntent, mutateSidebarSort } from "./sidebar-sort.mjs";
1414
import { readProjectGit } from "./project-git.mjs";
1515
import { parseGitRead } from "../src/features/projects/git.ts";
16+
import { validateMemberAdministrationTemplate } from "../src/features/channel-members/administration-protocol.ts";
1617
import { validateLifecycleTemplate } from "../src/features/relay/channel-lifecycle-protocol.ts";
1718
import { validateDetailsTemplate } from "../src/features/relay/channel-details-protocol.ts";
1819
import { validateArchiveRequestTemplate } from "../src/features/relay/identity-archive-protocol.ts";
@@ -1432,6 +1433,7 @@ export function relayBrokerPlugin({
14321433
],
14331434
channelLifecycle: true,
14341435
channelDetails: true,
1436+
memberAdministration: true,
14351437
identityArchives: true,
14361438
workflowReads: true,
14371439
projectGit: true,
@@ -1939,6 +1941,8 @@ export function relayBrokerPlugin({
19391941
"/api/relay/sign",
19401942
"/api/relay/channel-details-sign",
19411943
"/api/relay/channel-details-publish",
1944+
"/api/relay/member-administration-sign",
1945+
"/api/relay/member-administration-publish",
19421946
"/api/relay/channel-lifecycle-sign",
19431947
"/api/relay/channel-lifecycle-publish",
19441948
"/api/relay/identity-archive-sign",
@@ -2295,6 +2299,9 @@ export function relayBrokerPlugin({
22952299
const details =
22962300
route === "/api/relay/channel-details-sign" ||
22972301
route === "/api/relay/channel-details-publish";
2302+
const administration =
2303+
route === "/api/relay/member-administration-sign" ||
2304+
route === "/api/relay/member-administration-publish";
22982305
const lifecycle =
22992306
route === "/api/relay/channel-lifecycle-sign" ||
23002307
route === "/api/relay/channel-lifecycle-publish";
@@ -2304,15 +2311,26 @@ export function relayBrokerPlugin({
23042311
const signing =
23052312
route === "/api/relay/sign" ||
23062313
route === "/api/relay/channel-details-sign" ||
2314+
route === "/api/relay/member-administration-sign" ||
23072315
route === "/api/relay/channel-lifecycle-sign" ||
23082316
route === "/api/relay/identity-archive-sign";
23092317
const publishing =
23102318
route === "/api/relay/publish" ||
23112319
route === "/api/relay/channel-details-publish" ||
2320+
route === "/api/relay/member-administration-publish" ||
23122321
route === "/api/relay/channel-lifecycle-publish" ||
23132322
route === "/api/relay/identity-archive-publish";
23142323
if (signing || publishing) {
2315-
if (archive) {
2324+
if (administration) {
2325+
try {
2326+
validateMemberAdministrationTemplate(filters, viewer);
2327+
} catch {
2328+
return json(res, 400, {
2329+
error: "Invalid member administration command",
2330+
sent: false,
2331+
});
2332+
}
2333+
} else if (archive) {
23162334
try {
23172335
validateArchiveRequestTemplate(filters);
23182336
if (!(await getAuthority(relay)).archiveAuthority)

0 commit comments

Comments
 (0)