fix: preserve DM access precedence in Slack runtime · openclaw/openclaw@1d9959b
steipete
·
2026-04-29
·
via Recent Commits to openclaw:main
| Original file line number | Diff line number | Diff line change |
|---|
@@ -5,6 +5,7 @@ import {
|
5 | 5 | } from "openclaw/plugin-sdk/account-helpers"; |
6 | 6 | import { normalizeAccountId } from "openclaw/plugin-sdk/account-id"; |
7 | 7 | import { |
| 8 | +mapAllowFromEntries, |
8 | 9 | normalizeChannelDmPolicy, |
9 | 10 | resolveChannelDmAllowFrom, |
10 | 11 | resolveChannelDmPolicy, |
@@ -58,10 +59,11 @@ export function resolveDiscordAccountAllowFrom(params: {
|
58 | 59 | const accountConfig = resolveDiscordAccountConfig(params.cfg, accountId); |
59 | 60 | const rootConfig = params.cfg.channels?.discord as DiscordAccountConfig | undefined; |
60 | 61 | |
61 | | -return resolveChannelDmAllowFrom({ |
| 62 | +const allowFrom = resolveChannelDmAllowFrom({ |
62 | 63 | account: accountConfig as Record<string, unknown> | undefined, |
63 | 64 | parent: rootConfig as Record<string, unknown> | undefined, |
64 | | -}) as string[] | undefined; |
| 65 | +}); |
| 66 | +return allowFrom ? mapAllowFromEntries(allowFrom) : undefined; |
65 | 67 | } |
66 | 68 | |
67 | 69 | export function resolveDiscordAccountDmPolicy(params: { |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -110,4 +110,22 @@ describe("discordConfigAdapter", () => {
|
110 | 110 | "account-legacy", |
111 | 111 | ]); |
112 | 112 | }); |
| 113 | + |
| 114 | +it("coerces numeric allowFrom entries at the config boundary", () => { |
| 115 | +const cfg = { |
| 116 | +channels: { |
| 117 | +discord: { |
| 118 | +accounts: { |
| 119 | +default: { |
| 120 | +allowFrom: [123456789], |
| 121 | +}, |
| 122 | +}, |
| 123 | +}, |
| 124 | +}, |
| 125 | +} as unknown as OpenClawConfig; |
| 126 | + |
| 127 | +expect(discordConfigAdapter.resolveAllowFrom?.({ cfg, accountId: "default" })).toEqual([ |
| 128 | +"123456789", |
| 129 | +]); |
| 130 | +}); |
113 | 131 | }); |
| Original file line number | Diff line number | Diff line change |
|---|
|
1 | 1 | import type { OpenClawConfig } from "openclaw/plugin-sdk/config-types"; |
2 | 2 | import { describe, expect, it } from "vitest"; |
3 | | -import { resolveSlackAccount, resolveSlackAccountAllowFrom } from "./accounts.js"; |
| 3 | +import { |
| 4 | +resolveSlackAccount, |
| 5 | +resolveSlackAccountAllowFrom, |
| 6 | +resolveSlackAccountDmPolicy, |
| 7 | +} from "./accounts.js"; |
4 | 8 | |
5 | 9 | describe("resolveSlackAccount allowFrom precedence", () => { |
6 | 10 | it("uses configured defaultAccount when accountId is omitted", () => { |
@@ -126,6 +130,43 @@ describe("resolveSlackAccount allowFrom precedence", () => {
|
126 | 130 | |
127 | 131 | expect(resolveSlackAccountAllowFrom({ cfg, accountId: "work" })).toEqual(["account-legacy"]); |
128 | 132 | }); |
| 133 | + |
| 134 | +it("coerces numeric allowFrom entries at the config boundary", () => { |
| 135 | +const cfg = { |
| 136 | +channels: { |
| 137 | +slack: { |
| 138 | +accounts: { |
| 139 | +work: { |
| 140 | +botToken: "xoxb-work", |
| 141 | +appToken: "xapp-work", |
| 142 | +allowFrom: [12345], |
| 143 | +}, |
| 144 | +}, |
| 145 | +}, |
| 146 | +}, |
| 147 | +} as unknown as OpenClawConfig; |
| 148 | + |
| 149 | +expect(resolveSlackAccountAllowFrom({ cfg, accountId: "work" })).toEqual(["12345"]); |
| 150 | +}); |
| 151 | + |
| 152 | +it("resolves account legacy dm policy before inherited root policy", () => { |
| 153 | +const cfg = { |
| 154 | +channels: { |
| 155 | +slack: { |
| 156 | +dmPolicy: "open", |
| 157 | +accounts: { |
| 158 | +work: { |
| 159 | +botToken: "xoxb-work", |
| 160 | +appToken: "xapp-work", |
| 161 | +dm: { policy: "allowlist" }, |
| 162 | +}, |
| 163 | +}, |
| 164 | +}, |
| 165 | +}, |
| 166 | +} satisfies OpenClawConfig; |
| 167 | + |
| 168 | +expect(resolveSlackAccountDmPolicy({ cfg, accountId: "work" })).toBe("allowlist"); |
| 169 | +}); |
129 | 170 | }); |
130 | 171 | |
131 | 172 | describe("resolveSlackAccount active secret surfaces", () => { |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -6,6 +6,7 @@ import {
|
6 | 6 | type OpenClawConfig, |
7 | 7 | } from "openclaw/plugin-sdk/account-resolution"; |
8 | 8 | import { |
| 9 | +mapAllowFromEntries, |
9 | 10 | normalizeChannelDmPolicy, |
10 | 11 | resolveChannelDmAllowFrom, |
11 | 12 | resolveChannelDmPolicy, |
@@ -57,10 +58,11 @@ export function resolveSlackAccountAllowFrom(params: {
|
57 | 58 | ); |
58 | 59 | const accountConfig = params.cfg.channels?.slack?.accounts?.[accountId]; |
59 | 60 | const rootConfig = params.cfg.channels?.slack as SlackAccountConfig | undefined; |
60 | | -return resolveChannelDmAllowFrom({ |
| 61 | +const allowFrom = resolveChannelDmAllowFrom({ |
61 | 62 | account: accountConfig as Record<string, unknown> | undefined, |
62 | 63 | parent: rootConfig as Record<string, unknown> | undefined, |
63 | | -}) as string[] | undefined; |
| 64 | +}); |
| 65 | +return allowFrom ? mapAllowFromEntries(allowFrom) : undefined; |
64 | 66 | } |
65 | 67 | |
66 | 68 | export function resolveSlackAccountDmPolicy(params: { |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -22,7 +22,11 @@ import {
|
22 | 22 | import { normalizeResolvedSecretInputString } from "openclaw/plugin-sdk/secret-input"; |
23 | 23 | import { normalizeStringEntries } from "openclaw/plugin-sdk/text-runtime"; |
24 | 24 | import { installRequestBodyLimitGuard } from "openclaw/plugin-sdk/webhook-request-guards"; |
25 | | -import { resolveSlackAccount, resolveSlackAccountAllowFrom } from "../accounts.js"; |
| 25 | +import { |
| 26 | +resolveSlackAccount, |
| 27 | +resolveSlackAccountAllowFrom, |
| 28 | +resolveSlackAccountDmPolicy, |
| 29 | +} from "../accounts.js"; |
26 | 30 | import { resolveSlackWebClientOptions } from "../client-options.js"; |
27 | 31 | import { isSlackExecApprovalClientEnabled } from "../exec-approvals.js"; |
28 | 32 | import { normalizeSlackWebhookPath, registerSlackHttpHandler } from "../http/index.js"; |
@@ -148,7 +152,7 @@ export async function monitorSlackProvider(opts: MonitorSlackOpts = {}) {
|
148 | 152 | const dmConfig = slackCfg.dm; |
149 | 153 | |
150 | 154 | const dmEnabled = dmConfig?.enabled ?? true; |
151 | | -const dmPolicy = slackCfg.dmPolicy ?? dmConfig?.policy ?? "pairing"; |
| 155 | +const dmPolicy = resolveSlackAccountDmPolicy({ cfg, accountId: account.accountId }) ?? "pairing"; |
152 | 156 | let allowFrom = resolveSlackAccountAllowFrom({ cfg, accountId: account.accountId }); |
153 | 157 | const groupDmEnabled = dmConfig?.groupEnabled ?? false; |
154 | 158 | const groupDmChannels = dmConfig?.groupChannels; |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。