mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-08 15:51:06 +00:00
fix: honor googlechat default allowFrom account
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import {
|
||||
addWildcardAllowFrom,
|
||||
applySetupAccountConfigPatch,
|
||||
createNestedChannelParsedAllowFromPrompt,
|
||||
createPromptParsedAllowFromForAccount,
|
||||
createStandardChannelSetupStatus,
|
||||
DEFAULT_ACCOUNT_ID,
|
||||
formatDocsLink,
|
||||
@@ -25,16 +25,27 @@ const ENV_SERVICE_ACCOUNT_FILE = "GOOGLE_CHAT_SERVICE_ACCOUNT_FILE";
|
||||
const USE_ENV_FLAG = "__googlechatUseEnv";
|
||||
const AUTH_METHOD_FLAG = "__googlechatAuthMethod";
|
||||
|
||||
const promptAllowFrom = createNestedChannelParsedAllowFromPrompt({
|
||||
channel,
|
||||
section: "dm",
|
||||
defaultAccountId: DEFAULT_ACCOUNT_ID,
|
||||
enabled: true,
|
||||
const promptAllowFrom = createPromptParsedAllowFromForAccount({
|
||||
defaultAccountId: resolveDefaultGoogleChatAccountId,
|
||||
message: "Google Chat allowFrom (users/<id> or raw email; avoid users/<email>)",
|
||||
placeholder: "users/123456789, name@example.com",
|
||||
parseEntries: (raw) => ({
|
||||
entries: mergeAllowFromEntries(undefined, splitSetupEntries(raw)),
|
||||
}),
|
||||
getExistingAllowFrom: ({ cfg, accountId }) =>
|
||||
resolveGoogleChatAccount({ cfg, accountId }).config.dm?.allowFrom ?? [],
|
||||
applyAllowFrom: ({ cfg, accountId, allowFrom }) =>
|
||||
applySetupAccountConfigPatch({
|
||||
cfg,
|
||||
channelKey: channel,
|
||||
accountId,
|
||||
patch: {
|
||||
dm: {
|
||||
...(resolveGoogleChatAccount({ cfg, accountId }).config.dm ?? {}),
|
||||
allowFrom,
|
||||
},
|
||||
},
|
||||
}),
|
||||
});
|
||||
|
||||
const googlechatDmPolicy: ChannelSetupDmPolicy = {
|
||||
|
||||
@@ -249,6 +249,41 @@ describe("googlechat setup", () => {
|
||||
expect(next?.channels?.googlechat?.accounts?.alerts?.dm?.policy).toBe("open");
|
||||
});
|
||||
|
||||
it("uses configured defaultAccount for omitted allowFrom prompt context", async () => {
|
||||
const prompter = {
|
||||
note: vi.fn(async () => {}),
|
||||
text: vi.fn(async () => "users/123456789"),
|
||||
};
|
||||
|
||||
const next = await googlechatPlugin.setupWizard?.dmPolicy?.promptAllowFrom?.({
|
||||
cfg: {
|
||||
channels: {
|
||||
googlechat: {
|
||||
defaultAccount: "alerts",
|
||||
dm: {
|
||||
allowFrom: ["users/root"],
|
||||
},
|
||||
accounts: {
|
||||
alerts: {
|
||||
serviceAccount: { client_email: "bot@example.com" },
|
||||
dm: {
|
||||
allowFrom: ["users/alerts"],
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
} as OpenClawConfig,
|
||||
// oxlint-disable-next-line typescript/no-explicit-any
|
||||
prompter: prompter as any,
|
||||
});
|
||||
|
||||
expect(next?.channels?.googlechat?.dm?.allowFrom).toEqual(["users/root"]);
|
||||
expect(next?.channels?.googlechat?.accounts?.alerts?.dm?.allowFrom).toEqual([
|
||||
"users/123456789",
|
||||
]);
|
||||
});
|
||||
|
||||
it('writes open DM policy to the named account and preserves inherited allowFrom with "*"', () => {
|
||||
const next = googlechatPlugin.setupWizard?.dmPolicy?.setPolicy(
|
||||
{
|
||||
|
||||
@@ -1344,7 +1344,7 @@ export function createTopLevelChannelParsedAllowFromPrompt(params: {
|
||||
export function createNestedChannelParsedAllowFromPrompt(params: {
|
||||
channel: string;
|
||||
section: string;
|
||||
defaultAccountId: string;
|
||||
defaultAccountId: string | ((cfg: OpenClawConfig) => string);
|
||||
enabled?: boolean;
|
||||
noteTitle?: string;
|
||||
noteLines?: string[];
|
||||
@@ -1360,7 +1360,10 @@ export function createNestedChannelParsedAllowFromPrompt(params: {
|
||||
...(params.enabled ? { enabled: true } : {}),
|
||||
});
|
||||
return createPromptParsedAllowFromForAccount({
|
||||
defaultAccountId: params.defaultAccountId,
|
||||
defaultAccountId:
|
||||
typeof params.defaultAccountId === "function"
|
||||
? params.defaultAccountId
|
||||
: () => params.defaultAccountId,
|
||||
...(params.noteTitle ? { noteTitle: params.noteTitle } : {}),
|
||||
...(params.noteLines ? { noteLines: params.noteLines } : {}),
|
||||
message: params.message,
|
||||
|
||||
Reference in New Issue
Block a user