feat: add permissionMap and fallbackPermissions for group panel permission control

and remove old mode for forbid user speak
pull/146/merge
moonrailgun 2 years ago
parent 19b8a99486
commit e731c61964

@ -11,7 +11,6 @@
"k13bea6d2": "User not found",
"k1431a9e8": "Saving, please wait",
"k14565202": "Allow deletion of user information",
"k1596c75c": "Only allow specified users to speak",
"k1704ea49": "Install",
"k170859cb": "A communication platform completely exclusive to the private team",
"k17777797": "The panel is provided by the plugin",
@ -419,7 +418,6 @@
"kf8de33b7": "Plugin provider not found",
"kf9235c11": "Something went wrong",
"kf94465ba": "Invite Code",
"kf98fbe5e": "Forbid everyone to speak",
"kfa01c850": "No private message found",
"kfa493f3f": "Reply",
"kfa610536": "Alpha mode switch",

@ -11,7 +11,6 @@
"k13bea6d2": "没有找到用户",
"k1431a9e8": "正在保存, 请稍后",
"k14565202": "允许删除用户信息",
"k1596c75c": "仅允许指定用户发言",
"k1704ea49": "安装",
"k170859cb": "完全独属于私人团队的沟通平台",
"k17777797": "该面板由插件提供",
@ -419,7 +418,6 @@
"kf8de33b7": "未找到插件的提供者",
"kf9235c11": "出现了一些问题",
"kf94465ba": "邀请码",
"kf98fbe5e": "禁止所有人发言",
"kfa01c850": "找不到私信会话",
"kfa493f3f": "回复",
"kfa610536": "Alpha测试开关",

@ -11,10 +11,8 @@ import {
createMetaFormSchema,
MetaFormFieldMeta,
metaFormFieldSchema,
useMetaFormContext,
} from 'tailchat-design';
import type { GroupPanelValues } from './types';
import _compact from 'lodash/compact';
import _groupBy from 'lodash/groupBy';
import _mapValues from 'lodash/mapValues';
import { pluginGroupPanel } from '@/plugin/common';
@ -55,55 +53,7 @@ export function useGroupPanelFields(
groupId: string,
currentValues: Partial<GroupPanelValues>
) {
const disableSendMessageWithoutRender = useMemo(() => {
const DisableSendMessageWithoutComponent: React.FC = () => {
const groupMemberUUIDs = useGroupMemberIds(groupId);
const context = useMetaFormContext<any>();
return (
<UserSelector
allUserIds={groupMemberUUIDs}
onChange={(userIds) => {
context?.setValues({
...context.values,
disableSendMessageWithout: userIds,
});
}}
/>
);
};
DisableSendMessageWithoutComponent.displayName =
'DisableSendMessageWithoutComponent';
return DisableSendMessageWithoutComponent;
}, [groupId]);
const ret = useMemo(() => {
// NOTICE: 仅开发环境有这个配置
if (isDevelopment && currentValues.type === GroupPanelType.TEXT) {
return {
fields: _compact([
...baseFields,
{
type: 'checkbox',
name: 'disableSendMessage',
label: t('禁止所有人发言'),
},
currentValues.disableSendMessage === true && {
type: 'custom',
name: 'disableSendMessageWithout',
label: t('仅允许指定用户发言'),
render: disableSendMessageWithoutRender,
},
]) as MetaFormFieldMeta[],
schema: createMetaFormSchema({
...baseSchema,
disableSendMessage: metaFormFieldSchema.mixed(),
disableSendMessageWithout: metaFormFieldSchema.mixed(),
}),
};
}
let fields = baseFields;
let schema = baseSchema;

@ -78,6 +78,26 @@ export class GroupPanel {
*/
@prop()
meta?: object;
/**
*
*
*
* key idid
* value
*/
@prop()
permissionMap?: Record<string, string[]>;
/**
*
*
*/
@prop({
type: () => String,
default: () => [],
})
fallbackPermissions?: string[];
}
/**

@ -147,6 +147,8 @@ class GroupService extends TcService {
provider: { type: 'string', optional: true },
pluginPanelName: { type: 'string', optional: true },
meta: { type: 'object', optional: true },
permissionMap: { type: 'object', optional: true },
fallbackPermissions: { type: 'array', items: 'string', optional: true },
},
});
this.registerAction('deleteGroupPanel', this.deleteGroupPanel, {
@ -812,10 +814,21 @@ class GroupService extends TcService {
provider?: string;
pluginPanelName?: string;
meta?: object;
permissionMap?: object;
fallbackPermissions?: string[];
}>
) {
const { groupId, panelId, name, type, provider, pluginPanelName, meta } =
ctx.params;
const {
groupId,
panelId,
name,
type,
provider,
pluginPanelName,
meta,
permissionMap,
fallbackPermissions,
} = ctx.params;
const { t, userId } = ctx.meta;
const [hasPermission] = await call(ctx).checkUserPermissions(
@ -839,6 +852,8 @@ class GroupService extends TcService {
'panels.$[element].provider': provider,
'panels.$[element].pluginPanelName': pluginPanelName,
'panels.$[element].meta': meta,
'panels.$[element].permissionMap': permissionMap,
'panels.$[element].fallbackPermissions': fallbackPermissions,
},
},
{

Loading…
Cancel
Save