Browse Source

(*)数据服务权限完善

master
peng.peng 1 year ago
parent
commit
1aefb64092
  1. 11
      api/app/lib/controllers/dataService/index.js
  2. 109
      web/client/src/sections/dataService/containers/serviceManagement.js
  3. 67
      web/client/src/sections/dataService/containers/serviceView.js
  4. 4
      web/client/src/sections/dataService/nav-item.js
  5. 31
      web/client/src/sections/resourceConsumption/containers/approve.js

11
api/app/lib/controllers/dataService/index.js

@ -15,7 +15,16 @@ function getServiceManagement(opts) {
order: [["id", "desc"]], order: [["id", "desc"]],
include: [{ include: [{
model: models.ResourceConsumption, model: models.ResourceConsumption,
}], },
{
model: models.ResourceCatalog,
attributes: ['id', 'name'],
include: [{
model: models.Organization,
attributes: ['id', 'name'],
}]
}
],
distinct: true distinct: true
} }
if (keyword) { if (keyword) {

109
web/client/src/sections/dataService/containers/serviceManagement.js

@ -2,7 +2,7 @@ import React, { useEffect, useState } from 'react'
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import moment from 'moment'; import moment from 'moment';
import { RouteRequest } from '@peace/utils'; import { RouteRequest } from '@peace/utils';
import { RouteTable } from '$utils' import { Func } from '$utils'
import { Tabs, Form, Input, Space, Button, Table, Popconfirm, message } from 'antd'; import { Tabs, Form, Input, Space, Button, Table, Popconfirm, message } from 'antd';
const { Search } = Input; const { Search } = Input;
@ -10,7 +10,7 @@ const { Search } = Input;
import EditModal from '../components/editModal'; import EditModal from '../components/editModal';
function ServiceManagement ({ loading, clientHeight, actions, dispatch, }) { function ServiceManagement({ loading, clientHeight, actions, dispatch, }) {
const { dataService } = actions const { dataService } = actions
const [query, setQuery] = useState({ page: 0, limit: 10 }); const [query, setQuery] = useState({ page: 0, limit: 10 });
@ -53,63 +53,66 @@ function ServiceManagement ({ loading, clientHeight, actions, dispatch, }) {
dataIndex: 'handle', dataIndex: 'handle',
width: '250px', width: '250px',
// ellipsis: true, // ellipsis: true,
render: (text, record) => <div style={{ width: 200, display: 'flex', justifyContent: 'space-evenly' }}> render: (text, record) => {
<a onClick={() => { const isCurrentOrg = Func?.isOrgOrSuperAdmin(record?.resourceCatalog?.organization?.id)
setEditData(record) return <div style={{ width: 200, display: 'flex', justifyContent: 'space-evenly' }}>
setEditModal(true) <a onClick={() => {
setViewDetails(true) setEditData(record)
}}>查看详情</a> setEditModal(true)
<a onClick={() => { setViewDetails(true)
setEditData(record) }}>查看详情</a>
setEditModal(true) {isCurrentOrg && <a onClick={() => {
}}>编辑</a> setEditData(record)
setEditModal(true)
{/* {record?.enabled ? */} }}>编辑</a>
{record?.resourceConsumptions?.length > 0 ? <a onClick={() => { }
message.warning('已有关联数据,无法删除') {/* {record?.enabled ? */}
}}>删除</a> {!isCurrentOrg ? '' : record?.resourceConsumptions?.length > 0 ? <a onClick={() => {
: <Popconfirm message.warning('已有关联数据,无法删除')
title="是否确认删除该服务?" }}>删除</a>
onConfirm={() => { : <Popconfirm
dispatch(dataService.delServiceManagement(record.id)).then(res => { title="是否确认删除该服务?"
if (res.success) { onConfirm={() => {
setQuery({ limit: 10, page: 0 }); dispatch(dataService.delServiceManagement(record.id)).then(res => {
resourceData({ limit: 10, page: 0, keyword }) if (res.success) {
} setQuery({ limit: 10, page: 0 });
}) resourceData({ limit: 10, page: 0, keyword })
}} }
> })
<a >删除</a> }}
</Popconfirm>} >
<a >删除</a>
{/* // } */} </Popconfirm>}
{record?.enabled ?
<Popconfirm {/* // } */}
title="禁用后该服务将不可用" {!isCurrentOrg ? '' : record?.enabled ?
onConfirm={() => { <Popconfirm
title="禁用后该服务将不可用"
onConfirm={() => {
dispatch(dataService.postServiceManagement({
id: record.id, name: record?.name, enabled: false
}, true)).then(res => {
if (res.success) {
resourceData({ keyword })
}
})
}}
>
<a>禁用</a>
</Popconfirm>
: <a onClick={() => {
dispatch(dataService.postServiceManagement({ dispatch(dataService.postServiceManagement({
id: record.id, name: record?.name, enabled: false id: record.id, name: record?.name, enabled: true
}, true)).then(res => { }, true)).then(res => {
if (res.success) { if (res.success) {
resourceData({ keyword }) resourceData({ keyword })
} }
}) })
}} }}>启用</a>
> }
<a>禁用</a>
</Popconfirm>
: <a onClick={() => {
dispatch(dataService.postServiceManagement({
id: record.id, name: record?.name, enabled: true
}, true)).then(res => {
if (res.success) {
resourceData({ keyword })
}
})
}}>启用</a>
}
</div > </div >
}
}, },
]; ];
@ -174,7 +177,7 @@ function ServiceManagement ({ loading, clientHeight, actions, dispatch, }) {
</> </>
} }
function mapStateToProps (state) { function mapStateToProps(state) {
const { global, auth, resourceCatalog } = state; const { global, auth, resourceCatalog } = state;
return { return {
user: auth.user, user: auth.user,

67
web/client/src/sections/dataService/containers/serviceView.js

@ -2,7 +2,7 @@ import React, { useEffect, useState } from 'react'
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import moment from 'moment'; import moment from 'moment';
import { RouteRequest } from '@peace/utils'; import { RouteRequest } from '@peace/utils';
import { RouteTable } from '$utils' import { Func } from '$utils'
import { Tabs, Form, Input, Space, Button, Table, message } from 'antd'; import { Tabs, Form, Input, Space, Button, Table, message } from 'antd';
const { Search } = Input; const { Search } = Input;
@ -14,7 +14,7 @@ import ResourceModal from '../components/resourceModal';
import { If } from 'react-if'; import { If } from 'react-if';
function ServiceView ({ loading, clientHeight, actions, dispatch, }) { function ServiceView({ loading, clientHeight, actions, dispatch, user }) {
const { dataService, metadataManagement } = actions const { dataService, metadataManagement } = actions
const [query, setQuery] = useState({ page: 0, limit: 10 }); const [query, setQuery] = useState({ page: 0, limit: 10 });
@ -54,38 +54,43 @@ function ServiceView ({ loading, clientHeight, actions, dispatch, }) {
dataIndex: 'handle', dataIndex: 'handle',
width: '250px', width: '250px',
// ellipsis: true, // ellipsis: true,
render: (text, record) => <div style={{ width: 200, display: 'flex', justifyContent: 'space-evenly' }}> render: (text, record) => {
<a onClick={() => { const isCurrentOrg = Func?.isOrgOrSuperAdmin(record?.resourceCatalog?.organization?.id)
setEditData(record) return <div style={{ width: 200, display: 'flex', justifyContent: 'space-evenly' }}>
setEditModal(true) <a onClick={() => {
setViewDetails(true)
}}>查看详情</a>
<a onClick={() => {
let result
record?.resourceConsumptions?.map(v => {
if (result != '已有申请成功的资源' && result != '资源审批中') {
if (v.token) {
result = '已有申请成功的资源'
} else if (v.approveState == '审批中') {
result = '资源审批中'
}
}
})
if (result) {
message.warning({
duration: 1,
content: result,
})
} else {
setEditData(record) setEditData(record)
setResourceModal(true) setEditModal(true)
setViewDetails(true)
}}>查看详情</a>
{!isCurrentOrg && <a onClick={() => {
let result
record?.resourceConsumptions
?.filter(v => v.applyBy == user?.id)
?.map(v => {
if (result != '已有申请成功的资源' && result != '资源审批中') {
if (v.token) {
result = '已有申请成功的资源'
} else if (v.approveState == '审批中') {
result = '资源审批中'
}
}
})
if (result) {
message.warning({
duration: 1,
content: result,
})
} else {
setEditData(record)
setResourceModal(true)
}
}}>申请资源</a>
} }
}}>申请资源</a>
</div >
</div > }
}, },
]; ];
@ -165,7 +170,7 @@ function ServiceView ({ loading, clientHeight, actions, dispatch, }) {
</> </>
} }
function mapStateToProps (state) { function mapStateToProps(state) {
const { global, auth, resourceCatalog } = state; const { global, auth, resourceCatalog } = state;
return { return {
user: auth.user, user: auth.user,

4
web/client/src/sections/dataService/nav-item.js

@ -4,14 +4,14 @@ import { Menu } from 'antd';
import { CarryOutOutlined } from '@ant-design/icons'; import { CarryOutOutlined } from '@ant-design/icons';
const SubMenu = Menu.SubMenu; const SubMenu = Menu.SubMenu;
export function getNavItem (user) { export function getNavItem(user) {
return ( return (
<SubMenu key="dataService" icon={<CarryOutOutlined />} title='数据服务'> <SubMenu key="dataService" icon={<CarryOutOutlined />} title='数据服务'>
{user?.role == '系统管理员' && <Menu.Item key="serviceManagement"> {user?.role == '系统管理员' && <Menu.Item key="serviceManagement">
<Link to="/dataService/serviceManagement">服务管理</Link> <Link to="/dataService/serviceManagement">服务管理</Link>
</Menu.Item>} </Menu.Item>}
{user?.role != '系统管理员' && <Menu.Item key="serviceView"> {<Menu.Item key="serviceView">
<Link to="/dataService/serviceView">服务查看</Link> <Link to="/dataService/serviceView">服务查看</Link>
</Menu.Item>} </Menu.Item>}
</ SubMenu > </ SubMenu >

31
web/client/src/sections/resourceConsumption/containers/approve.js

@ -21,14 +21,24 @@ function Approve({ loading, clientHeight, actions, dispatch, user }) {
resourceData() resourceData()
}, []) }, [])
useEffect(() => {
resourceData()
}, [tabsKey, query])
let resourceData = (params) => { let resourceData = (params) => {
let data = params || query let data = params || query
dispatch(resourceConsumption.getApproveList({ const obj = {
approveState: tabsKey == 'stay' ? "审批中" : '已审批', ...formData, ...data, approveState: tabsKey == 'stay' ? "审批中" : '已审批',
orgId: user?.orgId, ...formData, ...data,
approveId: (params?.approveState == '已审批' && user?.username != 'SuperAdmin') ? user?.id : null approveId: (tabsKey == 'stay' && user?.username != 'SuperAdmin') ? user?.id : null,
})).then(res => { }
if (tabsKey == 'stay') {
obj.orgId = user?.orgId;
} else {
obj.applyById = user?.id;
}
dispatch(resourceConsumption.getApproveList(obj)).then(res => {
if (res.success) { if (res.success) {
setProTableList(res.payload.data) setProTableList(res.payload.data)
} }
@ -120,11 +130,12 @@ function Approve({ loading, clientHeight, actions, dispatch, user }) {
}, [tabsKey]) }, [tabsKey])
return <> return <>
<Tabs defaultActiveKey="stay" items={[{ key: 'stay', label: '待审批' }, { key: 'end', label: '已审批' }]} onTabClick={key => { <Tabs defaultActiveKey="stay" items={[{ key: 'stay', label: '待审批' }, { key: 'end', label: '已审批' }]}
setTabsKey(key) onTabClick={key => {
resourceData({ limit: 10, page: 0, approveState: key == 'stay' ? "审批中" : '已审批' }) setTabsKey(key)
setQuery({ limit: 10, page: 0 }); // resourceData({ limit: 10, page: 0, approveState: key == 'stay' ? "审批中" : '已审批' })
}} /> setQuery({ limit: 10, page: 0 });
}} />
<Form <Form
style={{ display: 'flex' }} style={{ display: 'flex' }}
onFinish={v => { onFinish={v => {

Loading…
Cancel
Save