refactor: share route policy evaluation in chat monitors

This commit is contained in:
Peter Steinberger
2026-03-07 23:13:06 +00:00
parent 8c15b8600c
commit 99d14a820a
2 changed files with 18 additions and 23 deletions

View File

@@ -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: {

View File

@@ -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;
}