Merge branch 'MSP-3107-app_access' into 'main'
Resolve MSP-3107 "App access" Closes MSP-3107 See merge request isp/isp-admin-ui!11
This commit is contained in:
commit
3fc78ec432
37 files changed
+976
-27
No files matched your search
@@ -1,3 +1,8 @@
|
||||
## 0.4.0
|
||||
- Добавлен экран управления доступами приложений
|
||||
- Исправлены корневые стили приложения
|
||||
- Обновлена поддержка пользовательских разрешений для страниц
|
||||
- Добавлена локализация Antd
|
||||
## 0.3.2
|
||||
- Добавлен generateVersionFile.cjs
|
||||
## 0.3.1
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "isp-admin-ui",
|
||||
"private": true,
|
||||
"version": "0.3.2",
|
||||
"version": "0.4.0",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"start": "vite",
|
||||
|
||||
@@ -7,7 +7,7 @@ import { PermissionKeys } from '@type/roles.type.ts'
|
||||
const AdminPermission = ({ children }: PropsWithChildren) => {
|
||||
const { hasPermission } = useRole()
|
||||
|
||||
if (hasPermission(PermissionKeys.admin_view)) {
|
||||
if (hasPermission(PermissionKeys.read)) {
|
||||
return <>{children}</>
|
||||
}
|
||||
return null
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { ConfigProvider } from 'antd'
|
||||
import ruRu from 'antd/locale/ru_RU'
|
||||
import { useState } from 'react'
|
||||
|
||||
import { lightTheme } from '@constants/theme.ts'
|
||||
@@ -15,7 +16,7 @@ const App = () => {
|
||||
return (
|
||||
<div className="app">
|
||||
<Context.Provider value={{ setTheme }}>
|
||||
<ConfigProvider theme={themes}>
|
||||
<ConfigProvider theme={themes} locale={ruRu}>
|
||||
<Routers />
|
||||
</ConfigProvider>
|
||||
</Context.Provider>
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
@import 'src/constants/style/styleConst';
|
||||
|
||||
.app-access-content {
|
||||
height: 100%;
|
||||
width: 100%;
|
||||
min-width: 760px;
|
||||
|
||||
padding: $basic-padding * 2;
|
||||
border: 1px solid $border-color;
|
||||
|
||||
&__header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
margin-bottom: $basic-margin * 2;
|
||||
|
||||
&__action-buttons {
|
||||
display: flex;
|
||||
gap: $basic-margin * 2;
|
||||
}
|
||||
}
|
||||
|
||||
&__main {
|
||||
display: grid;
|
||||
grid-template-columns:1fr 1fr;
|
||||
|
||||
|
||||
&__tree-search-input {
|
||||
width: 350px;
|
||||
margin-bottom: $basic-margin * 2;
|
||||
}
|
||||
}
|
||||
|
||||
.unknown-label {
|
||||
color: $error-red
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
export interface AppAccessContentPropsType {
|
||||
id: number
|
||||
paramPrefix: string
|
||||
}
|
||||
@@ -0,0 +1,208 @@
|
||||
import { SearchOutlined } from '@ant-design/icons'
|
||||
import { Button, Input, message, Spin, TreeProps } from 'antd'
|
||||
import { ChangeEvent, FC, memo, useEffect, useState } from 'react'
|
||||
import { Navigate, useSearchParams } from 'react-router-dom'
|
||||
|
||||
import AccessListTree from '@widgets/AccessListTree'
|
||||
import SelectedAccessMethod from '@widgets/SelectedAccessMethod'
|
||||
|
||||
import { AppAccessContentPropsType } from '@components/AppAccessContent/app-access-content.type.ts'
|
||||
|
||||
import { setSearchValue } from '@utils/columnLayoutUtils.ts'
|
||||
|
||||
import useRole from '@hooks/useRole.tsx'
|
||||
|
||||
import accessListApi from '@services/accessListService.ts'
|
||||
import routeApi from '@services/routeService.ts'
|
||||
|
||||
import { routePaths } from '@routes/routePaths.ts'
|
||||
|
||||
import { AccessListMethodType, EndpointType } from '@type/accessList.type.ts'
|
||||
import { PermissionKeys } from '@type/roles.type.ts'
|
||||
|
||||
import './app-access-content.scss'
|
||||
|
||||
|
||||
const unknownMethodKey = 'неизвестные методы'
|
||||
|
||||
const AppAccessContent: FC<AppAccessContentPropsType> = ({
|
||||
id,
|
||||
paramPrefix
|
||||
}) => {
|
||||
const [messageApi, contextHolder] = message.useMessage()
|
||||
const { hasPermission } = useRole()
|
||||
|
||||
const canWrite = hasPermission(PermissionKeys.write)
|
||||
|
||||
const {
|
||||
data: methods = [],
|
||||
isLoading: isMethodsLoading,
|
||||
isError: isMethodsError,
|
||||
isSuccess: isMethodsSuccess
|
||||
} = accessListApi.useGetByIdQuery({ id })
|
||||
const [setList] = accessListApi.useSetListMutation()
|
||||
const [setOne] = accessListApi.useSetOneMutation()
|
||||
|
||||
const {
|
||||
data: routes = {
|
||||
originalResponse: [],
|
||||
moduleEndpoints: {},
|
||||
allRouteMap: {}
|
||||
},
|
||||
isLoading: isRouteLoading,
|
||||
isError: isRouteError,
|
||||
isSuccess: isRouteSuccess
|
||||
} = routeApi.useGetAllRoutesQuery()
|
||||
const { moduleEndpoints, allRouteMap } = routes
|
||||
const [defaultAllRoutes, setDefaultAllRoutes] = useState<
|
||||
Record<string, EndpointType[]>
|
||||
>({})
|
||||
|
||||
const [searchParams, setSearchParams] = useSearchParams()
|
||||
const searchValue = searchParams.get(paramPrefix) || ''
|
||||
|
||||
const isLoading = isMethodsLoading || isRouteLoading
|
||||
const isError = isMethodsError || isRouteError
|
||||
const isSuccess = isMethodsSuccess && isRouteSuccess
|
||||
|
||||
const openSuccessMessage = (body: string) => {
|
||||
messageApi.success(body)
|
||||
}
|
||||
|
||||
const openErrorMessage = (body: string) => {
|
||||
messageApi.error(body)
|
||||
}
|
||||
|
||||
const createAllMethodList = (status: boolean) => {
|
||||
return Object.keys(allRouteMap).map((key) => {
|
||||
return {
|
||||
method: key,
|
||||
value: status
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
const onCheck: TreeProps['onCheck'] = (_, info): void | never[] => {
|
||||
const { node } = info
|
||||
if (!node.children) {
|
||||
const sendData = {
|
||||
appId: id,
|
||||
method: node.key as string,
|
||||
value: !node.checked
|
||||
}
|
||||
setOne(sendData)
|
||||
.then(() => {
|
||||
openSuccessMessage('Статус метода успешно изменен')
|
||||
})
|
||||
.catch(() => {
|
||||
openErrorMessage('Не удалось изменить статус метода')
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
const newCheckedKeys = node.children.map((child) => ({
|
||||
method: child.key as string,
|
||||
value: !node.checked
|
||||
}))
|
||||
setListMethods(newCheckedKeys)
|
||||
}
|
||||
|
||||
const onChange = (e: ChangeEvent<HTMLInputElement>) => {
|
||||
const { value } = e.target
|
||||
setSearchValue(value.trim().toLowerCase(), setSearchParams, paramPrefix)
|
||||
}
|
||||
|
||||
const setListMethods = (methods: AccessListMethodType[]) => {
|
||||
setList({
|
||||
appId: id,
|
||||
methods: methods
|
||||
})
|
||||
.then(() => {
|
||||
openSuccessMessage('Статус методов успешно изменен')
|
||||
})
|
||||
.catch(() => {
|
||||
openErrorMessage('Не удалось изменить статус методов')
|
||||
})
|
||||
}
|
||||
|
||||
const setAllMethods = (status: boolean) => {
|
||||
const methods = createAllMethodList(status)
|
||||
setListMethods(methods)
|
||||
}
|
||||
|
||||
const getAllRoutes = () => {
|
||||
const missingRoute: EndpointType[] = []
|
||||
const copyAllRoutes = { ...moduleEndpoints }
|
||||
|
||||
methods.forEach((item) => {
|
||||
if (!allRouteMap[item.method]) {
|
||||
missingRoute.push({ path: item.method } as EndpointType)
|
||||
}
|
||||
})
|
||||
|
||||
if (missingRoute.length) {
|
||||
copyAllRoutes[unknownMethodKey] = missingRoute
|
||||
}
|
||||
return copyAllRoutes
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
const allRoutes = getAllRoutes()
|
||||
setDefaultAllRoutes(allRoutes)
|
||||
}, [isSuccess])
|
||||
|
||||
if (isLoading) {
|
||||
return <Spin className="spin" />
|
||||
}
|
||||
|
||||
if (isError) {
|
||||
return <Navigate to={routePaths.error} />
|
||||
}
|
||||
return (
|
||||
<div className="app-access-content">
|
||||
{contextHolder}
|
||||
<div className="app-access-content__header">
|
||||
<Input
|
||||
prefix={<SearchOutlined />}
|
||||
allowClear
|
||||
className="app-access-content__main__tree-search-input"
|
||||
value={searchValue}
|
||||
placeholder="Найти метод"
|
||||
onChange={onChange}
|
||||
/>
|
||||
<div className="app-access-content__header__action-buttons">
|
||||
<Button disabled={!canWrite}
|
||||
onClick={() => {
|
||||
setAllMethods(false)
|
||||
}}
|
||||
>
|
||||
Запретить все
|
||||
</Button>
|
||||
<Button
|
||||
disabled={!canWrite}
|
||||
onClick={() => {
|
||||
setAllMethods(true)
|
||||
}}
|
||||
>
|
||||
Выбрать все
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
<div className="app-access-content__main">
|
||||
<AccessListTree
|
||||
searchValue={searchValue}
|
||||
onCheck={onCheck}
|
||||
defaultAllRoutes={defaultAllRoutes}
|
||||
methods={methods}
|
||||
/>
|
||||
<SelectedAccessMethod
|
||||
unknownMethodKey={unknownMethodKey}
|
||||
methods={methods}
|
||||
allRoutes={defaultAllRoutes}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export default memo(AppAccessContent)
|
||||
@@ -1,7 +1,7 @@
|
||||
import { ProfileOutlined } from '@ant-design/icons'
|
||||
import { LockOutlined, ProfileOutlined } from '@ant-design/icons'
|
||||
import { Divider, Layout, Menu, Spin } from 'antd'
|
||||
import { useEffect, useState } from 'react'
|
||||
import { Navigate, Outlet, useLocation } from 'react-router-dom'
|
||||
import { Navigate, Outlet, useLocation, useNavigate } from 'react-router-dom'
|
||||
|
||||
import { localStorageKeys } from '@constants/localStorageKeys.ts'
|
||||
|
||||
@@ -26,10 +26,11 @@ import { PermissionKeys } from '@type/roles.type.ts'
|
||||
|
||||
import './layout.scss'
|
||||
|
||||
|
||||
const { Content, Sider } = Layout
|
||||
|
||||
const LayoutComponent = () => {
|
||||
const navigate = useNavigate()
|
||||
|
||||
const [collapsed, setCollapsed] = useState<boolean>(false)
|
||||
const [selectedMenuKeys, setSelectedMenuKeys] = useState<MenuItemKeys[]>([])
|
||||
const [openKeys, setOpenKeys] = useState<string[]>([])
|
||||
@@ -51,16 +52,22 @@ const LayoutComponent = () => {
|
||||
return hasPermission(permission) ? '' : 'hide-item'
|
||||
}
|
||||
const menuItems: MenuItemType[] = [
|
||||
{
|
||||
label: 'Доступы приложений',
|
||||
key: 'appAccess',
|
||||
className: hideItem([PermissionKeys.read]),
|
||||
icon: <LockOutlined />
|
||||
},
|
||||
{
|
||||
label: 'Пользователи и роли',
|
||||
key: 'sessionManagement',
|
||||
className: hideItem([PermissionKeys.user_view]),
|
||||
className: hideItem([PermissionKeys.read]),
|
||||
icon: <ProfileOutlined />,
|
||||
children: [
|
||||
{
|
||||
label: 'Пользователи',
|
||||
key: 'users',
|
||||
className: hideItem(PermissionKeys.user_view)
|
||||
className: hideItem(PermissionKeys.read)
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -85,6 +92,9 @@ const LayoutComponent = () => {
|
||||
|
||||
const handlerOnClickMenu = ({ key }: any): void => {
|
||||
switch (key) {
|
||||
case MenuItemKeys.appAccess:
|
||||
navigate(routePaths.appAccess)
|
||||
break
|
||||
default:
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import { MenuProps } from 'antd'
|
||||
|
||||
export enum MenuItemKeys {
|
||||
users = 'users'
|
||||
users = 'users',
|
||||
appAccess = 'appAccess'
|
||||
}
|
||||
|
||||
type MenuItem = {
|
||||
@@ -12,6 +13,10 @@ export const menuKeys: Record<MenuItemKeys, MenuItem> = {
|
||||
[MenuItemKeys.users]: {
|
||||
key: MenuItemKeys.users,
|
||||
parent: ['sessionManagement']
|
||||
},
|
||||
[MenuItemKeys.appAccess]: {
|
||||
key: MenuItemKeys.appAccess,
|
||||
parent: []
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,8 @@
|
||||
}
|
||||
|
||||
.app{
|
||||
overflow: hidden;
|
||||
height: 100vh;
|
||||
padding: 0 $basic-padding;
|
||||
min-height: 0;
|
||||
min-width: 500px;
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
type PathKeys =
|
||||
| 'baseUrl'
|
||||
| 'baseSystemUrl'
|
||||
| 'baseConfigUrl'
|
||||
| 'getAllRoles'
|
||||
| 'createRole'
|
||||
| 'updateRole'
|
||||
@@ -7,8 +9,15 @@ type PathKeys =
|
||||
| 'login'
|
||||
| 'logout'
|
||||
| 'getProfile'
|
||||
| 'getSystemTree'
|
||||
| 'getById'
|
||||
| 'setList'
|
||||
| 'setOne'
|
||||
| 'getAllRoutes'
|
||||
export const apiPaths: Record<PathKeys, string> = {
|
||||
baseUrl: '/api/admin',
|
||||
baseSystemUrl: '/api/system',
|
||||
baseConfigUrl: '/api/config',
|
||||
// ======= ROLES ======
|
||||
getAllRoles: '/role/all',
|
||||
createRole: '/role/create',
|
||||
@@ -18,5 +27,12 @@ export const apiPaths: Record<PathKeys, string> = {
|
||||
login: '/api/admin/auth/login',
|
||||
logout: '/api/admin/auth/logout',
|
||||
// ======= PROFILE ======
|
||||
getProfile: '/api/admin/user/get_profile'
|
||||
getProfile: '/api/admin/user/get_profile',
|
||||
// ======= APPLICATIONS ======
|
||||
getSystemTree: '/application/get_system_tree',
|
||||
// ======= ACCESS_LIST ======
|
||||
getById: '/access_list/get_by_id',
|
||||
setList: '/access_list/set_list',
|
||||
setOne: '/access_list/set_one',
|
||||
getAllRoutes: '/routing/get_routes'
|
||||
}
|
||||
@@ -7,5 +7,7 @@ $text-size-header2: 1.25rem;
|
||||
|
||||
$text-color-gray: var(--ant-primary-color);
|
||||
$background-color: #F0F2F5;
|
||||
$grey:#606060;
|
||||
$grey: #606060;
|
||||
$border-color: #d9d9d9;
|
||||
$error-red: #cf1322;
|
||||
|
||||
@@ -7,6 +7,9 @@ import App from './components/App.tsx'
|
||||
|
||||
import { setupStore } from './stores'
|
||||
|
||||
import 'simplebar-react/dist/simplebar.min.css'
|
||||
|
||||
|
||||
const store = setupStore()
|
||||
setupListeners(store.dispatch)
|
||||
const root = createRoot(document.getElementById('root') as HTMLElement)
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
@import "src/constants/style/styleConst";
|
||||
|
||||
.app-access-page {
|
||||
display: flex;
|
||||
height: 100%;
|
||||
|
||||
.ant-tree {
|
||||
background: none;
|
||||
}
|
||||
|
||||
&__content-wrap{
|
||||
width: 100%;
|
||||
overflow-x: scroll;
|
||||
}
|
||||
}
|
||||
Whitespace-only changes.
@@ -0,0 +1,111 @@
|
||||
import { Spin } from 'antd'
|
||||
import { Layout } from 'isp-ui-kit'
|
||||
import { ColumnItem } from 'isp-ui-kit/dist/Layout/Column/column.type'
|
||||
import { memo, useEffect } from 'react'
|
||||
import {
|
||||
createSearchParams,
|
||||
Navigate,
|
||||
useNavigate,
|
||||
useParams,
|
||||
useSearchParams
|
||||
} from 'react-router-dom'
|
||||
|
||||
import ListItem from '@widgets/ListItem'
|
||||
|
||||
import AppAccessContent from '@components/AppAccessContent'
|
||||
|
||||
import { setSearchValue, setSelectedItemId } from '@utils/columnLayoutUtils.ts'
|
||||
import { filterFirstColumnItems } from '@utils/firstColumnUtils.ts'
|
||||
|
||||
import useRole from '@hooks/useRole.tsx'
|
||||
|
||||
import appApi from '@services/appService.ts'
|
||||
|
||||
import { routePaths } from '@routes/routePaths.ts'
|
||||
|
||||
import { SystemTreeAppType } from '@type/app.type.ts'
|
||||
import { PermissionKeys } from '@type/roles.type.ts'
|
||||
|
||||
import './app-access-page.scss'
|
||||
|
||||
|
||||
const { Column, EmptyData } = Layout
|
||||
|
||||
const firstColumnSearchParam = 'search'
|
||||
const findMethodParam = 'method'
|
||||
|
||||
const AppAccessPage = () => {
|
||||
const {
|
||||
data = { originalResponse: [], appList: [] },
|
||||
isLoading,
|
||||
isError
|
||||
} = appApi.useGetSystemTreeQuery()
|
||||
|
||||
const { appList } = data
|
||||
const navigate = useNavigate()
|
||||
const { hasPermission } = useRole()
|
||||
|
||||
const { id: selectedItemId = '' } = useParams()
|
||||
const [searchParams, setSearchParams] = useSearchParams()
|
||||
const searchValue = searchParams.get(firstColumnSearchParam) || ''
|
||||
const canRead = hasPermission(PermissionKeys.read)
|
||||
|
||||
useEffect(() => {
|
||||
if (!canRead) {
|
||||
navigate(routePaths.home)
|
||||
}
|
||||
}, [canRead])
|
||||
|
||||
const handleOnChangeSearchValue = (value: string): void => {
|
||||
setSearchValue(value, setSearchParams)
|
||||
}
|
||||
|
||||
const onSelectedItemId = (id: string): void => {
|
||||
setSearchValue('', setSearchParams, findMethodParam)
|
||||
setSelectedItemId(
|
||||
routePaths.appAccess,
|
||||
id,
|
||||
createSearchParams(searchParams).toString(),
|
||||
navigate
|
||||
)
|
||||
}
|
||||
|
||||
if (isLoading) {
|
||||
return <Spin className="spin" />
|
||||
}
|
||||
|
||||
if (isError) {
|
||||
return <Navigate to={routePaths.error} />
|
||||
}
|
||||
|
||||
return (
|
||||
<section className="app-access-page">
|
||||
<Column
|
||||
showAddBtn={false}
|
||||
showRemoveBtn={false}
|
||||
items={filterFirstColumnItems(
|
||||
appList as ColumnItem<SystemTreeAppType>,
|
||||
searchValue
|
||||
)}
|
||||
renderItems={(item) => <ListItem item={item} />}
|
||||
searchValue={searchValue}
|
||||
selectedItemId={selectedItemId}
|
||||
setSelectedItemId={onSelectedItemId}
|
||||
onChangeSearchValue={handleOnChangeSearchValue}
|
||||
/>
|
||||
<div className="app-access-page__content-wrap">
|
||||
{selectedItemId ? (
|
||||
<AppAccessContent
|
||||
paramPrefix={findMethodParam}
|
||||
key={`content-${selectedItemId}`}
|
||||
id={Number(selectedItemId)}
|
||||
/>
|
||||
) : (
|
||||
<EmptyData />
|
||||
)}
|
||||
</div>
|
||||
</section>
|
||||
)
|
||||
}
|
||||
|
||||
export default memo(AppAccessPage)
|
||||
@@ -6,6 +6,7 @@ import { LocalStorage } from '@utils/localStorageUtils.ts'
|
||||
|
||||
import { routePaths } from '@routes/routePaths.ts'
|
||||
|
||||
|
||||
const PrivateRoute = () => {
|
||||
const location = useLocation()
|
||||
const userToken = LocalStorage.get(localStorageKeys.USER_TOKEN)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { Spin } from 'antd'
|
||||
import { Suspense, lazy } from 'react'
|
||||
import { lazy, Suspense } from 'react'
|
||||
import { Route, Routes } from 'react-router-dom'
|
||||
|
||||
import Layout from '@components/Layout'
|
||||
@@ -10,11 +10,9 @@ import PrivateRoute from '@routes/PrivateRoute'
|
||||
import { routePaths } from '@routes/routePaths.ts'
|
||||
|
||||
const LoginPage = lazy(() => import('@pages/LoginPage'))
|
||||
|
||||
const ErrorPage = lazy(() => import('@components/ErrorPage'))
|
||||
|
||||
|
||||
const ProfilePage = lazy(() => import('@pages/ProfilePage'))
|
||||
const AppAccessPage = lazy(() => import('@pages/AppAccessPage'))
|
||||
|
||||
const Routers = () => {
|
||||
return (
|
||||
@@ -29,17 +27,35 @@ const Routers = () => {
|
||||
</Suspense>
|
||||
}
|
||||
/>
|
||||
<Route
|
||||
path={`${routePaths.profile}`}
|
||||
element={
|
||||
<Suspense fallback={<Spin />}>
|
||||
<ProfilePage />
|
||||
</Suspense>
|
||||
}
|
||||
/>
|
||||
<Route
|
||||
path={`${routePaths.appAccess}`}
|
||||
element={
|
||||
<Suspense fallback={<Spin />}>
|
||||
<AppAccessPage />
|
||||
</Suspense>
|
||||
}
|
||||
>
|
||||
<Route
|
||||
path={`${routePaths.profile}`}
|
||||
path=":id"
|
||||
element={
|
||||
<Suspense fallback={<Spin />}>
|
||||
<ProfilePage />
|
||||
<AppAccessPage />
|
||||
</Suspense>
|
||||
}
|
||||
/>
|
||||
</Route>
|
||||
</Route>
|
||||
<Route path={routePaths.error}
|
||||
</Route>
|
||||
<Route
|
||||
path={routePaths.error}
|
||||
element={
|
||||
<Suspense fallback={<Spin />}>
|
||||
<ErrorPage />
|
||||
|
||||
@@ -1,9 +1,16 @@
|
||||
type RoutePaths = 'home' | 'notFound' | 'error' | 'login' | 'profile'
|
||||
type RoutePaths =
|
||||
| 'home'
|
||||
| 'notFound'
|
||||
| 'error'
|
||||
| 'login'
|
||||
| 'profile'
|
||||
| 'appAccess'
|
||||
|
||||
export const routePaths: Record<RoutePaths, string> = {
|
||||
home: '/',
|
||||
error: '/error',
|
||||
notFound: '*',
|
||||
login: '/login',
|
||||
profile: '/profile'
|
||||
profile: '/profile',
|
||||
appAccess: '/appAccess'
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
import { createApi } from '@reduxjs/toolkit/query/react'
|
||||
|
||||
import { apiPaths } from '@constants/api/apiPaths.ts'
|
||||
|
||||
import { axiosBaseQuery } from '@utils/apiUtils.ts'
|
||||
|
||||
import {
|
||||
AccessListMethodType,
|
||||
AccessListSetListRequestType,
|
||||
AccessListSetListSetOneRequestType
|
||||
} from '@type/accessList.type.ts'
|
||||
|
||||
|
||||
const accessListApi = createApi({
|
||||
reducerPath: 'accessListApi',
|
||||
refetchOnFocus: true,
|
||||
tagTypes: ['AccessItems'],
|
||||
baseQuery: axiosBaseQuery({ baseUrl: apiPaths.baseSystemUrl }),
|
||||
endpoints: (builder) => ({
|
||||
getById: builder.query<AccessListMethodType[], { id: number }>({
|
||||
query: ({ id }) => ({ url: apiPaths.getById, data: { id } }),
|
||||
providesTags: () => ['AccessItems']
|
||||
}),
|
||||
setList: builder.mutation<AccessListMethodType[], AccessListSetListRequestType>({
|
||||
query: (data) => ({ url: apiPaths.setList, data }),
|
||||
invalidatesTags: () => ['AccessItems']
|
||||
}),
|
||||
setOne: builder.mutation<void, AccessListSetListSetOneRequestType>({
|
||||
query: (data) => ({ url: apiPaths.setOne, data }),
|
||||
invalidatesTags: () => ['AccessItems']
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
export default accessListApi
|
||||
@@ -0,0 +1,33 @@
|
||||
import { createApi } from '@reduxjs/toolkit/query/react'
|
||||
|
||||
import { apiPaths } from '@constants/api/apiPaths.ts'
|
||||
|
||||
import { axiosBaseQuery } from '@utils/apiUtils.ts'
|
||||
|
||||
import { AppApiResponseType, DomainType } from '@type/app.type.ts'
|
||||
|
||||
|
||||
const appApi = createApi({
|
||||
reducerPath: 'appService',
|
||||
refetchOnFocus: true,
|
||||
tagTypes: ['SystemTreeApps'],
|
||||
baseQuery: axiosBaseQuery({ baseUrl: apiPaths.baseSystemUrl }),
|
||||
endpoints: (builder) => ({
|
||||
getSystemTree: builder.query<AppApiResponseType, void>({
|
||||
query: () => ({ url: apiPaths.getSystemTree }),
|
||||
transformResponse: (response: DomainType[]) => {
|
||||
const apps = response.flatMap(({ services }) =>
|
||||
services.flatMap(({ apps }) => apps)
|
||||
)
|
||||
|
||||
return {
|
||||
originalResponse: response,
|
||||
appList: apps
|
||||
}
|
||||
},
|
||||
providesTags: () => ['SystemTreeApps']
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
export default appApi
|
||||
@@ -0,0 +1,50 @@
|
||||
import { createApi } from '@reduxjs/toolkit/query/react'
|
||||
|
||||
import { apiPaths } from '@constants/api/apiPaths.ts'
|
||||
|
||||
import { axiosBaseQuery } from '@utils/apiUtils.ts'
|
||||
|
||||
import {
|
||||
EndpointType,
|
||||
RouteApiResponseType,
|
||||
RouteType
|
||||
} from '@type/accessList.type.ts'
|
||||
|
||||
|
||||
const routeApi = createApi({
|
||||
reducerPath: 'routeApi',
|
||||
refetchOnFocus: true,
|
||||
tagTypes: ['Routes'],
|
||||
baseQuery: axiosBaseQuery({ baseUrl: apiPaths.baseConfigUrl }),
|
||||
endpoints: (builder) => ({
|
||||
getAllRoutes: builder.query<RouteApiResponseType, void>({
|
||||
query: () => ({ url: apiPaths.getAllRoutes }),
|
||||
transformResponse: (response: RouteType[]) => {
|
||||
const moduleEndpoints: Record<string, EndpointType[]> = {}
|
||||
const allRouteMap: Record<string, EndpointType> = {}
|
||||
|
||||
response.forEach((route) => {
|
||||
if (route.endpoints && route.endpoints.length) {
|
||||
moduleEndpoints[route.moduleName] = route.endpoints
|
||||
}
|
||||
})
|
||||
Object.keys(moduleEndpoints)
|
||||
.sort()
|
||||
.forEach((groupName) => {
|
||||
moduleEndpoints[groupName].forEach((method) => {
|
||||
allRouteMap[method.path] = method
|
||||
})
|
||||
})
|
||||
|
||||
return {
|
||||
originalResponse: response,
|
||||
moduleEndpoints: moduleEndpoints,
|
||||
allRouteMap: allRouteMap
|
||||
}
|
||||
},
|
||||
providesTags: () => ['Routes']
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
export default routeApi
|
||||
+13
-2
@@ -3,7 +3,10 @@ import { theme } from 'antd'
|
||||
import { MapToken, SeedToken } from 'antd/es/theme/interface'
|
||||
import { createContext, Dispatch, SetStateAction } from 'react'
|
||||
|
||||
import accessListApi from '@services/accessListService.ts'
|
||||
import appApi from '@services/appService.ts'
|
||||
import roleApi from '@services/roleService.ts'
|
||||
import routeApi from '@services/routeService.ts'
|
||||
|
||||
import profileReducer from './redusers/ProfileSlice.ts'
|
||||
|
||||
@@ -20,14 +23,22 @@ export const Context = createContext<ContextProps>({
|
||||
|
||||
const rootReducer = combineReducers({
|
||||
profileReducer,
|
||||
[roleApi.reducerPath]: roleApi.reducer
|
||||
[roleApi.reducerPath]: roleApi.reducer,
|
||||
[appApi.reducerPath]: appApi.reducer,
|
||||
[accessListApi.reducerPath]: accessListApi.reducer,
|
||||
[routeApi.reducerPath]: routeApi.reducer
|
||||
})
|
||||
|
||||
export const setupStore = () =>
|
||||
configureStore({
|
||||
reducer: rootReducer,
|
||||
middleware: (getDefaultMiddleware) =>
|
||||
getDefaultMiddleware().concat([roleApi.middleware])
|
||||
getDefaultMiddleware().concat(
|
||||
roleApi.middleware,
|
||||
appApi.middleware,
|
||||
accessListApi.middleware,
|
||||
routeApi.middleware
|
||||
)
|
||||
})
|
||||
|
||||
export type RootState = ReturnType<typeof rootReducer>
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
export interface AccessListMethodType {
|
||||
method: string
|
||||
value: boolean
|
||||
}
|
||||
|
||||
export interface AccessListSetListRequestType {
|
||||
appId: number
|
||||
methods: AccessListMethodType[]
|
||||
removeOld?: boolean
|
||||
}
|
||||
|
||||
export interface AccessListSetListSetOneRequestType {
|
||||
appId: number
|
||||
method: string
|
||||
value: boolean
|
||||
}
|
||||
|
||||
export interface EndpointType {
|
||||
extra: Record<string, any>
|
||||
inner: boolean
|
||||
path: string
|
||||
userAuthRequired: boolean
|
||||
}
|
||||
|
||||
export type AddressType = {
|
||||
ip: string
|
||||
port: string
|
||||
}
|
||||
|
||||
export type RequiredModuleType = {
|
||||
name: string
|
||||
required: boolean
|
||||
}
|
||||
|
||||
export type RouteType = {
|
||||
address: AddressType
|
||||
endpoints: EndpointType[]
|
||||
libVersion: string
|
||||
moduleName: string
|
||||
requiredModules: RequiredModuleType[]
|
||||
version: string
|
||||
}
|
||||
|
||||
export interface RouteApiResponseType {
|
||||
originalResponse: RouteType[]
|
||||
moduleEndpoints: Record<string, EndpointType[]>
|
||||
allRouteMap: Record<string, EndpointType>
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
interface TokenType {
|
||||
appId: boolean
|
||||
createdAt: string
|
||||
expireTime: boolean
|
||||
token: string
|
||||
}
|
||||
|
||||
export interface SystemTreeAppType {
|
||||
description: string
|
||||
id: boolean
|
||||
name: string
|
||||
tokens: TokenType[]
|
||||
type: string
|
||||
}
|
||||
|
||||
interface SystemServiceType {
|
||||
apps: SystemTreeAppType[]
|
||||
description: string
|
||||
id: boolean
|
||||
name: string
|
||||
}
|
||||
|
||||
export interface DomainType {
|
||||
description: string
|
||||
id: boolean
|
||||
name: string
|
||||
services: SystemServiceType[]
|
||||
}
|
||||
|
||||
export interface AppApiResponseType {
|
||||
originalResponse: DomainType[]
|
||||
appList: SystemTreeAppType[]
|
||||
}
|
||||
@@ -4,11 +4,8 @@ export enum RoleKeys {
|
||||
}
|
||||
|
||||
export enum PermissionKeys {
|
||||
user_view = 'user_view', // Просмотр списка пользователей
|
||||
admin_view = 'admin_view', // роль суперадмина, требуется для интерфейса
|
||||
session_view = 'session_view', // Просмотр списка пользовательских сессий
|
||||
security_log_view = 'security_log_view', // Просмотр журналов ИБ
|
||||
role_view = 'role_view', // Просмотр экрана ролей
|
||||
read = 'read', // Просмотр страниц
|
||||
write = 'write', // Редактирование страниц
|
||||
}
|
||||
|
||||
export type RoleType = {
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
import { NavigateFunction, SetURLSearchParams } from 'react-router-dom'
|
||||
|
||||
export const setSelectedItemId = (
|
||||
path: string,
|
||||
id: string,
|
||||
searchParams: string,
|
||||
navigate: NavigateFunction
|
||||
): void => {
|
||||
navigate(
|
||||
{
|
||||
pathname: `${path}/${id}`,
|
||||
search: searchParams
|
||||
},
|
||||
{ replace: true }
|
||||
)
|
||||
}
|
||||
|
||||
export const setSearchValue = (
|
||||
value: string,
|
||||
setSearchParams: SetURLSearchParams,
|
||||
prefix: string = 'search'
|
||||
) => {
|
||||
setSearchParams((prev) => {
|
||||
if (!value) {
|
||||
prev.delete(prefix)
|
||||
} else {
|
||||
prev.set(prefix, value)
|
||||
}
|
||||
return prev
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
import { ColumnItem } from 'isp-ui-kit/dist/Layout/Column/column.type'
|
||||
|
||||
export const filterFirstColumnItems = <T extends NonNullable<unknown>>(
|
||||
listItems: ColumnItem<T>[],
|
||||
searchValue: string
|
||||
): ColumnItem<T>[] =>
|
||||
listItems
|
||||
? listItems.filter((el) =>
|
||||
el.name.toLowerCase().trim().includes(searchValue.toLowerCase().trim())
|
||||
)
|
||||
: []
|
||||
@@ -0,0 +1,5 @@
|
||||
.access-list-tree{
|
||||
overflow-y: scroll;
|
||||
height: calc(100vh - 130px);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
import { TreeProps } from 'antd'
|
||||
|
||||
import { AccessListMethodType, EndpointType } from '@type/accessList.type.ts'
|
||||
|
||||
|
||||
export interface AccessListTreePropsType {
|
||||
searchValue: string
|
||||
defaultAllRoutes: Record<string, EndpointType[]>
|
||||
methods: AccessListMethodType[]
|
||||
onCheck: TreeProps['onCheck']
|
||||
}
|
||||
@@ -0,0 +1,137 @@
|
||||
import { WarningOutlined } from '@ant-design/icons'
|
||||
import { Tag, Tree, TreeProps } from 'antd'
|
||||
import { FC, memo, useCallback, useEffect, useState } from 'react'
|
||||
|
||||
import { AccessListTreePropsType } from '@widgets/AccessListTree/access-list-tree.type.ts'
|
||||
|
||||
import useRole from '@hooks/useRole.tsx'
|
||||
|
||||
import { EndpointType } from '@type/accessList.type.ts'
|
||||
import { PermissionKeys } from '@type/roles.type.ts'
|
||||
|
||||
import './access-list-tree.scss'
|
||||
|
||||
|
||||
const unknownMethodKey = 'неизвестные методы'
|
||||
|
||||
const AccessListTree: FC<AccessListTreePropsType> = ({
|
||||
searchValue,
|
||||
defaultAllRoutes,
|
||||
methods,
|
||||
onCheck = []
|
||||
}) => {
|
||||
const { hasPermission } = useRole()
|
||||
const [checkedKeys, setCheckedKeys] = useState<string[]>([])
|
||||
const [expandedKeys, setExpandedKeys] = useState<string[]>([])
|
||||
|
||||
const createTreeData = (data: Record<string, EndpointType[]>) => {
|
||||
return Object.keys(data)
|
||||
.sort()
|
||||
.map((routeKey) => {
|
||||
if (routeKey === unknownMethodKey) {
|
||||
return {
|
||||
title: (
|
||||
<span className="unknown-label">
|
||||
{routeKey} <WarningOutlined />
|
||||
</span>
|
||||
),
|
||||
key: routeKey,
|
||||
children: data[routeKey].map((route) => createTreeNode(route, true))
|
||||
}
|
||||
}
|
||||
return {
|
||||
title: routeKey,
|
||||
key: routeKey,
|
||||
children: data[routeKey].map((route) => createTreeNode(route))
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
const createTreeNode = useCallback((obj: EndpointType, unknown = false) => {
|
||||
return {
|
||||
title: (
|
||||
<span className={`${unknown ? 'unknown-label' : ''}`}>
|
||||
{obj.path}
|
||||
{obj.inner ? (
|
||||
<Tag color="processing" bordered={false}>
|
||||
Внутренний
|
||||
</Tag>
|
||||
) : null}
|
||||
</span>
|
||||
),
|
||||
key: obj.path
|
||||
}
|
||||
}, [])
|
||||
|
||||
const filteredRoute = () => {
|
||||
if (!searchValue) {
|
||||
return defaultAllRoutes
|
||||
}
|
||||
const filteredRoute: Record<string, EndpointType[]> = {}
|
||||
Object.keys(defaultAllRoutes).forEach((groupName) => {
|
||||
const filterArray = defaultAllRoutes[groupName].filter(({ path }) =>
|
||||
path.toLowerCase().includes(searchValue)
|
||||
)
|
||||
if (filterArray.length) {
|
||||
filteredRoute[groupName] = filterArray
|
||||
}
|
||||
})
|
||||
return filteredRoute
|
||||
}
|
||||
|
||||
const treeData = createTreeData(filteredRoute())
|
||||
|
||||
const filteredCheckedKeys = () => {
|
||||
const isStringPresent = (string: string) => {
|
||||
for (const service of treeData) {
|
||||
for (const endpoint of service.children) {
|
||||
if (endpoint.key === string) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
return checkedKeys.filter((string) => isStringPresent(string))
|
||||
}
|
||||
|
||||
const filteredKeys = filteredCheckedKeys()
|
||||
|
||||
useEffect(() => {
|
||||
const checkedKeys = new Set<string>()
|
||||
methods.forEach(({ method, value }) => {
|
||||
if (value) {
|
||||
checkedKeys.add(method)
|
||||
}
|
||||
})
|
||||
|
||||
const arrayCheckedKeys = Array.from(checkedKeys)
|
||||
setCheckedKeys(arrayCheckedKeys)
|
||||
}, [methods])
|
||||
|
||||
useEffect(() => {
|
||||
if (!searchValue) {
|
||||
setExpandedKeys([])
|
||||
return
|
||||
}
|
||||
const keys = Object.values(treeData).map((node) => node.key)
|
||||
setExpandedKeys(keys)
|
||||
}, [searchValue, defaultAllRoutes])
|
||||
|
||||
return (
|
||||
<div className="access-list-tree">
|
||||
<Tree
|
||||
className="app-access-content__main__tree"
|
||||
checkable={hasPermission(PermissionKeys.write)}
|
||||
checkedKeys={filteredKeys}
|
||||
expandedKeys={expandedKeys}
|
||||
onExpand={(keys) => setExpandedKeys(keys as string[])}
|
||||
onCheck={onCheck as TreeProps['onCheck']}
|
||||
treeData={treeData}
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export default memo(AccessListTree)
|
||||
@@ -0,0 +1,17 @@
|
||||
import { List, Tooltip } from 'antd'
|
||||
import { FC } from 'react'
|
||||
|
||||
import { ListItemProps } from '@widgets/ListItem/list-item.type.ts'
|
||||
|
||||
|
||||
const ListItem: FC<ListItemProps> = ({ item }) => {
|
||||
return (
|
||||
<List.Item>
|
||||
<Tooltip mouseEnterDelay={1} title={item.name}>
|
||||
<List.Item.Meta title={item.name} />
|
||||
</Tooltip>
|
||||
</List.Item>
|
||||
)
|
||||
}
|
||||
|
||||
export default ListItem
|
||||
@@ -0,0 +1,5 @@
|
||||
import { ColumnItem } from 'isp-ui-kit/dist/Layout/Column/column.type'
|
||||
|
||||
export interface ListItemProps {
|
||||
item: ColumnItem<any>
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
import { FC } from 'react'
|
||||
|
||||
import { SelectedAccessMethodPropsType } from '@widgets/SelectedAccessMethod/selected-access-method.type.ts'
|
||||
|
||||
import { AccessListMethodType } from '@type/accessList.type.ts'
|
||||
|
||||
import './selected-access-method.scss'
|
||||
|
||||
|
||||
const SelectedAccessMethod: FC<SelectedAccessMethodPropsType> = ({
|
||||
unknownMethodKey,
|
||||
allRoutes,
|
||||
methods
|
||||
}) => {
|
||||
const checkIsUnknownMethod = (method: string) => {
|
||||
const routes = allRoutes[unknownMethodKey] || []
|
||||
return routes.find((route) => route.path === method)
|
||||
}
|
||||
|
||||
const renderMethodList = () => {
|
||||
const knownMethods: AccessListMethodType[] = []
|
||||
const unknownMethods: AccessListMethodType[] = []
|
||||
const sortAlphabetically = (a: AccessListMethodType, b: AccessListMethodType) =>
|
||||
a.method.localeCompare(b.method)
|
||||
methods.forEach((method) => {
|
||||
const isUnknown = checkIsUnknownMethod(method.method)
|
||||
if (isUnknown) {
|
||||
unknownMethods.push(method)
|
||||
} else {
|
||||
knownMethods.push(method)
|
||||
}
|
||||
})
|
||||
|
||||
const mergedMethods = [
|
||||
...knownMethods.sort(sortAlphabetically),
|
||||
...unknownMethods.sort(sortAlphabetically)
|
||||
]
|
||||
const allMethodsDisabled = mergedMethods.every((method) => !method.value)
|
||||
|
||||
if (allMethodsDisabled) {
|
||||
return <h3>Нет разрешенных методов</h3>
|
||||
}
|
||||
return mergedMethods.map((method) => {
|
||||
if (!method.value) {
|
||||
return null
|
||||
}
|
||||
return (
|
||||
<span
|
||||
className={`${checkIsUnknownMethod(method.method) ? 'unknown-label' : ''}`}
|
||||
key={method.method}
|
||||
>
|
||||
{method.method}
|
||||
</span>
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
return <div className="selected-access-method">{renderMethodList()}</div>
|
||||
}
|
||||
|
||||
export default SelectedAccessMethod
|
||||
@@ -0,0 +1,13 @@
|
||||
@import "src/constants/style/styleConst";
|
||||
|
||||
.selected-access-method {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: $basic-margin;
|
||||
padding: $basic-padding;
|
||||
border: 1px dashed $grey;
|
||||
|
||||
overflow-y: scroll;
|
||||
height: calc(100vh - 130px);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
import { AccessListMethodType, EndpointType } from '@type/accessList.type.ts'
|
||||
|
||||
export interface SelectedAccessMethodPropsType {
|
||||
unknownMethodKey: string
|
||||
methods: AccessListMethodType[]
|
||||
allRoutes: Record<string, EndpointType[]>
|
||||
}
|
||||
@@ -5,10 +5,12 @@ import svgr from 'vite-plugin-svgr'
|
||||
|
||||
import tsconfigPaths from 'vite-tsconfig-paths'
|
||||
|
||||
|
||||
// https://vitejs.dev/config/
|
||||
export default defineConfig(({ mode }) => {
|
||||
const env = loadEnv(mode, process.cwd(), '')
|
||||
return {
|
||||
optimizeDeps: { exclude: [] },
|
||||
define: {
|
||||
__APP_ENV__: env.APP_ENV,
|
||||
APP_VERSION: JSON.stringify(process.env.npm_package_version)
|
||||
|
||||
Reference in new issue
Block a user