Commit ce05a28b by zhaochengxiang

资产目录权限控制

parent feaef511
...@@ -46,7 +46,7 @@ export class App extends React.Component { ...@@ -46,7 +46,7 @@ export class App extends React.Component {
this.setState({ hostParams: this.props?.data }); this.setState({ hostParams: this.props?.data });
if (isSzseEnv) { if (isSzseEnv) {
this.getDataRoles(); this.getUserDataRoles();
} }
this.$$hostParams = $hostParams.subscribe({ this.$$hostParams = $hostParams.subscribe({
...@@ -63,9 +63,12 @@ export class App extends React.Component { ...@@ -63,9 +63,12 @@ export class App extends React.Component {
this.$$hostParams?.unsubscribe(); this.$$hostParams?.unsubscribe();
} }
getDataRoles = () => { getUserDataRoles = () => {
dispatch({ dispatch({
type: 'user.getDataRoles', type: 'user.getUserDataRoles',
payload: {
id: this.props.data?.user?.userId,
},
callback: data => { callback: data => {
this.setState({ dataRoles: data||[] }) this.setState({ dataRoles: data||[] })
} }
......
...@@ -18,3 +18,6 @@ export function* getDomains() { ...@@ -18,3 +18,6 @@ export function* getDomains() {
export function* getDataRoles() { export function* getDataRoles() {
return yield call(service.getDataRoles); return yield call(service.getDataRoles);
} }
export function* getUserDataRoles(payload) {
return yield call(service.getUserDataRoles, payload)
}
\ No newline at end of file
...@@ -26,3 +26,7 @@ export function getDomains() { ...@@ -26,3 +26,7 @@ export function getDomains() {
export function getDataRoles() { export function getDataRoles() {
return GetJSON("/authservice/dataRoles"); return GetJSON("/authservice/dataRoles");
} }
export function getUserDataRoles(payload) {
return GetJSON(`/authservice/users/${payload.id}/dataRoles`)
}
\ No newline at end of file
...@@ -413,3 +413,26 @@ export function isSystemAdmin(dataRoles) { ...@@ -413,3 +413,26 @@ export function isSystemAdmin(dataRoles) {
return flag; return flag;
} }
export function getAssetCatalogAuths(dataRoles) {
if (!isSzseEnv) return ["L1", "L2", "L3", "L4"];
if (dataRoles?.length > 0) {
let filterRoles = dataRoles?.filter(item => item.name==='sysadmin' || item.name==='系统管理员角色');
if (filterRoles?.length > 0) {
return ["L1", "L2", "L3", "L4"];
}
filterRoles = dataRoles?.filter(item => item.name === '行管部门');
if (filterRoles?.length > 0) {
return ["L3", "L4"];
}
filterRoles = dataRoles?.filter(item => item.name === '数据责任人' || item.name === '数据管家');
if (filterRoles?.length > 0) {
return ["L4"];
}
}
return [];
}
\ No newline at end of file
import React, { useEffect, useState, useRef } from 'react'; import React, { useEffect, useState, useRef, useContext } from 'react';
import {Card, Spin, Tooltip, Tree, Dropdown, Menu, Modal, AutoComplete} from 'antd'; import {Card, Spin, Tooltip, Tree, Dropdown, Menu, Modal, AutoComplete} from 'antd';
import { PlusOutlined, ImportOutlined,ExportOutlined,ReloadOutlined, SettingOutlined } from '@ant-design/icons'; import { PlusOutlined, ImportOutlined,ExportOutlined,ReloadOutlined, SettingOutlined } from '@ant-design/icons';
import classNames from 'classnames'; import classNames from 'classnames';
...@@ -9,9 +9,10 @@ import { dispatch } from '../../../../model'; ...@@ -9,9 +9,10 @@ import { dispatch } from '../../../../model';
import ImportDirectory from './ImportDirectory'; import ImportDirectory from './ImportDirectory';
import UpdateDirectoryModal from './UpdateDirectoryModal'; import UpdateDirectoryModal from './UpdateDirectoryModal';
import CustomDirectoryModal from './CustomDirectoryModal'; import CustomDirectoryModal from './CustomDirectoryModal';
import { showMessage, getQueryParam } from '../../../../util'; import { showMessage, getQueryParam, getAssetCatalogAuths } from '../../../../util';
import { AnchorTimestamp, AnchorId, AssetManageReference, AssetBrowseReference, ResourceBrowseReference, AssetMountReference, AnchorDirId } from '../../../../util/constant'; import { AnchorTimestamp, AnchorId, AssetManageReference, AssetBrowseReference, ResourceBrowseReference, AssetMountReference, AnchorDirId } from '../../../../util/constant';
import { highlightSearchContentByTerms } from '../../../../util'; import { highlightSearchContentByTerms } from '../../../../util';
import { AppContext } from '../../../../App';
import './AssetManageTree.less'; import './AssetManageTree.less';
import 'react-contexify/dist/ReactContexify.css'; import 'react-contexify/dist/ReactContexify.css';
...@@ -70,6 +71,8 @@ const AssetManageTree = (props) => { ...@@ -70,6 +71,8 @@ const AssetManageTree = (props) => {
const id = getQueryParam(AnchorId, props?.location?.search); const id = getQueryParam(AnchorId, props?.location?.search);
const did = getQueryParam(AnchorDirId, props?.location?.search); const did = getQueryParam(AnchorDirId, props?.location?.search);
const app = useContext(AppContext);
const treeDataRef = useRef([]); const treeDataRef = useRef([]);
const dataListRef = useRef([]); const dataListRef = useRef([]);
...@@ -704,6 +707,34 @@ const AssetManageTree = (props) => { ...@@ -704,6 +707,34 @@ const AssetManageTree = (props) => {
'asset-manage-tree-asset-mount-reference': reference===AssetMountReference, 'asset-manage-tree-asset-mount-reference': reference===AssetMountReference,
}); });
let addAble = true, addTip = '新增目录', updateAble = true, deleteAble = true;
if (currentDirType==='custom') {
addAble = false;
addTip = '自定义目录下不允许增加子目录';
} else {
if (currentDir) {
if (getAssetCatalogAuths(app?.dataRoles).indexOf('L1') === -1 && getAssetCatalogAuths(app?.dataRoles).indexOf(`L${currentDir?.level+1}`) === -1) {
addAble = false;
addTip = '无权限';
}
} else {
if (getAssetCatalogAuths(app?.dataRoles).indexOf('L1') === -1) {
addAble = false;
addTip = '无权限';
}
}
}
if (currentRightClickDir?.type==='custom'
|| getAssetCatalogAuths(app?.dataRoles).indexOf(`L${currentRightClickDir?.level}`) === -1) {
updateAble = false;
}
if ((currentRightClickDir.type==='custom'&&currentRightClickDir.level!==2)
|| getAssetCatalogAuths(app?.dataRoles).indexOf(`L${currentRightClickDir?.level}`) === -1) {
deleteAble = false;
}
return ( return (
<Card <Card
className={classes} className={classes}
...@@ -716,8 +747,12 @@ const AssetManageTree = (props) => { ...@@ -716,8 +747,12 @@ const AssetManageTree = (props) => {
justifyContent: 'space-around', justifyContent: 'space-around',
}} }}
> >
<Tooltip title="新增目录"> <Tooltip title={addTip}>
<PlusOutlined className={(currentDir?.resourceType==='custom')?'disable': 'default'} onClick={addDir} style={{ fontSize:16,cursor: (currentDirType==='custom')?'not-allowed':'pointer' }}/> <PlusOutlined className={!addAble?'disable': 'default'} onClick={() => {
if (addAble) {
addDir();
}
}} style={{ fontSize:16,cursor: !addAble?'not-allowed':'pointer' }}/>
</Tooltip> </Tooltip>
<Tooltip title="刷新目录"> <Tooltip title="刷新目录">
<ReloadOutlined className='default' onClick={refreshTree} style={{ fontSize:16,cursor:'pointer' }} /> <ReloadOutlined className='default' onClick={refreshTree} style={{ fontSize:16,cursor:'pointer' }} />
...@@ -791,6 +826,7 @@ const AssetManageTree = (props) => { ...@@ -791,6 +826,7 @@ const AssetManageTree = (props) => {
onCancel={ onUpdateDirectoryCancel } onCancel={ onUpdateDirectoryCancel }
action={ updateDirectoryAction } action={ updateDirectoryAction }
dirId={ (updateDirectoryAction==='add')?currentDirId:currentRightClickDir.nodeId } dirId={ (updateDirectoryAction==='add')?currentDirId:currentRightClickDir.nodeId }
level={currentRightClickDir?.level}
/> />
<ImportDirectory <ImportDirectory
visible={ importDirectoryVisible } visible={ importDirectoryVisible }
...@@ -806,7 +842,7 @@ const AssetManageTree = (props) => { ...@@ -806,7 +842,7 @@ const AssetManageTree = (props) => {
{ {
(reference!==AssetMountReference) && <RcMenu id={MENU_ID}> (reference!==AssetMountReference) && <RcMenu id={MENU_ID}>
{ {
currentRightClickDir && (currentRightClickDir.type!=='custom') && <RcItem id="edit" onClick={editDir}> currentRightClickDir && updateAble && <RcItem id="edit" onClick={editDir}>
{ (currentRightClickDir.level===1)?'修改栏目':'修改目录' } { (currentRightClickDir.level===1)?'修改栏目':'修改目录' }
</RcItem> </RcItem>
} }
...@@ -817,7 +853,7 @@ const AssetManageTree = (props) => { ...@@ -817,7 +853,7 @@ const AssetManageTree = (props) => {
{ (currentRightClickDir.level===1)?'下移栏目':'下移目录' } { (currentRightClickDir.level===1)?'下移栏目':'下移目录' }
</RcItem> </RcItem>
{ {
currentRightClickDir && (currentRightClickDir.type!=='custom'||(currentRightClickDir.type==='custom'&&currentRightClickDir.level===2)) && <RcItem id="delete" onClick={deleteDir}> currentRightClickDir && deleteAble && <RcItem id="delete" onClick={deleteDir}>
{ (currentRightClickDir.level===1)?'删除栏目':'删除目录' } { (currentRightClickDir.level===1)?'删除栏目':'删除目录' }
</RcItem> </RcItem>
} }
......
import React, { useEffect, useState } from 'react'; import React, { useEffect, useState, useContext } from 'react';
import { Modal, Form, Input, Space, Button, Radio, Select } from 'antd'; import { Modal, Form, Input, Space, Button, Radio, Select } from 'antd';
import { dispatch } from '../../../../model'; import { dispatch } from '../../../../model';
import { showMessage } from '../../../../util'; import { showMessage, getAssetCatalogAuths } from '../../../../util';
import { AppContext } from '../../../../App';
const resourceTypes = [ const resourceTypes = [
// { key: 'innerSource', name: '内部资源' }, // { key: 'innerSource', name: '内部资源' },
...@@ -13,13 +14,15 @@ const resourceTypes = [ ...@@ -13,13 +14,15 @@ const resourceTypes = [
const UpdateDirectoryModal = (props) => { const UpdateDirectoryModal = (props) => {
const { visible, onCancel, dirId, action } = props; const { visible, onCancel, dirId, action, level } = props;
const [ form ] = Form.useForm(); const [ form ] = Form.useForm();
const [ dir, setDir ] = useState(null); const [ dir, setDir ] = useState(null);
const [ confirmLoading, setConfirmLoading ] = useState(false); const [ confirmLoading, setConfirmLoading ] = useState(false);
const [ isThemeAdd, setIsThemeAdd ] = useState(false); const [ isThemeAdd, setIsThemeAdd ] = useState(false);
const app = useContext(AppContext);
useEffect(() => { useEffect(() => {
if (visible) { if (visible) {
...@@ -133,8 +136,10 @@ const UpdateDirectoryModal = (props) => { ...@@ -133,8 +136,10 @@ const UpdateDirectoryModal = (props) => {
const onValuesChange = (changedValues, allValues) => { const onValuesChange = (changedValues, allValues) => {
if (action==='add') { if (action==='add') {
if (changedValues.type === 'theme') { if (changedValues.type === 'theme') {
form.setFieldsValue({ remarks: 'L1' });
setIsThemeAdd(true); setIsThemeAdd(true);
} else if (changedValues.type === 'directory') { } else if (changedValues.type === 'directory') {
form.setFieldsValue({ remarks: `L${++level}` });
setIsThemeAdd(false); setIsThemeAdd(false);
} }
} }
...@@ -151,6 +156,15 @@ const UpdateDirectoryModal = (props) => { ...@@ -151,6 +156,15 @@ const UpdateDirectoryModal = (props) => {
}, },
}; };
let themeAble = true, catalogAble = true;
if (getAssetCatalogAuths(app?.dataRoles).indexOf('L1') === -1) {
themeAble = false;
}
if (dirId===null || getAssetCatalogAuths(app?.dataRoles).indexOf(`L${++level}`) === -1) {
catalogAble = false;
}
return ( return (
<Modal <Modal
forceRender forceRender
...@@ -174,8 +188,8 @@ const UpdateDirectoryModal = (props) => { ...@@ -174,8 +188,8 @@ const UpdateDirectoryModal = (props) => {
rules={[{ required: true, message: '必填项' }]} rules={[{ required: true, message: '必填项' }]}
> >
<Radio.Group> <Radio.Group>
<Radio value='theme'>栏目</Radio> <Radio value='theme' disabled={!themeAble}>栏目</Radio>
<Radio value='directory' disabled={ dirId===null }>目录</Radio> <Radio value='directory' disabled={!catalogAble}>目录</Radio>
</Radio.Group> </Radio.Group>
</Form.Item> </Form.Item>
} }
...@@ -228,10 +242,10 @@ const UpdateDirectoryModal = (props) => { ...@@ -228,10 +242,10 @@ const UpdateDirectoryModal = (props) => {
<Input.TextArea placeholder="请输入描述" autoSize={{ minRows: 4, maxRows: 4 }} /> <Input.TextArea placeholder="请输入描述" autoSize={{ minRows: 4, maxRows: 4 }} />
</Form.Item> </Form.Item>
<Form.Item <Form.Item
label="备注" label="目录等级"
name="remarks" name="remarks"
> >
<Input.TextArea placeholder="请输入备注" autoSize={{ minRows: 4, maxRows: 4 }} /> <Input placeholder="请输入目录等级" disabled={true} />
</Form.Item> </Form.Item>
</Form> </Form>
</Modal> </Modal>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment