mirror of https://github.com/openclaw/openclaw.git
refactor: share open allowFrom config checks
This commit is contained in:
parent
38b09866b8
commit
55ebdce9c3
|
|
@ -9,6 +9,7 @@ import {
|
|||
requireOpenAllowFrom,
|
||||
} from "openclaw/plugin-sdk/irc";
|
||||
import { z } from "zod";
|
||||
import { requireChannelOpenAllowFrom } from "../../shared/config-schema-helpers.js";
|
||||
|
||||
const IrcGroupSchema = z
|
||||
.object({
|
||||
|
|
@ -69,12 +70,12 @@ export const IrcAccountSchemaBase = z
|
|||
.strict();
|
||||
|
||||
export const IrcAccountSchema = IrcAccountSchemaBase.superRefine((value, ctx) => {
|
||||
requireOpenAllowFrom({
|
||||
requireChannelOpenAllowFrom({
|
||||
channel: "irc",
|
||||
policy: value.dmPolicy,
|
||||
allowFrom: value.allowFrom,
|
||||
ctx,
|
||||
path: ["allowFrom"],
|
||||
message: 'channels.irc.dmPolicy="open" requires channels.irc.allowFrom to include "*"',
|
||||
requireOpenAllowFrom,
|
||||
});
|
||||
});
|
||||
|
||||
|
|
@ -82,11 +83,11 @@ export const IrcConfigSchema = IrcAccountSchemaBase.extend({
|
|||
accounts: z.record(z.string(), IrcAccountSchema.optional()).optional(),
|
||||
defaultAccount: z.string().optional(),
|
||||
}).superRefine((value, ctx) => {
|
||||
requireOpenAllowFrom({
|
||||
requireChannelOpenAllowFrom({
|
||||
channel: "irc",
|
||||
policy: value.dmPolicy,
|
||||
allowFrom: value.allowFrom,
|
||||
ctx,
|
||||
path: ["allowFrom"],
|
||||
message: 'channels.irc.dmPolicy="open" requires channels.irc.allowFrom to include "*"',
|
||||
requireOpenAllowFrom,
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import {
|
|||
requireOpenAllowFrom,
|
||||
} from "openclaw/plugin-sdk/mattermost";
|
||||
import { z } from "zod";
|
||||
import { requireChannelOpenAllowFrom } from "../../shared/config-schema-helpers.js";
|
||||
import { buildSecretInputSchema } from "./secret-input.js";
|
||||
|
||||
const MattermostSlashCommandsSchema = z
|
||||
|
|
@ -61,13 +62,12 @@ const MattermostAccountSchemaBase = z
|
|||
.strict();
|
||||
|
||||
const MattermostAccountSchema = MattermostAccountSchemaBase.superRefine((value, ctx) => {
|
||||
requireOpenAllowFrom({
|
||||
requireChannelOpenAllowFrom({
|
||||
channel: "mattermost",
|
||||
policy: value.dmPolicy,
|
||||
allowFrom: value.allowFrom,
|
||||
ctx,
|
||||
path: ["allowFrom"],
|
||||
message:
|
||||
'channels.mattermost.dmPolicy="open" requires channels.mattermost.allowFrom to include "*"',
|
||||
requireOpenAllowFrom,
|
||||
});
|
||||
});
|
||||
|
||||
|
|
@ -75,12 +75,11 @@ export const MattermostConfigSchema = MattermostAccountSchemaBase.extend({
|
|||
accounts: z.record(z.string(), MattermostAccountSchema.optional()).optional(),
|
||||
defaultAccount: z.string().optional(),
|
||||
}).superRefine((value, ctx) => {
|
||||
requireOpenAllowFrom({
|
||||
requireChannelOpenAllowFrom({
|
||||
channel: "mattermost",
|
||||
policy: value.dmPolicy,
|
||||
allowFrom: value.allowFrom,
|
||||
ctx,
|
||||
path: ["allowFrom"],
|
||||
message:
|
||||
'channels.mattermost.dmPolicy="open" requires channels.mattermost.allowFrom to include "*"',
|
||||
requireOpenAllowFrom,
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ import {
|
|||
requireOpenAllowFrom,
|
||||
} from "openclaw/plugin-sdk/nextcloud-talk";
|
||||
import { z } from "zod";
|
||||
import { requireChannelOpenAllowFrom } from "../../shared/config-schema-helpers.js";
|
||||
import { buildSecretInputSchema } from "./secret-input.js";
|
||||
|
||||
export const NextcloudTalkRoomSchema = z
|
||||
|
|
@ -48,13 +49,12 @@ export const NextcloudTalkAccountSchemaBase = z
|
|||
|
||||
export const NextcloudTalkAccountSchema = NextcloudTalkAccountSchemaBase.superRefine(
|
||||
(value, ctx) => {
|
||||
requireOpenAllowFrom({
|
||||
requireChannelOpenAllowFrom({
|
||||
channel: "nextcloud-talk",
|
||||
policy: value.dmPolicy,
|
||||
allowFrom: value.allowFrom,
|
||||
ctx,
|
||||
path: ["allowFrom"],
|
||||
message:
|
||||
'channels.nextcloud-talk.dmPolicy="open" requires channels.nextcloud-talk.allowFrom to include "*"',
|
||||
requireOpenAllowFrom,
|
||||
});
|
||||
},
|
||||
);
|
||||
|
|
@ -63,12 +63,11 @@ export const NextcloudTalkConfigSchema = NextcloudTalkAccountSchemaBase.extend({
|
|||
accounts: z.record(z.string(), NextcloudTalkAccountSchema.optional()).optional(),
|
||||
defaultAccount: z.string().optional(),
|
||||
}).superRefine((value, ctx) => {
|
||||
requireOpenAllowFrom({
|
||||
requireChannelOpenAllowFrom({
|
||||
channel: "nextcloud-talk",
|
||||
policy: value.dmPolicy,
|
||||
allowFrom: value.allowFrom,
|
||||
ctx,
|
||||
path: ["allowFrom"],
|
||||
message:
|
||||
'channels.nextcloud-talk.dmPolicy="open" requires channels.nextcloud-talk.allowFrom to include "*"',
|
||||
requireOpenAllowFrom,
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -0,0 +1,25 @@
|
|||
import type { z } from "zod";
|
||||
|
||||
type RequireOpenAllowFromFn = (params: {
|
||||
policy: unknown;
|
||||
allowFrom: unknown;
|
||||
ctx: z.RefinementCtx;
|
||||
path: string[];
|
||||
message: string;
|
||||
}) => void;
|
||||
|
||||
export function requireChannelOpenAllowFrom(params: {
|
||||
channel: string;
|
||||
policy: unknown;
|
||||
allowFrom: unknown;
|
||||
ctx: z.RefinementCtx;
|
||||
requireOpenAllowFrom: RequireOpenAllowFromFn;
|
||||
}) {
|
||||
params.requireOpenAllowFrom({
|
||||
policy: params.policy,
|
||||
allowFrom: params.allowFrom,
|
||||
ctx: params.ctx,
|
||||
path: ["allowFrom"],
|
||||
message: `channels.${params.channel}.dmPolicy="open" requires channels.${params.channel}.allowFrom to include "*"`,
|
||||
});
|
||||
}
|
||||
Loading…
Reference in New Issue