From b9176f9b0189d225cfadb1cca003cff649623f2d Mon Sep 17 00:00:00 2001 From: Shani Singh Date: Fri, 20 Nov 2026 12:05:12 +0530 Subject: [PATCH] fix(desktop): stop offering guests the add-members search The relay's kind:9000 rule (buzz_core::channel::decide_member_put) refuses every add from a guest since announce channels (#8143): a guest can read and leave but not write, and adding people is a write. The desktop's mirror of that rule, canAddChannelMembers, still allowed any active member of a private channel and anyone in an open channel, so a guest was offered the add-members search and every add they picked was rejected by the relay. canAddChannelMembers now returns false for a guest, as the relay does. The denial notice says the add needs a member who can post, which also reads correctly for a guest. Signed-off-by: Shani Singh --- .../lib/channelMemberAdmission.test.mjs | 18 ++++++++++++++++-- .../channels/lib/channelMemberAdmission.ts | 14 ++++++++------ 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/desktop/src/features/channels/lib/channelMemberAdmission.test.mjs b/desktop/src/features/channels/lib/channelMemberAdmission.test.mjs index 4f705d0f405..0b1f7644b14 100644 --- a/desktop/src/features/channels/lib/channelMemberAdmission.test.mjs +++ b/desktop/src/features/channels/lib/channelMemberAdmission.test.mjs @@ -22,8 +22,8 @@ test("open channels accept adds from anyone, member or not", () => { ); }); -test("private channels accept adds from every active member role", () => { - for (const selfRole of ["owner", "admin", "member", "bot", "guest"]) { +test("private channels accept adds from every active role that can post", () => { + for (const selfRole of ["owner", "admin", "member", "bot"]) { assert.equal( canAddChannelMembers({ channelType: "stream", @@ -46,6 +46,20 @@ test("private channels accept adds from every active member role", () => { ); }); +test("guests never add anyone, as the relay's decide_member_put refuses", () => { + for (const visibility of ["open", "private"]) { + assert.equal( + canAddChannelMembers({ + channelType: "stream", + visibility, + selfRole: "guest", + }), + false, + `a guest must not be offered adds (${visibility} channel)`, + ); + } +}); + test("DMs never accept adds, even from an owner", () => { assert.equal( canAddChannelMembers({ diff --git a/desktop/src/features/channels/lib/channelMemberAdmission.ts b/desktop/src/features/channels/lib/channelMemberAdmission.ts index 7ef15c6b68c..d7723c4b84a 100644 --- a/desktop/src/features/channels/lib/channelMemberAdmission.ts +++ b/desktop/src/features/channels/lib/channelMemberAdmission.ts @@ -1,11 +1,13 @@ /** * Client mirror of the relay's kind:9000 authority for adding *another* - * identity to a channel (`validate_admin_event` + `buzz_db::channel::add_member`): + * identity to a channel (`buzz_core::channel::decide_member_put`): * * - DMs: nobody — membership is fixed at creation. - * - Open channels: anyone, member or not. - * - Private channels: any active member. The relay separately reserves elevated - * role grants and active-role changes for owners/admins. + * - Guests: never. A guest can read and leave but not write, and adding + * people is a write. + * - Open channels: anyone else, member or not. + * - Private channels: any other active member. The relay separately reserves + * elevated role grants and active-role changes for owners/admins. * * Unknown visibility fails closed — the relay is the authority and a hidden * button is cheaper than an opaque rejection. @@ -19,7 +21,7 @@ export function canAddChannelMembers({ visibility?: string | null; selfRole?: string | null; }): boolean { - if (channelType === "dm") { + if (channelType === "dm" || selfRole === "guest") { return false; } @@ -36,4 +38,4 @@ export function canAddChannelMembers({ /** Explains a denied add so the user isn't left guessing at a missing button. */ export const PRIVATE_CHANNEL_ADD_DENIED_MESSAGE = - "Only channel members can add people to a private channel."; + "Only channel members who can post can add people to a private channel.";