Skip to content

Commit

Permalink
feat: add permissionMap and fallbackPermissions for group panel permi…
Browse files Browse the repository at this point in the history
…ssion control

and remove old mode for forbid user speak
  • Loading branch information
moonrailgun committed Sep 6, 2023
1 parent 19b8a99 commit e731c61
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 56 deletions.
2 changes: 0 additions & 2 deletions client/shared/i18n/langs/en-US/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
2 changes: 0 additions & 2 deletions client/shared/i18n/langs/zh-CN/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
"k13bea6d2": "没有找到用户",
"k1431a9e8": "正在保存, 请稍后",
"k14565202": "允许删除用户信息",
"k1596c75c": "仅允许指定用户发言",
"k1704ea49": "安装",
"k170859cb": "完全独属于私人团队的沟通平台",
"k17777797": "该面板由插件提供",
Expand Down Expand Up @@ -419,7 +418,6 @@
"kf8de33b7": "未找到插件的提供者",
"kf9235c11": "出现了一些问题",
"kf94465ba": "邀请码",
"kf98fbe5e": "禁止所有人发言",
"kfa01c850": "找不到私信会话",
"kfa493f3f": "回复",
"kfa610536": "Alpha测试开关",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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;

Expand Down
20 changes: 20 additions & 0 deletions server/models/group/group.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,26 @@ export class GroupPanel {
*/
@prop()
meta?: object;

/**
* 身份组或者用户的权限
* 如果没有设定则应用群组权限
*
* key 为身份组id或者用户id
* value 为权限字符串列表
*/
@prop()
permissionMap?: Record<string, string[]>;

/**
* 所有人的权限列表
* 如果没有设定则应用群组权限
*/
@prop({
type: () => String,
default: () => [],
})
fallbackPermissions?: string[];
}

/**
Expand Down
19 changes: 17 additions & 2 deletions server/services/core/group/group.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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, {
Expand Down Expand Up @@ -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(
Expand All @@ -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,
},
},
{
Expand Down

0 comments on commit e731c61

Please sign in to comment.