From ff7a7351150279303009fa9f54a6a5e059e6c834 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Mon, 16 Feb 2026 22:50:41 +0000 Subject: [PATCH] refactor(onboarding): share allowlist merge helpers --- src/channels/plugins/onboarding/discord.ts | 19 ++++--------------- src/channels/plugins/onboarding/helpers.ts | 8 ++++++++ src/channels/plugins/onboarding/slack.ts | 8 +++----- 3 files changed, 15 insertions(+), 20 deletions(-) diff --git a/src/channels/plugins/onboarding/discord.ts b/src/channels/plugins/onboarding/discord.ts index 23a87d0ca37..0b327050ccc 100644 --- a/src/channels/plugins/onboarding/discord.ts +++ b/src/channels/plugins/onboarding/discord.ts @@ -17,23 +17,14 @@ import { resolveDiscordUserAllowlist } from "../../../discord/resolve-users.js"; import { DEFAULT_ACCOUNT_ID, normalizeAccountId } from "../../../routing/session-key.js"; import { formatDocsLink } from "../../../terminal/links.js"; import { promptChannelAccessConfig } from "./channel-access.js"; -import { promptAccountId } from "./helpers.js"; - -function addDiscordWildcardAllowFrom(allowFrom?: string[] | null): string[] { - const next = (allowFrom ?? []).map((entry) => entry.trim()).filter(Boolean); - if (!next.includes("*")) { - next.push("*"); - } - return next; -} +import { addWildcardAllowFrom, mergeAllowFromEntries, promptAccountId } from "./helpers.js"; const channel = "discord" as const; function setDiscordDmPolicy(cfg: OpenClawConfig, dmPolicy: DmPolicy) { const existingAllowFrom = cfg.channels?.discord?.allowFrom ?? cfg.channels?.discord?.dm?.allowFrom; - const allowFrom = - dmPolicy === "open" ? addDiscordWildcardAllowFrom(existingAllowFrom) : undefined; + const allowFrom = dmPolicy === "open" ? addWildcardAllowFrom(existingAllowFrom) : undefined; return { ...cfg, channels: { @@ -221,9 +212,7 @@ async function promptDiscordAllowFrom(params: { ); continue; } - const unique = [...new Set([...existing.map((v) => String(v).trim()), ...ids])].filter( - Boolean, - ); + const unique = mergeAllowFromEntries(existing, ids); return setDiscordAllowFrom(params.cfg, unique); } @@ -244,7 +233,7 @@ async function promptDiscordAllowFrom(params: { continue; } const ids = results.map((res) => res.id as string); - const unique = [...new Set([...existing.map((v) => String(v).trim()).filter(Boolean), ...ids])]; + const unique = mergeAllowFromEntries(existing, ids); return setDiscordAllowFrom(params.cfg, unique); } } diff --git a/src/channels/plugins/onboarding/helpers.ts b/src/channels/plugins/onboarding/helpers.ts index e713904b8d8..4bed42fea1a 100644 --- a/src/channels/plugins/onboarding/helpers.ts +++ b/src/channels/plugins/onboarding/helpers.ts @@ -14,3 +14,11 @@ export function addWildcardAllowFrom( } return next; } + +export function mergeAllowFromEntries( + current: Array | null | undefined, + additions: Array, +): string[] { + const merged = [...(current ?? []), ...additions].map((v) => String(v).trim()).filter(Boolean); + return [...new Set(merged)]; +} diff --git a/src/channels/plugins/onboarding/slack.ts b/src/channels/plugins/onboarding/slack.ts index f1aa29b7c11..991a8c446c8 100644 --- a/src/channels/plugins/onboarding/slack.ts +++ b/src/channels/plugins/onboarding/slack.ts @@ -12,7 +12,7 @@ import { resolveSlackChannelAllowlist } from "../../../slack/resolve-channels.js import { resolveSlackUserAllowlist } from "../../../slack/resolve-users.js"; import { formatDocsLink } from "../../../terminal/links.js"; import { promptChannelAccessConfig } from "./channel-access.js"; -import { addWildcardAllowFrom, promptAccountId } from "./helpers.js"; +import { addWildcardAllowFrom, mergeAllowFromEntries, promptAccountId } from "./helpers.js"; const channel = "slack" as const; @@ -280,9 +280,7 @@ async function promptSlackAllowFrom(params: { ); continue; } - const unique = [...new Set([...existing.map((v) => String(v).trim()), ...ids])].filter( - Boolean, - ); + const unique = mergeAllowFromEntries(existing, ids); return setSlackAllowFrom(params.cfg, unique); } @@ -303,7 +301,7 @@ async function promptSlackAllowFrom(params: { continue; } const ids = results.map((res) => res.id as string); - const unique = [...new Set([...existing.map((v) => String(v).trim()).filter(Boolean), ...ids])]; + const unique = mergeAllowFromEntries(existing, ids); return setSlackAllowFrom(params.cfg, unique); } }