feat: add view panel permission which can control panel display for different users #149

pull/146/merge
moonrailgun 2 years ago
parent 16cac375d1
commit c59e56c31a

@ -298,6 +298,7 @@
"kb7a57f24": "Plugin Registry Service", "kb7a57f24": "Plugin Registry Service",
"kb8021af2": "Disable create converse from group", "kb8021af2": "Disable create converse from group",
"kb8185132": "Or", "kb8185132": "Or",
"kb86bd9c9": "View Panel",
"kb8ec7062": "Email verification passed", "kb8ec7062": "Email verification passed",
"kb96b79c5": "Allow management of invitation links", "kb96b79c5": "Allow management of invitation links",
"kbc76781d": "No permission to send messages, please contact the group owner", "kbc76781d": "No permission to send messages, please contact the group owner",
@ -319,6 +320,7 @@
"kc6e50666": "Color Scheme", "kc6e50666": "Color Scheme",
"kc6f6df4": "Do you want to uninstall the plugin", "kc6f6df4": "Do you want to uninstall the plugin",
"kc74e5f62": "Search for members", "kc74e5f62": "Search for members",
"kc77e00c7": "Allow members to view the panel",
"kc7cc96c8": "From", "kc7cc96c8": "From",
"kc9283683": "Are you sure you want to delete the panel [{{name}}]", "kc9283683": "Are you sure you want to delete the panel [{{name}}]",
"kc9bd3ad6": "Reset to default permissions", "kc9bd3ad6": "Reset to default permissions",
@ -367,6 +369,7 @@
"ke00c5a2f": "An open source IM for everyone", "ke00c5a2f": "An open source IM for everyone",
"ke0131e71": "Recommended aspect: 16:9 | Recommended size: 1280x720", "ke0131e71": "Recommended aspect: 16:9 | Recommended size: 1280x720",
"ke0161a83": "Reset to default address", "ke0161a83": "Reset to default address",
"ke03e2010": "No panel access",
"ke040edce": "No rendering method of this type found", "ke040edce": "No rendering method of this type found",
"ke071c620": "Allow members to manage users, such as banning, removing users, etc.", "ke071c620": "Allow members to manage users, such as banning, removing users, etc.",
"ke17b2c87": "Do not upload pictures that violate local laws and regulations", "ke17b2c87": "Do not upload pictures that violate local laws and regulations",

@ -298,6 +298,7 @@
"kb7a57f24": "插件中心服务", "kb7a57f24": "插件中心服务",
"kb8021af2": "禁止在群组发起私信", "kb8021af2": "禁止在群组发起私信",
"kb8185132": "或", "kb8185132": "或",
"kb86bd9c9": "查看面板",
"kb8ec7062": "邮箱验证通过", "kb8ec7062": "邮箱验证通过",
"kb96b79c5": "允许管理邀请链接", "kb96b79c5": "允许管理邀请链接",
"kbc76781d": "没有发送消息的权限, 请联系群组所有者", "kbc76781d": "没有发送消息的权限, 请联系群组所有者",
@ -319,6 +320,7 @@
"kc6e50666": "配色方案", "kc6e50666": "配色方案",
"kc6f6df4": "是否要卸载插件", "kc6f6df4": "是否要卸载插件",
"kc74e5f62": "搜索成员", "kc74e5f62": "搜索成员",
"kc77e00c7": "允许成员查看面板",
"kc7cc96c8": "来自", "kc7cc96c8": "来自",
"kc9283683": "确定要删除面板 【{{name}}】 么", "kc9283683": "确定要删除面板 【{{name}}】 么",
"kc9bd3ad6": "重置为默认权限", "kc9bd3ad6": "重置为默认权限",
@ -367,6 +369,7 @@
"ke00c5a2f": "属于所有人的开源聊天工具", "ke00c5a2f": "属于所有人的开源聊天工具",
"ke0131e71": "建议比例: 16:9 | 建议大小: 1280x720", "ke0131e71": "建议比例: 16:9 | 建议大小: 1280x720",
"ke0161a83": "重置为默认地址", "ke0161a83": "重置为默认地址",
"ke03e2010": "没有面板访问权限",
"ke040edce": "没有找到该类型的渲染方式", "ke040edce": "没有找到该类型的渲染方式",
"ke071c620": "允许成员管理用户,如禁言、移除用户等操作", "ke071c620": "允许成员管理用户,如禁言、移除用户等操作",
"ke17b2c87": "请勿上传违反当地法律法规的图片", "ke17b2c87": "请勿上传违反当地法律法规的图片",

@ -45,6 +45,7 @@ export const PERMISSION = {
* core * core
*/ */
core: { core: {
viewPanel: 'core.viewPanel',
message: 'core.message', message: 'core.message',
invite: 'core.invite', invite: 'core.invite',
unlimitedInvite: 'core.unlimitedInvite', unlimitedInvite: 'core.unlimitedInvite',
@ -60,6 +61,13 @@ export const PERMISSION = {
}; };
export const getPermissionList = (): PermissionItemType[] => [ export const getPermissionList = (): PermissionItemType[] => [
{
key: PERMISSION.core.viewPanel,
title: t('查看面板'),
desc: t('允许成员查看面板'),
default: true,
panel: true,
},
{ {
key: PERMISSION.core.message, key: PERMISSION.core.message,
title: t('发送消息'), title: t('发送消息'),

@ -8,9 +8,11 @@ import React, { useEffect, useMemo } from 'react';
import { import {
GroupInfoContextProvider, GroupInfoContextProvider,
GroupPanelType, GroupPanelType,
PERMISSION,
t, t,
useGroupInfo, useGroupInfo,
useGroupPanelInfo, useGroupPanelInfo,
useHasGroupPanelPermission,
} from 'tailchat-shared'; } from 'tailchat-shared';
import { useGroupPanelParams } from './utils'; import { useGroupPanelParams } from './utils';
@ -47,6 +49,9 @@ export const GroupPanelRender: React.FC<GroupPanelRenderProps> = React.memo(
[groupId, panelId] [groupId, panelId]
); );
useRecordGroupPanel(groupId, panelId); useRecordGroupPanel(groupId, panelId);
const [viewPanelPermission] = useHasGroupPanelPermission(groupId, panelId, [
PERMISSION.core.viewPanel,
]);
if (groupInfo === null) { if (groupInfo === null) {
return ( return (
@ -62,6 +67,10 @@ export const GroupPanelRender: React.FC<GroupPanelRenderProps> = React.memo(
return <Problem text={t('面板不存在')} />; return <Problem text={t('面板不存在')} />;
} }
if (!viewPanelPermission) {
return <Problem text={t('没有面板访问权限')} />;
}
if (panelInfo.type === GroupPanelType.TEXT) { if (panelInfo.type === GroupPanelType.TEXT) {
return ( return (
<GroupInfoContextProvider groupInfo={groupInfo}> <GroupInfoContextProvider groupInfo={groupInfo}>

@ -4,11 +4,13 @@ import {
GroupPanel, GroupPanel,
GroupPanelType, GroupPanelType,
isValidStr, isValidStr,
PERMISSION,
showToasts, showToasts,
t, t,
useAppDispatch, useAppDispatch,
useConverseAck, useConverseAck,
useGroupInfo, useGroupInfo,
useHasGroupPanelPermission,
useUserNotifyMute, useUserNotifyMute,
} from 'tailchat-shared'; } from 'tailchat-shared';
import { GroupPanelItem } from '@/components/GroupPanelItem'; import { GroupPanelItem } from '@/components/GroupPanelItem';
@ -44,11 +46,18 @@ export const SidebarItem: React.FC<{
panel.pluginPanelName ?? '' panel.pluginPanelName ?? ''
); );
const { checkIsMuted, toggleMute } = useUserNotifyMute(); const { checkIsMuted, toggleMute } = useUserNotifyMute();
const [viewPanelPermission] = useHasGroupPanelPermission(groupId, panelId, [
PERMISSION.core.viewPanel,
]);
if (!groupInfo) { if (!groupInfo) {
return <LoadingSpinner />; return <LoadingSpinner />;
} }
if (!viewPanelPermission) {
return null;
}
const isPinned = const isPinned =
isValidStr(groupInfo.pinnedPanelId) && groupInfo.pinnedPanelId === panelId; isValidStr(groupInfo.pinnedPanelId) && groupInfo.pinnedPanelId === panelId;

Loading…
Cancel
Save