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.";