Discord: fix allowlist gating. Closes #961

This commit is contained in:
Shadow
2026-01-15 11:53:13 -06:00
parent 4de81ed6c4
commit 316e8b2eb2
7 changed files with 29 additions and 6 deletions

View File

@@ -215,6 +215,7 @@ describe("discord groupPolicy gating", () => {
expect(
isDiscordGroupAllowedByPolicy({
groupPolicy: "open",
guildAllowlisted: false,
channelAllowlistConfigured: false,
channelAllowed: false,
}),
@@ -225,26 +226,40 @@ describe("discord groupPolicy gating", () => {
expect(
isDiscordGroupAllowedByPolicy({
groupPolicy: "disabled",
guildAllowlisted: true,
channelAllowlistConfigured: true,
channelAllowed: true,
}),
).toBe(false);
});
it("blocks allowlist when no channel allowlist configured", () => {
it("blocks allowlist when guild is not allowlisted", () => {
expect(
isDiscordGroupAllowedByPolicy({
groupPolicy: "allowlist",
guildAllowlisted: false,
channelAllowlistConfigured: false,
channelAllowed: true,
}),
).toBe(false);
});
it("allows allowlist when guild allowlisted but no channel allowlist", () => {
expect(
isDiscordGroupAllowedByPolicy({
groupPolicy: "allowlist",
guildAllowlisted: true,
channelAllowlistConfigured: false,
channelAllowed: true,
}),
).toBe(true);
});
it("allows allowlist when channel is allowed", () => {
expect(
isDiscordGroupAllowedByPolicy({
groupPolicy: "allowlist",
guildAllowlisted: true,
channelAllowlistConfigured: true,
channelAllowed: true,
}),
@@ -255,6 +270,7 @@ describe("discord groupPolicy gating", () => {
expect(
isDiscordGroupAllowedByPolicy({
groupPolicy: "allowlist",
guildAllowlisted: true,
channelAllowlistConfigured: true,
channelAllowed: false,
}),

View File

@@ -197,13 +197,15 @@ export function resolveDiscordShouldRequireMention(params: {
export function isDiscordGroupAllowedByPolicy(params: {
groupPolicy: "open" | "disabled" | "allowlist";
guildAllowlisted: boolean;
channelAllowlistConfigured: boolean;
channelAllowed: boolean;
}): boolean {
const { groupPolicy, channelAllowlistConfigured, channelAllowed } = params;
const { groupPolicy, guildAllowlisted, channelAllowlistConfigured, channelAllowed } = params;
if (groupPolicy === "disabled") return false;
if (groupPolicy === "open") return true;
if (!channelAllowlistConfigured) return false;
if (!guildAllowlisted) return false;
if (!channelAllowlistConfigured) return true;
return channelAllowed;
}

View File

@@ -260,6 +260,7 @@ export async function preflightDiscordMessage(
isGuildMessage &&
!isDiscordGroupAllowedByPolicy({
groupPolicy: params.groupPolicy,
guildAllowlisted: Boolean(guildInfo),
channelAllowlistConfigured,
channelAllowed,
})

View File

@@ -448,6 +448,7 @@ async function dispatchDiscordCommandInteraction(params: {
const channelAllowed = channelConfig?.allowed !== false;
const allowByPolicy = isDiscordGroupAllowedByPolicy({
groupPolicy: discordConfig?.groupPolicy ?? "open",
guildAllowlisted: Boolean(guildInfo),
channelAllowlistConfigured,
channelAllowed,
});