From 83a1cd220594babb073a99f0d6f1156af15d5b47 Mon Sep 17 00:00:00 2001 From: txix Date: Thu, 4 Jul 2024 11:26:18 +0300 Subject: [PATCH] 2024-07-04 11:26:18: merge [main:50175f6fa5ae6d41dfbbfa36fd0563c0908b3009]; --- CHANGELOG.md | 2 ++ package.json | 2 +- src/components/Layout/index.tsx | 14 +++++++++----- src/components/RolesContent/index.tsx | 7 ++----- src/pages/RolesPage/index.tsx | 6 +++--- src/pages/SecurityLogPage/index.tsx | 2 +- src/pages/SessionsPage/index.tsx | 9 ++++----- src/pages/UsersPage/index.tsx | 18 ++++++++++-------- src/type/roles.type.ts | 14 +++++++++++++- 9 files changed, 45 insertions(+), 29 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2c6825e..cce9f93 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,5 @@ +## 0.13.2 +- Обновление пермишенов ## 0.13.1 - В LoginPage исправлен background для темной темы ## 0.13.0 diff --git a/package.json b/package.json index 38eefeb..6b8feef 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "isp-admin-ui", "private": true, - "version": "0.13.1", + "version": "0.13.2", "type": "module", "scripts": { "start": "vite", diff --git a/src/components/Layout/index.tsx b/src/components/Layout/index.tsx index c856efa..f5ccc8c 100644 --- a/src/components/Layout/index.tsx +++ b/src/components/Layout/index.tsx @@ -95,28 +95,32 @@ const LayoutComponent = () => { { label: 'Пользователи и роли', key: 'sessionManagement', - className: hideItem([PermissionKeysType.read]), + className: hideItem([ + PermissionKeysType.user_view, + PermissionKeysType.session_view, + PermissionKeysType.role_view, + ]), icon: , children: [ { label: 'Пользователи', key: 'users', - className: hideItem(PermissionKeysType.read) + className: hideItem(PermissionKeysType.user_view), }, { label: 'Пользовательские сессии', key: 'sessions', - className: hideItem(PermissionKeysType.read) + className: hideItem(PermissionKeysType.session_view), }, { label: 'Просмотр журналов ИБ', key: 'securityLog', - className: hideItem(PermissionKeysType.read) + className: hideItem(PermissionKeysType.security_log_view), }, { label: 'Роли', key: 'roles', - className: hideItem(PermissionKeysType.read) + className: hideItem(PermissionKeysType.role_view), } ] } diff --git a/src/components/RolesContent/index.tsx b/src/components/RolesContent/index.tsx index dfa5403..7c5824d 100644 --- a/src/components/RolesContent/index.tsx +++ b/src/components/RolesContent/index.tsx @@ -58,14 +58,12 @@ const RolesContent = ({ const { id: selectedItemId } = useParams() const [openModal, setOpenModal] = useState(false) - const isUpdateRole = hasPermission(PermissionKeysType.write) - const isCreateRole = hasPermission(PermissionKeysType.write) + const isUpdateRole = hasPermission(PermissionKeysType.role_update) + const isCreateRole = hasPermission(PermissionKeysType.role_add) const isSaveBtnAvailable = selectedItemId === 'new' ? isCreateRole : isUpdateRole - const isExternalGroup = hasPermission(PermissionKeysType.write) - useEffect(() => { if (!role) { reset(newRole) @@ -152,7 +150,6 @@ const RolesContent = ({ /> { const [updateRole] = roleApi.useUpdateRoleMutation() const [removeRole] = roleApi.useRemoveRoleMutation() - const isPageAvailable = hasPermission(PermissionKeysType.read) - const isAddRolePermissions = hasPermission(PermissionKeysType.write) - const isRemoveRolePermissions = hasPermission(PermissionKeysType.write) + const isPageAvailable = hasPermission(PermissionKeysType.role_view) + const isAddRolePermissions = hasPermission(PermissionKeysType.role_add) + const isRemoveRolePermissions = hasPermission(PermissionKeysType.role_delete) const isLoading = isPermissionLoading || isRolesLoading const isNew = selectedItemId === 'new' diff --git a/src/pages/SecurityLogPage/index.tsx b/src/pages/SecurityLogPage/index.tsx index f48f057..dc994d6 100644 --- a/src/pages/SecurityLogPage/index.tsx +++ b/src/pages/SecurityLogPage/index.tsx @@ -33,7 +33,7 @@ const SecurityLogPage = () => { const [currentPage, setCurrentPage] = useState(1) const isLoading = isUsersLoading || isLoadingLogs - const isPageAvailable = hasPermission(PermissionKeysType.read) + const isPageAvailable = hasPermission(PermissionKeysType.security_log_view) useEffect(() => { getAllLogs({ limit, offset: 0 }) diff --git a/src/pages/SessionsPage/index.tsx b/src/pages/SessionsPage/index.tsx index 74d9661..c967375 100644 --- a/src/pages/SessionsPage/index.tsx +++ b/src/pages/SessionsPage/index.tsx @@ -14,8 +14,6 @@ import { useNavigate } from 'react-router-dom' import { SessionStatusKeysType, sessionStatuses } from '@constants/statuses' -import CanEdit from '@components/CanEdit' - import { getUserFullName } from '@utils/userUtils/getFullNameUtil' import useRole from '@hooks/useRole' @@ -47,7 +45,8 @@ const SessionsPage = () => { const isLoading = isUsersLoading || isLoadingSession - const isPageAvailable = hasPermission(PermissionKeysType.read) + const isPageAvailable = hasPermission(PermissionKeysType.session_view) + const hasRevokePermission = hasPermission(PermissionKeysType.session_revoke) useEffect(() => { if (!isPageAvailable) { @@ -124,7 +123,7 @@ const SessionsPage = () => { } return ( <> - + {hasRevokePermission && ( handleRevokeSessions(record.id)} @@ -136,7 +135,7 @@ const SessionsPage = () => { /> - + )} ) } diff --git a/src/pages/UsersPage/index.tsx b/src/pages/UsersPage/index.tsx index ca1e268..71558a5 100644 --- a/src/pages/UsersPage/index.tsx +++ b/src/pages/UsersPage/index.tsx @@ -13,8 +13,6 @@ import { useNavigate } from 'react-router-dom' import { dateFormats } from '@constants/date.ts' -import CanEdit from '@components/CanEdit' - import { getUserFullName } from '@utils/userUtils/getFullNameUtil.ts' import useRole from '@hooks/useRole.tsx' @@ -42,8 +40,11 @@ const UsersPage = () => { const isLoading = isRolesLoading || isUsersLoading - const isPageAvailable = hasPermission(PermissionKeysType.read) - const hasCreateUserPermission = hasPermission(PermissionKeysType.write) + const isPageAvailable = hasPermission(PermissionKeysType.user_view) + const hasBlockUserPermission = hasPermission(PermissionKeysType.user_block) + const hasDeleteUserPermission = hasPermission(PermissionKeysType.user_delete) + const hasUpdateUserPermission = hasPermission(PermissionKeysType.user_update) + const hasCreateUserPermission = hasPermission(PermissionKeysType.user_create) useEffect(() => { if (!isPageAvailable) { @@ -169,9 +170,9 @@ const UsersPage = () => { render: (_, record) => { return (
- - {renderBlockButton(record)} + {hasBlockUserPermission && renderBlockButton(record)} + {hasUpdateUserPermission && (
) } diff --git a/src/type/roles.type.ts b/src/type/roles.type.ts index 800d310..71634f1 100644 --- a/src/type/roles.type.ts +++ b/src/type/roles.type.ts @@ -1,6 +1,18 @@ export enum PermissionKeysType { read = 'read', // Просмотр страниц - write = 'write' // Редактирование страниц + write = 'write', // Редактирование страниц + user_view = 'user_view', // Просмотр списка пользователей + user_block = 'user_block', // Блокировка пользователя + user_create = 'user_create', // Создать пользователя + user_update = 'user_update', // Обновить пользователя + user_delete = 'user_delete', // Удаление пользователя + session_view = 'session_view', // Просмотр списка пользовательских сессий + session_revoke = 'session_revoke', // Отзыв сессии + role_view = 'role_view', // Просмотр экрана ролей + role_add = 'role_add', // Создание роли + role_update = 'role_update', // Обновление роли + role_delete = 'role_delete', // Удаление роли + security_log_view = 'security_log_view', // Просмотр журналов ИБ } export interface RoleType {