diff --git a/server/.gitignore b/server/.gitignore index d1d15e1e..385bead9 100644 --- a/server/.gitignore +++ b/server/.gitignore @@ -5,6 +5,7 @@ __uploads/ # 插件 public/plugins/ public/registry.json +public/registry-be.json # Logs logs diff --git a/server/plugins/com.msgbyte.github/web/plugins/com.msgbyte.github/src/index.tsx b/server/plugins/com.msgbyte.github/web/plugins/com.msgbyte.github/src/index.tsx index 33533cff..a774cc34 100644 --- a/server/plugins/com.msgbyte.github/web/plugins/com.msgbyte.github/src/index.tsx +++ b/server/plugins/com.msgbyte.github/web/plugins/com.msgbyte.github/src/index.tsx @@ -20,7 +20,7 @@ regInspectService({ regPluginPermission({ key: 'plugin.com.msgbyte.github.subscribe.manage', - title: 'Github 订阅管理', - desc: '允许管理Github订阅列表', + title: Translate.permissionTitle, + desc: Translate.permissionDesc, default: false, }); diff --git a/server/plugins/com.msgbyte.github/web/plugins/com.msgbyte.github/src/translate.ts b/server/plugins/com.msgbyte.github/web/plugins/com.msgbyte.github/src/translate.ts index 66fb30f7..8954b4ec 100644 --- a/server/plugins/com.msgbyte.github/web/plugins/com.msgbyte.github/src/translate.ts +++ b/server/plugins/com.msgbyte.github/web/plugins/com.msgbyte.github/src/translate.ts @@ -61,4 +61,12 @@ export const Translate = { 'zh-CN': '文本频道不能为空', 'en-US': 'Text Panel Not Allowd Empty', }), + permissionTitle: localTrans({ + 'zh-CN': 'Github 订阅管理', + 'en-US': 'Github Subscribe Manager', + }), + permissionDesc: localTrans({ + 'zh-CN': '允许管理Github订阅列表', + 'en-US': 'Allows to manage Github subscription list', + }), }; diff --git a/server/plugins/com.msgbyte.simplenotify/services/simplenotify.service.ts b/server/plugins/com.msgbyte.simplenotify/services/simplenotify.service.ts index e9f4dbf4..5be2d62d 100644 --- a/server/plugins/com.msgbyte.simplenotify/services/simplenotify.service.ts +++ b/server/plugins/com.msgbyte.simplenotify/services/simplenotify.service.ts @@ -3,12 +3,16 @@ import { TcDbService, TcContext, TcPureContext, + call, + NoPermissionError, } from 'tailchat-server-sdk'; import type { SimpleNotifyDocument, SimpleNotifyModel, } from '../models/simplenotify'; +const PERMISSION_MANAGE = 'plugin.com.msgbyte.simplenotify.subscribe.manage'; + /** * 任务管理服务 */ @@ -89,16 +93,19 @@ class SimpleNotifyService extends TcService { }> ) { const { groupId, textPanelId } = ctx.params; + const { userId, t } = ctx.meta; if (!groupId || !textPanelId) { throw new Error('参数不全'); } - const isGroupOwner = await ctx.call('group.isGroupOwner', { + const [hasPermission] = await call(ctx).checkUserPermissions( groupId, - }); - if (isGroupOwner !== true) { - throw new Error('没有操作权限'); + userId, + [PERMISSION_MANAGE] + ); + if (!hasPermission) { + throw new NoPermissionError(t('没有操作权限')); } // TODO: 需要检查textPanelId是否合法 @@ -154,6 +161,16 @@ class SimpleNotifyService extends TcService { }> ) { const { groupId, type } = ctx.params; + const { userId, t } = ctx.meta; + + const [hasPermission] = await call(ctx).checkUserPermissions( + groupId, + userId, + [PERMISSION_MANAGE] + ); + if (!hasPermission) { + throw new NoPermissionError(t('没有查看权限')); + } const docs = await this.adapter.model .find({ @@ -175,11 +192,15 @@ class SimpleNotifyService extends TcService { }> ) { const { groupId, subscribeId } = ctx.params; - const isGroupOwner = await ctx.call('group.isGroupOwner', { + const { userId, t } = ctx.meta; + + const [hasPermission] = await call(ctx).checkUserPermissions( groupId, - }); - if (isGroupOwner !== true) { - throw new Error('没有操作权限'); + userId, + [PERMISSION_MANAGE] + ); + if (!hasPermission) { + throw new NoPermissionError(t('没有删除权限')); } await this.adapter.model.deleteOne({ diff --git a/server/plugins/com.msgbyte.simplenotify/web/plugins/com.msgbyte.simplenotify/src/GroupSubscribePanel/AddGroupSubscribeModal.tsx b/server/plugins/com.msgbyte.simplenotify/web/plugins/com.msgbyte.simplenotify/src/GroupSubscribePanel/AddGroupSubscribeModal.tsx index 2e43e398..48906e9a 100644 --- a/server/plugins/com.msgbyte.simplenotify/web/plugins/com.msgbyte.simplenotify/src/GroupSubscribePanel/AddGroupSubscribeModal.tsx +++ b/server/plugins/com.msgbyte.simplenotify/web/plugins/com.msgbyte.simplenotify/src/GroupSubscribePanel/AddGroupSubscribeModal.tsx @@ -32,7 +32,7 @@ export const AddGroupSubscribeModal: React.FC<{ textPanelId, }); - showToasts('Success', 'success'); + showToasts(Translate.success, 'success'); props.onSuccess?.(); }, [groupId, props.onSuccess] diff --git a/server/plugins/com.msgbyte.simplenotify/web/plugins/com.msgbyte.simplenotify/src/index.tsx b/server/plugins/com.msgbyte.simplenotify/web/plugins/com.msgbyte.simplenotify/src/index.tsx index 1ef15e7c..0b27eca4 100644 --- a/server/plugins/com.msgbyte.simplenotify/web/plugins/com.msgbyte.simplenotify/src/index.tsx +++ b/server/plugins/com.msgbyte.simplenotify/web/plugins/com.msgbyte.simplenotify/src/index.tsx @@ -1,4 +1,9 @@ -import { regCustomPanel, Loadable, regInspectService } from '@capital/common'; +import { + regCustomPanel, + Loadable, + regInspectService, + regPluginPermission, +} from '@capital/common'; import { Translate } from './translate'; regCustomPanel({ @@ -12,3 +17,10 @@ regInspectService({ name: 'plugin:com.msgbyte.simplenotify', label: Translate.simplenotifyService, }); + +regPluginPermission({ + key: 'plugin.com.msgbyte.simplenotify.subscribe.manage', + title: Translate.permissionTitle, + desc: Translate.permissionDesc, + default: false, +}); diff --git a/server/plugins/com.msgbyte.simplenotify/web/plugins/com.msgbyte.simplenotify/src/translate.ts b/server/plugins/com.msgbyte.simplenotify/web/plugins/com.msgbyte.simplenotify/src/translate.ts index c146c2c9..912d00ec 100644 --- a/server/plugins/com.msgbyte.simplenotify/web/plugins/com.msgbyte.simplenotify/src/translate.ts +++ b/server/plugins/com.msgbyte.simplenotify/web/plugins/com.msgbyte.simplenotify/src/translate.ts @@ -45,4 +45,12 @@ export const Translate = { 'zh-CN': '文本频道不能为空', 'en-US': 'Text Panel Not Allowd Empty', }), + permissionTitle: localTrans({ + 'zh-CN': '简单通知管理', + 'en-US': 'Simple Notify Manager', + }), + permissionDesc: localTrans({ + 'zh-CN': '允许管理群组简单通知机器人', + 'en-US': 'Allows admin groups to simply notify bots', + }), }; diff --git a/server/plugins/com.msgbyte.simplenotify/web/plugins/com.msgbyte.simplenotify/types/tailchat.d.ts b/server/plugins/com.msgbyte.simplenotify/web/plugins/com.msgbyte.simplenotify/types/tailchat.d.ts index c03dd919..d2a277b3 100644 --- a/server/plugins/com.msgbyte.simplenotify/web/plugins/com.msgbyte.simplenotify/types/tailchat.d.ts +++ b/server/plugins/com.msgbyte.simplenotify/web/plugins/com.msgbyte.simplenotify/types/tailchat.d.ts @@ -179,6 +179,32 @@ declare module '@capital/common' { export const pluginPanelActions: any; export const regPluginPanelAction: any; + + export const pluginPermission: any; + + export const regPluginPermission: (permission: { + /** + * 权限唯一key, 用于写入数据库 + * 如果为插件则权限点应当符合命名规范, 如: plugin.com.msgbyte.github.manage + */ + key: string; + /** + * 权限点显示名称 + */ + title: string; + /** + * 权限描述 + */ + desc: string; + /** + * 是否默认开启 + */ + default: boolean; + /** + * 是否依赖其他权限点 + */ + required?: string[]; + }) => void; } /**