fix: honor account-scoped setup dm policy

This commit is contained in:
Tak Hoffman
2026-04-03 10:30:51 -05:00
parent c6b8109bd8
commit b1026a0b28
4 changed files with 183 additions and 10 deletions

View File

@@ -1,7 +1,7 @@
import {
addWildcardAllowFrom,
applySetupAccountConfigPatch,
createNestedChannelParsedAllowFromPrompt,
createNestedChannelDmPolicy,
createStandardChannelSetupStatus,
DEFAULT_ACCOUNT_ID,
formatDocsLink,
@@ -37,16 +37,49 @@ const promptAllowFrom = createNestedChannelParsedAllowFromPrompt({
}),
});
const googlechatDmPolicy: ChannelSetupDmPolicy = createNestedChannelDmPolicy({
const googlechatDmPolicy: ChannelSetupDmPolicy = {
label: "Google Chat",
channel,
section: "dm",
policyKey: "channels.googlechat.dm.policy",
allowFromKey: "channels.googlechat.dm.allowFrom",
getCurrent: (cfg) => cfg.channels?.googlechat?.dm?.policy ?? "pairing",
resolveConfigKeys: (_cfg, accountId) =>
accountId && accountId !== DEFAULT_ACCOUNT_ID
? {
policyKey: `channels.googlechat.accounts.${accountId}.dm.policy`,
allowFromKey: `channels.googlechat.accounts.${accountId}.dm.allowFrom`,
}
: {
policyKey: "channels.googlechat.dm.policy",
allowFromKey: "channels.googlechat.dm.allowFrom",
},
getCurrent: (cfg, accountId) =>
resolveGoogleChatAccount({
cfg,
accountId: accountId ?? DEFAULT_ACCOUNT_ID,
}).config.dm?.policy ?? "pairing",
setPolicy: (cfg, policy, accountId) => {
const resolvedAccountId = accountId ?? DEFAULT_ACCOUNT_ID;
const currentDm = resolveGoogleChatAccount({
cfg,
accountId: resolvedAccountId,
}).config.dm;
return applySetupAccountConfigPatch({
cfg,
channelKey: channel,
accountId: resolvedAccountId,
patch: {
dm: {
...currentDm,
policy,
...(policy === "open"
? { allowFrom: addWildcardAllowFrom(currentDm?.allowFrom) }
: {}),
},
},
});
},
promptAllowFrom,
enabled: true,
});
};
export { googlechatSetupAdapter } from "./setup-core.js";