Skip to content

Commit

Permalink
feat: add view panel permission which can control panel display for d…
Browse files Browse the repository at this point in the history
…ifferent users #149
  • Loading branch information
moonrailgun committed Sep 19, 2023
1 parent 16cac37 commit c59e56c
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 0 deletions.
3 changes: 3 additions & 0 deletions client/shared/i18n/langs/en-US/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,7 @@
"kb7a57f24": "Plugin Registry Service",
"kb8021af2": "Disable create converse from group",
"kb8185132": "Or",
"kb86bd9c9": "View Panel",
"kb8ec7062": "Email verification passed",
"kb96b79c5": "Allow management of invitation links",
"kbc76781d": "No permission to send messages, please contact the group owner",
Expand All @@ -319,6 +320,7 @@
"kc6e50666": "Color Scheme",
"kc6f6df4": "Do you want to uninstall the plugin",
"kc74e5f62": "Search for members",
"kc77e00c7": "Allow members to view the panel",
"kc7cc96c8": "From",
"kc9283683": "Are you sure you want to delete the panel [{{name}}]",
"kc9bd3ad6": "Reset to default permissions",
Expand Down Expand Up @@ -367,6 +369,7 @@
"ke00c5a2f": "An open source IM for everyone",
"ke0131e71": "Recommended aspect: 16:9 | Recommended size: 1280x720",
"ke0161a83": "Reset to default address",
"ke03e2010": "No panel access",
"ke040edce": "No rendering method of this type found",
"ke071c620": "Allow members to manage users, such as banning, removing users, etc.",
"ke17b2c87": "Do not upload pictures that violate local laws and regulations",
Expand Down
3 changes: 3 additions & 0 deletions client/shared/i18n/langs/zh-CN/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,7 @@
"kb7a57f24": "插件中心服务",
"kb8021af2": "禁止在群组发起私信",
"kb8185132": "",
"kb86bd9c9": "查看面板",
"kb8ec7062": "邮箱验证通过",
"kb96b79c5": "允许管理邀请链接",
"kbc76781d": "没有发送消息的权限, 请联系群组所有者",
Expand All @@ -319,6 +320,7 @@
"kc6e50666": "配色方案",
"kc6f6df4": "是否要卸载插件",
"kc74e5f62": "搜索成员",
"kc77e00c7": "允许成员查看面板",
"kc7cc96c8": "来自",
"kc9283683": "确定要删除面板 【{{name}}】 么",
"kc9bd3ad6": "重置为默认权限",
Expand Down Expand Up @@ -367,6 +369,7 @@
"ke00c5a2f": "属于所有人的开源聊天工具",
"ke0131e71": "建议比例: 16:9 | 建议大小: 1280x720",
"ke0161a83": "重置为默认地址",
"ke03e2010": "没有面板访问权限",
"ke040edce": "没有找到该类型的渲染方式",
"ke071c620": "允许成员管理用户,如禁言、移除用户等操作",
"ke17b2c87": "请勿上传违反当地法律法规的图片",
Expand Down
8 changes: 8 additions & 0 deletions client/shared/utils/role-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export const PERMISSION = {
* 非插件的权限点都叫core
*/
core: {
viewPanel: 'core.viewPanel',
message: 'core.message',
invite: 'core.invite',
unlimitedInvite: 'core.unlimitedInvite',
Expand All @@ -60,6 +61,13 @@ export const PERMISSION = {
};

export const getPermissionList = (): PermissionItemType[] => [
{
key: PERMISSION.core.viewPanel,
title: t('查看面板'),
desc: t('允许成员查看面板'),
default: true,
panel: true,
},
{
key: PERMISSION.core.message,
title: t('发送消息'),
Expand Down
9 changes: 9 additions & 0 deletions client/web/src/routes/Main/Content/Group/Panel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ import React, { useEffect, useMemo } from 'react';
import {
GroupInfoContextProvider,
GroupPanelType,
PERMISSION,
t,
useGroupInfo,
useGroupPanelInfo,
useHasGroupPanelPermission,
} from 'tailchat-shared';
import { useGroupPanelParams } from './utils';

Expand Down Expand Up @@ -47,6 +49,9 @@ export const GroupPanelRender: React.FC<GroupPanelRenderProps> = React.memo(
[groupId, panelId]
);
useRecordGroupPanel(groupId, panelId);
const [viewPanelPermission] = useHasGroupPanelPermission(groupId, panelId, [
PERMISSION.core.viewPanel,
]);

if (groupInfo === null) {
return (
Expand All @@ -62,6 +67,10 @@ export const GroupPanelRender: React.FC<GroupPanelRenderProps> = React.memo(
return <Problem text={t('面板不存在')} />;
}

if (!viewPanelPermission) {
return <Problem text={t('没有面板访问权限')} />;
}

if (panelInfo.type === GroupPanelType.TEXT) {
return (
<GroupInfoContextProvider groupInfo={groupInfo}>
Expand Down
9 changes: 9 additions & 0 deletions client/web/src/routes/Main/Content/Group/SidebarItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ import {
GroupPanel,
GroupPanelType,
isValidStr,
PERMISSION,
showToasts,
t,
useAppDispatch,
useConverseAck,
useGroupInfo,
useHasGroupPanelPermission,
useUserNotifyMute,
} from 'tailchat-shared';
import { GroupPanelItem } from '@/components/GroupPanelItem';
Expand Down Expand Up @@ -44,11 +46,18 @@ export const SidebarItem: React.FC<{
panel.pluginPanelName ?? ''
);
const { checkIsMuted, toggleMute } = useUserNotifyMute();
const [viewPanelPermission] = useHasGroupPanelPermission(groupId, panelId, [
PERMISSION.core.viewPanel,
]);

if (!groupInfo) {
return <LoadingSpinner />;
}

if (!viewPanelPermission) {
return null;
}

const isPinned =
isValidStr(groupInfo.pinnedPanelId) && groupInfo.pinnedPanelId === panelId;

Expand Down

0 comments on commit c59e56c

Please sign in to comment.