mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-18 17:17:26 +00:00
refactor: share route policy evaluation in chat monitors
This commit is contained in:
@@ -6,6 +6,7 @@ import {
|
||||
resolveChannelMatchConfig,
|
||||
type ChannelMatchSource,
|
||||
} from "../../channels/channel-config.js";
|
||||
import { evaluateGroupRouteAccessForPolicy } from "../../plugin-sdk/group-access.js";
|
||||
import { formatDiscordUserTag } from "./format.js";
|
||||
|
||||
export type DiscordAllowList = {
|
||||
@@ -512,20 +513,18 @@ export function isDiscordGroupAllowedByPolicy(params: {
|
||||
channelAllowlistConfigured: boolean;
|
||||
channelAllowed: boolean;
|
||||
}): boolean {
|
||||
const { groupPolicy, guildAllowlisted, channelAllowlistConfigured, channelAllowed } = params;
|
||||
if (groupPolicy === "disabled") {
|
||||
if (params.groupPolicy === "allowlist" && !params.guildAllowlisted) {
|
||||
return false;
|
||||
}
|
||||
if (groupPolicy === "open") {
|
||||
return true;
|
||||
}
|
||||
if (!guildAllowlisted) {
|
||||
return false;
|
||||
}
|
||||
if (!channelAllowlistConfigured) {
|
||||
return true;
|
||||
}
|
||||
return channelAllowed;
|
||||
|
||||
return evaluateGroupRouteAccessForPolicy({
|
||||
groupPolicy:
|
||||
params.groupPolicy === "allowlist" && !params.channelAllowlistConfigured
|
||||
? "open"
|
||||
: params.groupPolicy,
|
||||
routeAllowlistConfigured: params.channelAllowlistConfigured,
|
||||
routeMatched: params.channelAllowed,
|
||||
}).allowed;
|
||||
}
|
||||
|
||||
export function resolveGroupDmAllow(params: {
|
||||
|
||||
@@ -1,17 +1,13 @@
|
||||
import { evaluateGroupRouteAccessForPolicy } from "../../plugin-sdk/group-access.js";
|
||||
|
||||
export function isSlackChannelAllowedByPolicy(params: {
|
||||
groupPolicy: "open" | "disabled" | "allowlist";
|
||||
channelAllowlistConfigured: boolean;
|
||||
channelAllowed: boolean;
|
||||
}): boolean {
|
||||
const { groupPolicy, channelAllowlistConfigured, channelAllowed } = params;
|
||||
if (groupPolicy === "disabled") {
|
||||
return false;
|
||||
}
|
||||
if (groupPolicy === "open") {
|
||||
return true;
|
||||
}
|
||||
if (!channelAllowlistConfigured) {
|
||||
return false;
|
||||
}
|
||||
return channelAllowed;
|
||||
return evaluateGroupRouteAccessForPolicy({
|
||||
groupPolicy: params.groupPolicy,
|
||||
routeAllowlistConfigured: params.channelAllowlistConfigured,
|
||||
routeMatched: params.channelAllowed,
|
||||
}).allowed;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user