refactor: share sender group policy evaluation
This commit is contained in:
@@ -3,6 +3,7 @@ import type {
|
||||
ChannelGroupContext,
|
||||
GroupToolPolicyConfig,
|
||||
} from "openclaw/plugin-sdk/feishu";
|
||||
import { evaluateSenderGroupAccessForPolicy } from "openclaw/plugin-sdk/feishu";
|
||||
import { normalizeFeishuTarget } from "./targets.js";
|
||||
import type { FeishuConfig, FeishuGroupConfig } from "./types.js";
|
||||
|
||||
@@ -98,14 +99,12 @@ export function isFeishuGroupAllowed(params: {
|
||||
senderIds?: Array<string | null | undefined>;
|
||||
senderName?: string | null;
|
||||
}): boolean {
|
||||
const { groupPolicy } = params;
|
||||
if (groupPolicy === "disabled") {
|
||||
return false;
|
||||
}
|
||||
if (groupPolicy === "open" || groupPolicy === "allowall") {
|
||||
return true;
|
||||
}
|
||||
return resolveFeishuAllowlistMatch(params).allowed;
|
||||
return evaluateSenderGroupAccessForPolicy({
|
||||
groupPolicy: params.groupPolicy === "allowall" ? "open" : params.groupPolicy,
|
||||
groupAllowFrom: params.allowFrom.map((entry) => String(entry)),
|
||||
senderId: params.senderId,
|
||||
isSenderAllowed: () => resolveFeishuAllowlistMatch(params).allowed,
|
||||
}).allowed;
|
||||
}
|
||||
|
||||
export function resolveFeishuReplyPolicy(params: {
|
||||
|
||||
@@ -10,6 +10,7 @@ import type {
|
||||
} from "openclaw/plugin-sdk/msteams";
|
||||
import {
|
||||
buildChannelKeyCandidates,
|
||||
evaluateSenderGroupAccessForPolicy,
|
||||
normalizeChannelSlug,
|
||||
resolveAllowlistMatchSimple,
|
||||
resolveToolsBySender,
|
||||
@@ -248,12 +249,10 @@ export function isMSTeamsGroupAllowed(params: {
|
||||
senderName?: string | null;
|
||||
allowNameMatching?: boolean;
|
||||
}): boolean {
|
||||
const { groupPolicy } = params;
|
||||
if (groupPolicy === "disabled") {
|
||||
return false;
|
||||
}
|
||||
if (groupPolicy === "open") {
|
||||
return true;
|
||||
}
|
||||
return resolveMSTeamsAllowlistMatch(params).allowed;
|
||||
return evaluateSenderGroupAccessForPolicy({
|
||||
groupPolicy: params.groupPolicy,
|
||||
groupAllowFrom: params.allowFrom.map((entry) => String(entry)),
|
||||
senderId: params.senderId,
|
||||
isSenderAllowed: () => resolveMSTeamsAllowlistMatch(params).allowed,
|
||||
}).allowed;
|
||||
}
|
||||
|
||||
@@ -57,6 +57,7 @@ export type { AnyAgentTool, OpenClawPluginApi } from "../plugins/types.js";
|
||||
export { DEFAULT_ACCOUNT_ID, normalizeAgentId } from "../routing/session-key.js";
|
||||
export type { RuntimeEnv } from "../runtime.js";
|
||||
export { formatDocsLink } from "../terminal/links.js";
|
||||
export { evaluateSenderGroupAccessForPolicy } from "./group-access.js";
|
||||
export type { WizardPrompter } from "../wizard/prompts.js";
|
||||
export { buildAgentMediaPayload } from "./agent-media-payload.js";
|
||||
export { readJsonFileWithFallback } from "./json-store.js";
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { evaluateSenderGroupAccessForPolicy } from "../plugin-sdk/group-access.js";
|
||||
import { normalizeE164 } from "../utils.js";
|
||||
|
||||
export type SignalSender =
|
||||
@@ -129,15 +130,10 @@ export function isSignalGroupAllowed(params: {
|
||||
allowFrom: string[];
|
||||
sender: SignalSender;
|
||||
}): boolean {
|
||||
const { groupPolicy, allowFrom, sender } = params;
|
||||
if (groupPolicy === "disabled") {
|
||||
return false;
|
||||
}
|
||||
if (groupPolicy === "open") {
|
||||
return true;
|
||||
}
|
||||
if (allowFrom.length === 0) {
|
||||
return false;
|
||||
}
|
||||
return isSignalSenderAllowed(sender, allowFrom);
|
||||
return evaluateSenderGroupAccessForPolicy({
|
||||
groupPolicy: params.groupPolicy,
|
||||
groupAllowFrom: params.allowFrom,
|
||||
senderId: params.sender.raw,
|
||||
isSenderAllowed: () => isSignalSenderAllowed(params.sender, params.allowFrom),
|
||||
}).allowed;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user