mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-30 04:55:44 +00:00
refactor: share open allowFrom config checks
This commit is contained in:
@@ -9,6 +9,7 @@ import {
|
|||||||
requireOpenAllowFrom,
|
requireOpenAllowFrom,
|
||||||
} from "openclaw/plugin-sdk/irc";
|
} from "openclaw/plugin-sdk/irc";
|
||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
|
import { requireChannelOpenAllowFrom } from "../../shared/config-schema-helpers.js";
|
||||||
|
|
||||||
const IrcGroupSchema = z
|
const IrcGroupSchema = z
|
||||||
.object({
|
.object({
|
||||||
@@ -69,12 +70,12 @@ export const IrcAccountSchemaBase = z
|
|||||||
.strict();
|
.strict();
|
||||||
|
|
||||||
export const IrcAccountSchema = IrcAccountSchemaBase.superRefine((value, ctx) => {
|
export const IrcAccountSchema = IrcAccountSchemaBase.superRefine((value, ctx) => {
|
||||||
requireOpenAllowFrom({
|
requireChannelOpenAllowFrom({
|
||||||
|
channel: "irc",
|
||||||
policy: value.dmPolicy,
|
policy: value.dmPolicy,
|
||||||
allowFrom: value.allowFrom,
|
allowFrom: value.allowFrom,
|
||||||
ctx,
|
ctx,
|
||||||
path: ["allowFrom"],
|
requireOpenAllowFrom,
|
||||||
message: 'channels.irc.dmPolicy="open" requires channels.irc.allowFrom to include "*"',
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -82,11 +83,11 @@ export const IrcConfigSchema = IrcAccountSchemaBase.extend({
|
|||||||
accounts: z.record(z.string(), IrcAccountSchema.optional()).optional(),
|
accounts: z.record(z.string(), IrcAccountSchema.optional()).optional(),
|
||||||
defaultAccount: z.string().optional(),
|
defaultAccount: z.string().optional(),
|
||||||
}).superRefine((value, ctx) => {
|
}).superRefine((value, ctx) => {
|
||||||
requireOpenAllowFrom({
|
requireChannelOpenAllowFrom({
|
||||||
|
channel: "irc",
|
||||||
policy: value.dmPolicy,
|
policy: value.dmPolicy,
|
||||||
allowFrom: value.allowFrom,
|
allowFrom: value.allowFrom,
|
||||||
ctx,
|
ctx,
|
||||||
path: ["allowFrom"],
|
requireOpenAllowFrom,
|
||||||
message: 'channels.irc.dmPolicy="open" requires channels.irc.allowFrom to include "*"',
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import {
|
|||||||
requireOpenAllowFrom,
|
requireOpenAllowFrom,
|
||||||
} from "openclaw/plugin-sdk/mattermost";
|
} from "openclaw/plugin-sdk/mattermost";
|
||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
|
import { requireChannelOpenAllowFrom } from "../../shared/config-schema-helpers.js";
|
||||||
import { buildSecretInputSchema } from "./secret-input.js";
|
import { buildSecretInputSchema } from "./secret-input.js";
|
||||||
|
|
||||||
const MattermostSlashCommandsSchema = z
|
const MattermostSlashCommandsSchema = z
|
||||||
@@ -61,13 +62,12 @@ const MattermostAccountSchemaBase = z
|
|||||||
.strict();
|
.strict();
|
||||||
|
|
||||||
const MattermostAccountSchema = MattermostAccountSchemaBase.superRefine((value, ctx) => {
|
const MattermostAccountSchema = MattermostAccountSchemaBase.superRefine((value, ctx) => {
|
||||||
requireOpenAllowFrom({
|
requireChannelOpenAllowFrom({
|
||||||
|
channel: "mattermost",
|
||||||
policy: value.dmPolicy,
|
policy: value.dmPolicy,
|
||||||
allowFrom: value.allowFrom,
|
allowFrom: value.allowFrom,
|
||||||
ctx,
|
ctx,
|
||||||
path: ["allowFrom"],
|
requireOpenAllowFrom,
|
||||||
message:
|
|
||||||
'channels.mattermost.dmPolicy="open" requires channels.mattermost.allowFrom to include "*"',
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -75,12 +75,11 @@ export const MattermostConfigSchema = MattermostAccountSchemaBase.extend({
|
|||||||
accounts: z.record(z.string(), MattermostAccountSchema.optional()).optional(),
|
accounts: z.record(z.string(), MattermostAccountSchema.optional()).optional(),
|
||||||
defaultAccount: z.string().optional(),
|
defaultAccount: z.string().optional(),
|
||||||
}).superRefine((value, ctx) => {
|
}).superRefine((value, ctx) => {
|
||||||
requireOpenAllowFrom({
|
requireChannelOpenAllowFrom({
|
||||||
|
channel: "mattermost",
|
||||||
policy: value.dmPolicy,
|
policy: value.dmPolicy,
|
||||||
allowFrom: value.allowFrom,
|
allowFrom: value.allowFrom,
|
||||||
ctx,
|
ctx,
|
||||||
path: ["allowFrom"],
|
requireOpenAllowFrom,
|
||||||
message:
|
|
||||||
'channels.mattermost.dmPolicy="open" requires channels.mattermost.allowFrom to include "*"',
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import {
|
|||||||
requireOpenAllowFrom,
|
requireOpenAllowFrom,
|
||||||
} from "openclaw/plugin-sdk/nextcloud-talk";
|
} from "openclaw/plugin-sdk/nextcloud-talk";
|
||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
|
import { requireChannelOpenAllowFrom } from "../../shared/config-schema-helpers.js";
|
||||||
import { buildSecretInputSchema } from "./secret-input.js";
|
import { buildSecretInputSchema } from "./secret-input.js";
|
||||||
|
|
||||||
export const NextcloudTalkRoomSchema = z
|
export const NextcloudTalkRoomSchema = z
|
||||||
@@ -48,13 +49,12 @@ export const NextcloudTalkAccountSchemaBase = z
|
|||||||
|
|
||||||
export const NextcloudTalkAccountSchema = NextcloudTalkAccountSchemaBase.superRefine(
|
export const NextcloudTalkAccountSchema = NextcloudTalkAccountSchemaBase.superRefine(
|
||||||
(value, ctx) => {
|
(value, ctx) => {
|
||||||
requireOpenAllowFrom({
|
requireChannelOpenAllowFrom({
|
||||||
|
channel: "nextcloud-talk",
|
||||||
policy: value.dmPolicy,
|
policy: value.dmPolicy,
|
||||||
allowFrom: value.allowFrom,
|
allowFrom: value.allowFrom,
|
||||||
ctx,
|
ctx,
|
||||||
path: ["allowFrom"],
|
requireOpenAllowFrom,
|
||||||
message:
|
|
||||||
'channels.nextcloud-talk.dmPolicy="open" requires channels.nextcloud-talk.allowFrom to include "*"',
|
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
@@ -63,12 +63,11 @@ export const NextcloudTalkConfigSchema = NextcloudTalkAccountSchemaBase.extend({
|
|||||||
accounts: z.record(z.string(), NextcloudTalkAccountSchema.optional()).optional(),
|
accounts: z.record(z.string(), NextcloudTalkAccountSchema.optional()).optional(),
|
||||||
defaultAccount: z.string().optional(),
|
defaultAccount: z.string().optional(),
|
||||||
}).superRefine((value, ctx) => {
|
}).superRefine((value, ctx) => {
|
||||||
requireOpenAllowFrom({
|
requireChannelOpenAllowFrom({
|
||||||
|
channel: "nextcloud-talk",
|
||||||
policy: value.dmPolicy,
|
policy: value.dmPolicy,
|
||||||
allowFrom: value.allowFrom,
|
allowFrom: value.allowFrom,
|
||||||
ctx,
|
ctx,
|
||||||
path: ["allowFrom"],
|
requireOpenAllowFrom,
|
||||||
message:
|
|
||||||
'channels.nextcloud-talk.dmPolicy="open" requires channels.nextcloud-talk.allowFrom to include "*"',
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
25
extensions/shared/config-schema-helpers.ts
Normal file
25
extensions/shared/config-schema-helpers.ts
Normal file
@@ -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 "*"`,
|
||||||
|
});
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user