MSP-3107 update permissions logic
This commit is contained in:
1 parent
90e9485f19
commit
d63afbfcd0
4 files changed
+17
-9
No files matched your search
@@ -7,7 +7,7 @@ import { PermissionKeys } from '@type/roles.type.ts'
|
|||||||
const AdminPermission = ({ children }: PropsWithChildren) => {
|
const AdminPermission = ({ children }: PropsWithChildren) => {
|
||||||
const { hasPermission } = useRole()
|
const { hasPermission } = useRole()
|
||||||
|
|
||||||
if (hasPermission(PermissionKeys.admin_view)) {
|
if (hasPermission(PermissionKeys.read)) {
|
||||||
return <>{children}</>
|
return <>{children}</>
|
||||||
}
|
}
|
||||||
return null
|
return null
|
||||||
|
|||||||
@@ -55,19 +55,19 @@ const LayoutComponent = () => {
|
|||||||
{
|
{
|
||||||
label: 'Доступы приложений',
|
label: 'Доступы приложений',
|
||||||
key: 'appAccess',
|
key: 'appAccess',
|
||||||
className: hideItem([PermissionKeys.user_view]),
|
className: hideItem([PermissionKeys.read]),
|
||||||
icon: <LockOutlined />
|
icon: <LockOutlined />
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: 'Пользователи и роли',
|
label: 'Пользователи и роли',
|
||||||
key: 'sessionManagement',
|
key: 'sessionManagement',
|
||||||
className: hideItem([PermissionKeys.user_view]),
|
className: hideItem([PermissionKeys.read]),
|
||||||
icon: <ProfileOutlined />,
|
icon: <ProfileOutlined />,
|
||||||
children: [
|
children: [
|
||||||
{
|
{
|
||||||
label: 'Пользователи',
|
label: 'Пользователи',
|
||||||
key: 'users',
|
key: 'users',
|
||||||
className: hideItem(PermissionKeys.user_view)
|
className: hideItem(PermissionKeys.read)
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,9 +4,16 @@ import { localStorageKeys } from '@constants/localStorageKeys.ts'
|
|||||||
|
|
||||||
import { LocalStorage } from '@utils/localStorageUtils.ts'
|
import { LocalStorage } from '@utils/localStorageUtils.ts'
|
||||||
|
|
||||||
|
import useRole from '@hooks/useRole.tsx'
|
||||||
|
|
||||||
import { routePaths } from '@routes/routePaths.ts'
|
import { routePaths } from '@routes/routePaths.ts'
|
||||||
|
|
||||||
|
import { PermissionKeys } from '@type/roles.type.ts'
|
||||||
|
|
||||||
|
|
||||||
const PrivateRoute = () => {
|
const PrivateRoute = () => {
|
||||||
|
const { hasPermission } = useRole()
|
||||||
|
|
||||||
const location = useLocation()
|
const location = useLocation()
|
||||||
const userToken = LocalStorage.get(localStorageKeys.USER_TOKEN)
|
const userToken = LocalStorage.get(localStorageKeys.USER_TOKEN)
|
||||||
|
|
||||||
@@ -15,6 +22,10 @@ const PrivateRoute = () => {
|
|||||||
return <Navigate to={routePaths.login} replace />
|
return <Navigate to={routePaths.login} replace />
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( location.pathname !=='/' && !hasPermission(PermissionKeys.read)) {
|
||||||
|
return <Navigate to={routePaths.home} replace />
|
||||||
|
}
|
||||||
|
|
||||||
return <Outlet />
|
return <Outlet />
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,11 +4,8 @@ export enum RoleKeys {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export enum PermissionKeys {
|
export enum PermissionKeys {
|
||||||
user_view = 'user_view', // Просмотр списка пользователей
|
read = 'read', // Просмотр страниц
|
||||||
admin_view = 'admin_view', // роль суперадмина, требуется для интерфейса
|
write = 'write', // Редактирование страниц
|
||||||
session_view = 'session_view', // Просмотр списка пользовательских сессий
|
|
||||||
security_log_view = 'security_log_view', // Просмотр журналов ИБ
|
|
||||||
role_view = 'role_view', // Просмотр экрана ролей
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export type RoleType = {
|
export type RoleType = {
|
||||||
|
|||||||
Reference in new issue
Block a user