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"]],
include: [{
model: models.ResourceConsumption,
}],
},
{
model: models.ResourceCatalog,
attributes: ['id', 'name'],
include: [{
model: models.Organization,
attributes: ['id', 'name'],
}]
}
],
distinct: true
}
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 moment from 'moment';
import { RouteRequest } from '@peace/utils';
import { RouteTable } from '$utils'
import { Func } from '$utils'
import { Tabs, Form, Input, Space, Button, Table, Popconfirm, message } from 'antd';
const { Search } = Input;
@ -10,7 +10,7 @@ const { Search } = Input;
import EditModal from '../components/editModal';
function ServiceManagement ({ loading, clientHeight, actions, dispatch, }) {
function ServiceManagement({ loading, clientHeight, actions, dispatch, }) {
const { dataService } = actions
const [query, setQuery] = useState({ page: 0, limit: 10 });
@ -53,63 +53,66 @@ function ServiceManagement ({ loading, clientHeight, actions, dispatch, }) {
dataIndex: 'handle',
width: '250px',
// ellipsis: true,
render: (text, record) => <div style={{ width: 200, display: 'flex', justifyContent: 'space-evenly' }}>
<a onClick={() => {
setEditData(record)
setEditModal(true)
setViewDetails(true)
}}>查看详情</a>
<a onClick={() => {
setEditData(record)
setEditModal(true)
}}>编辑</a>
{/* {record?.enabled ? */}
{record?.resourceConsumptions?.length > 0 ? <a onClick={() => {
message.warning('已有关联数据,无法删除')
}}>删除</a>
: <Popconfirm
title="是否确认删除该服务?"
onConfirm={() => {
dispatch(dataService.delServiceManagement(record.id)).then(res => {
if (res.success) {
setQuery({ limit: 10, page: 0 });
resourceData({ limit: 10, page: 0, keyword })
}
})
}}
>
<a >删除</a>
</Popconfirm>}
{/* // } */}
{record?.enabled ?
<Popconfirm
title="禁用后该服务将不可用"
onConfirm={() => {
render: (text, record) => {
const isCurrentOrg = Func?.isOrgOrSuperAdmin(record?.resourceCatalog?.organization?.id)
return <div style={{ width: 200, display: 'flex', justifyContent: 'space-evenly' }}>
<a onClick={() => {
setEditData(record)
setEditModal(true)
setViewDetails(true)
}}>查看详情</a>
{isCurrentOrg && <a onClick={() => {
setEditData(record)
setEditModal(true)
}}>编辑</a>
}
{/* {record?.enabled ? */}
{!isCurrentOrg ? '' : record?.resourceConsumptions?.length > 0 ? <a onClick={() => {
message.warning('已有关联数据,无法删除')
}}>删除</a>
: <Popconfirm
title="是否确认删除该服务?"
onConfirm={() => {
dispatch(dataService.delServiceManagement(record.id)).then(res => {
if (res.success) {
setQuery({ limit: 10, page: 0 });
resourceData({ limit: 10, page: 0, keyword })
}
})
}}
>
<a >删除</a>
</Popconfirm>}
{/* // } */}
{!isCurrentOrg ? '' : record?.enabled ?
<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({
id: record.id, name: record?.name, enabled: false
id: record.id, name: record?.name, enabled: true
}, true)).then(res => {
if (res.success) {
resourceData({ keyword })
}
})
}}
>
<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>
}
}}>启用</a>
}
</div >
</div >
}
},
];
@ -174,7 +177,7 @@ function ServiceManagement ({ loading, clientHeight, actions, dispatch, }) {
</>
}
function mapStateToProps (state) {
function mapStateToProps(state) {
const { global, auth, resourceCatalog } = state;
return {
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 moment from 'moment';
import { RouteRequest } from '@peace/utils';
import { RouteTable } from '$utils'
import { Func } from '$utils'
import { Tabs, Form, Input, Space, Button, Table, message } from 'antd';
const { Search } = Input;
@ -14,7 +14,7 @@ import ResourceModal from '../components/resourceModal';
import { If } from 'react-if';
function ServiceView ({ loading, clientHeight, actions, dispatch, }) {
function ServiceView({ loading, clientHeight, actions, dispatch, user }) {
const { dataService, metadataManagement } = actions
const [query, setQuery] = useState({ page: 0, limit: 10 });
@ -54,38 +54,43 @@ function ServiceView ({ loading, clientHeight, actions, dispatch, }) {
dataIndex: 'handle',
width: '250px',
// ellipsis: true,
render: (text, record) => <div style={{ width: 200, display: 'flex', justifyContent: 'space-evenly' }}>
<a onClick={() => {
setEditData(record)
setEditModal(true)
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 {
render: (text, record) => {
const isCurrentOrg = Func?.isOrgOrSuperAdmin(record?.resourceCatalog?.organization?.id)
return <div style={{ width: 200, display: 'flex', justifyContent: 'space-evenly' }}>
<a onClick={() => {
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;
return {
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';
const SubMenu = Menu.SubMenu;
export function getNavItem (user) {
export function getNavItem(user) {
return (
<SubMenu key="dataService" icon={<CarryOutOutlined />} title='数据服务'>
{user?.role == '系统管理员' && <Menu.Item key="serviceManagement">
<Link to="/dataService/serviceManagement">服务管理</Link>
</Menu.Item>}
{user?.role != '系统管理员' && <Menu.Item key="serviceView">
{<Menu.Item key="serviceView">
<Link to="/dataService/serviceView">服务查看</Link>
</Menu.Item>}
</ SubMenu >

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

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

Loading…
Cancel
Save