feat: 简单通知管理增加权限点

pull/49/head
moonrailgun 3 years ago
parent 33d48cd203
commit 88e706b49c

1
server/.gitignore vendored

@ -5,6 +5,7 @@ __uploads/
# 插件 # 插件
public/plugins/ public/plugins/
public/registry.json public/registry.json
public/registry-be.json
# Logs # Logs
logs logs

@ -20,7 +20,7 @@ regInspectService({
regPluginPermission({ regPluginPermission({
key: 'plugin.com.msgbyte.github.subscribe.manage', key: 'plugin.com.msgbyte.github.subscribe.manage',
title: 'Github 订阅管理', title: Translate.permissionTitle,
desc: '允许管理Github订阅列表', desc: Translate.permissionDesc,
default: false, default: false,
}); });

@ -61,4 +61,12 @@ export const Translate = {
'zh-CN': '文本频道不能为空', 'zh-CN': '文本频道不能为空',
'en-US': 'Text Panel Not Allowd Empty', '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',
}),
}; };

@ -3,12 +3,16 @@ import {
TcDbService, TcDbService,
TcContext, TcContext,
TcPureContext, TcPureContext,
call,
NoPermissionError,
} from 'tailchat-server-sdk'; } from 'tailchat-server-sdk';
import type { import type {
SimpleNotifyDocument, SimpleNotifyDocument,
SimpleNotifyModel, SimpleNotifyModel,
} from '../models/simplenotify'; } 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 { groupId, textPanelId } = ctx.params;
const { userId, t } = ctx.meta;
if (!groupId || !textPanelId) { if (!groupId || !textPanelId) {
throw new Error('参数不全'); throw new Error('参数不全');
} }
const isGroupOwner = await ctx.call('group.isGroupOwner', { const [hasPermission] = await call(ctx).checkUserPermissions(
groupId, groupId,
}); userId,
if (isGroupOwner !== true) { [PERMISSION_MANAGE]
throw new Error('没有操作权限'); );
if (!hasPermission) {
throw new NoPermissionError(t('没有操作权限'));
} }
// TODO: 需要检查textPanelId是否合法 // TODO: 需要检查textPanelId是否合法
@ -154,6 +161,16 @@ class SimpleNotifyService extends TcService {
}> }>
) { ) {
const { groupId, type } = ctx.params; 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 const docs = await this.adapter.model
.find({ .find({
@ -175,11 +192,15 @@ class SimpleNotifyService extends TcService {
}> }>
) { ) {
const { groupId, subscribeId } = ctx.params; const { groupId, subscribeId } = ctx.params;
const isGroupOwner = await ctx.call('group.isGroupOwner', { const { userId, t } = ctx.meta;
const [hasPermission] = await call(ctx).checkUserPermissions(
groupId, groupId,
}); userId,
if (isGroupOwner !== true) { [PERMISSION_MANAGE]
throw new Error('没有操作权限'); );
if (!hasPermission) {
throw new NoPermissionError(t('没有删除权限'));
} }
await this.adapter.model.deleteOne({ await this.adapter.model.deleteOne({

@ -32,7 +32,7 @@ export const AddGroupSubscribeModal: React.FC<{
textPanelId, textPanelId,
}); });
showToasts('Success', 'success'); showToasts(Translate.success, 'success');
props.onSuccess?.(); props.onSuccess?.();
}, },
[groupId, props.onSuccess] [groupId, props.onSuccess]

@ -1,4 +1,9 @@
import { regCustomPanel, Loadable, regInspectService } from '@capital/common'; import {
regCustomPanel,
Loadable,
regInspectService,
regPluginPermission,
} from '@capital/common';
import { Translate } from './translate'; import { Translate } from './translate';
regCustomPanel({ regCustomPanel({
@ -12,3 +17,10 @@ regInspectService({
name: 'plugin:com.msgbyte.simplenotify', name: 'plugin:com.msgbyte.simplenotify',
label: Translate.simplenotifyService, label: Translate.simplenotifyService,
}); });
regPluginPermission({
key: 'plugin.com.msgbyte.simplenotify.subscribe.manage',
title: Translate.permissionTitle,
desc: Translate.permissionDesc,
default: false,
});

@ -45,4 +45,12 @@ export const Translate = {
'zh-CN': '文本频道不能为空', 'zh-CN': '文本频道不能为空',
'en-US': 'Text Panel Not Allowd Empty', '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',
}),
}; };

@ -179,6 +179,32 @@ declare module '@capital/common' {
export const pluginPanelActions: any; export const pluginPanelActions: any;
export const regPluginPanelAction: 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;
} }
/** /**

Loading…
Cancel
Save