mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 15:30:47 +00:00
fix: preserve discord setup channel allowlists (#47788) (thanks @Eldersonar)
This commit is contained in:
@@ -27,13 +27,44 @@ const DISCORD_TOKEN_HELP_LINES = [
|
||||
`Docs: ${formatDocsLink("/discord", "discord")}`,
|
||||
];
|
||||
|
||||
type DiscordGuildChannelAllowlistEntry = {
|
||||
guildKey: string;
|
||||
channelKey?: string;
|
||||
};
|
||||
|
||||
type DiscordSetupAllowlistResolution = {
|
||||
resolved?: boolean;
|
||||
guildId?: string;
|
||||
channelId?: string;
|
||||
guildKey?: string;
|
||||
channelKey?: string;
|
||||
};
|
||||
|
||||
function mapDiscordSetupAllowlistEntries(resolved: unknown): DiscordGuildChannelAllowlistEntry[] {
|
||||
if (!Array.isArray(resolved)) {
|
||||
return [];
|
||||
}
|
||||
return resolved.flatMap((entry): DiscordGuildChannelAllowlistEntry[] => {
|
||||
if (!entry || typeof entry !== "object") {
|
||||
return [];
|
||||
}
|
||||
const row = entry as DiscordSetupAllowlistResolution;
|
||||
if (row.resolved === false) {
|
||||
return [];
|
||||
}
|
||||
const guildKey = normalizeOptionalString(row.guildId ?? row.guildKey);
|
||||
if (!guildKey) {
|
||||
return [];
|
||||
}
|
||||
const channelKey = normalizeOptionalString(row.channelId ?? row.channelKey);
|
||||
return channelKey ? [{ guildKey, channelKey }] : [{ guildKey }];
|
||||
});
|
||||
}
|
||||
|
||||
function setDiscordGuildChannelAllowlist(
|
||||
cfg: OpenClawConfig,
|
||||
accountId: string,
|
||||
entries: Array<{
|
||||
guildKey: string;
|
||||
channelKey?: string;
|
||||
}>,
|
||||
entries: DiscordGuildChannelAllowlistEntry[],
|
||||
): OpenClawConfig {
|
||||
const baseGuilds =
|
||||
accountId === DEFAULT_ACCOUNT_ID
|
||||
@@ -152,7 +183,8 @@ export function createDiscordSetupWizardBase(handlers: {
|
||||
cfg: OpenClawConfig;
|
||||
accountId: string;
|
||||
resolved: unknown;
|
||||
}) => setDiscordGuildChannelAllowlist(cfg, accountId, resolved as never),
|
||||
}) =>
|
||||
setDiscordGuildChannelAllowlist(cfg, accountId, mapDiscordSetupAllowlistEntries(resolved)),
|
||||
}),
|
||||
allowFrom: createAccountScopedAllowFromSection({
|
||||
channel,
|
||||
|
||||
@@ -94,3 +94,44 @@ describe("discordSetupWizard.status", () => {
|
||||
expect(configured).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe("discordSetupWizard.groupAccess", () => {
|
||||
it("writes resolved Discord channel rows to their selected guild and channel", () => {
|
||||
const next = discordSetupWizard.groupAccess?.applyAllowlist?.({
|
||||
cfg: {
|
||||
channels: {
|
||||
discord: {
|
||||
guilds: {
|
||||
existing: {
|
||||
channels: {
|
||||
keep: { enabled: true },
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
} as OpenClawConfig,
|
||||
accountId: "default",
|
||||
resolved: [
|
||||
{
|
||||
input: "OpenClaw/#triage",
|
||||
resolved: true,
|
||||
guildId: "guild-1",
|
||||
channelId: "channel-1",
|
||||
},
|
||||
{
|
||||
input: "missing",
|
||||
resolved: false,
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
expect(next?.channels?.discord?.guilds?.["guild-1"]?.channels?.["channel-1"]).toEqual({
|
||||
enabled: true,
|
||||
});
|
||||
expect(next?.channels?.discord?.guilds?.["*"]).toBeUndefined();
|
||||
expect(next?.channels?.discord?.guilds?.existing?.channels?.keep).toEqual({
|
||||
enabled: true,
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user