diff --git a/client/shared/index.tsx b/client/shared/index.tsx index 7ceb6aa8..d31e8636 100644 --- a/client/shared/index.tsx +++ b/client/shared/index.tsx @@ -227,7 +227,7 @@ export { MessageHelper } from './utils/message-helper'; export { PERMISSION, AllPermission, - permissionList, + getPermissionList, getDefaultPermissionList, applyDefaultFallbackGroupPermission, } from './utils/role-helper'; diff --git a/client/shared/redux/hooks/useGroupPermission.ts b/client/shared/redux/hooks/useGroupPermission.ts index a050e2fa..b7b69a97 100644 --- a/client/shared/redux/hooks/useGroupPermission.ts +++ b/client/shared/redux/hooks/useGroupPermission.ts @@ -3,7 +3,7 @@ import { useUserId } from './useUserInfo'; import _uniq from 'lodash/uniq'; import _flatten from 'lodash/flatten'; import { useDebugValue, useMemo } from 'react'; -import { permissionList } from '../..'; +import { getPermissionList } from '../..'; /** * 获取群组用户的所有权限 @@ -19,7 +19,7 @@ export function useGroupMemberAllPermissions(groupId: string): string[] { if (groupInfo.owner === userId) { // 群组管理员拥有一切权限 // 返回所有权限 - return permissionList.map((p) => p.key); + return getPermissionList().map((p) => p.key); } const members = groupInfo.members; diff --git a/client/shared/utils/role-helper.ts b/client/shared/utils/role-helper.ts index 47a2e496..faa0a134 100644 --- a/client/shared/utils/role-helper.ts +++ b/client/shared/utils/role-helper.ts @@ -45,7 +45,7 @@ export const PERMISSION = { }, }; -export const permissionList: PermissionItemType[] = [ +export const getPermissionList = (): PermissionItemType[] => [ { key: PERMISSION.core.message, title: t('发送消息'), @@ -98,7 +98,9 @@ export const permissionList: PermissionItemType[] = [ * 获取默认权限列表 */ export function getDefaultPermissionList(): string[] { - return permissionList.filter((p) => p.default).map((p) => p.key); + return getPermissionList() + .filter((p) => p.default) + .map((p) => p.key); } /** diff --git a/client/web/src/components/modals/GroupDetail/Role/tabs/permission.tsx b/client/web/src/components/modals/GroupDetail/Role/tabs/permission.tsx index ea71396b..36a28e68 100644 --- a/client/web/src/components/modals/GroupDetail/Role/tabs/permission.tsx +++ b/client/web/src/components/modals/GroupDetail/Role/tabs/permission.tsx @@ -1,4 +1,4 @@ -import { AllPermission, permissionList } from 'tailchat-shared'; +import { AllPermission, getPermissionList } from 'tailchat-shared'; import { Button, Divider } from 'antd'; import React, { useCallback, useMemo } from 'react'; import { model, t } from 'tailchat-shared'; @@ -31,7 +31,9 @@ export const RolePermission: React.FC = React.memo( const handleResetPermission = useCallback(() => { setEditingPermission( - permissionList.filter((p) => p.default === true).map((p) => p.key) + getPermissionList() + .filter((p) => p.default === true) + .map((p) => p.key) ); }, []); @@ -50,7 +52,7 @@ export const RolePermission: React.FC = React.memo( {/* 权限详情 */} - {permissionList.map((p) => ( + {getPermissionList().map((p) => (