Commit ce05a28b by zhaochengxiang

资产目录权限控制

parent feaef511
......@@ -46,7 +46,7 @@ export class App extends React.Component {
this.setState({ hostParams: this.props?.data });
if (isSzseEnv) {
this.getDataRoles();
this.getUserDataRoles();
}
this.$$hostParams = $hostParams.subscribe({
......@@ -63,9 +63,12 @@ export class App extends React.Component {
this.$$hostParams?.unsubscribe();
}
getDataRoles = () => {
getUserDataRoles = () => {
dispatch({
type: 'user.getDataRoles',
type: 'user.getUserDataRoles',
payload: {
id: this.props.data?.user?.userId,
},
callback: data => {
this.setState({ dataRoles: data||[] })
}
......
......@@ -18,3 +18,6 @@ export function* getDomains() {
export function* 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() {
export function getDataRoles() {
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) {
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 { PlusOutlined, ImportOutlined,ExportOutlined,ReloadOutlined, SettingOutlined } from '@ant-design/icons';
import classNames from 'classnames';
......@@ -9,9 +9,10 @@ import { dispatch } from '../../../../model';
import ImportDirectory from './ImportDirectory';
import UpdateDirectoryModal from './UpdateDirectoryModal';
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 { highlightSearchContentByTerms } from '../../../../util';
import { AppContext } from '../../../../App';
import './AssetManageTree.less';
import 'react-contexify/dist/ReactContexify.css';
......@@ -70,6 +71,8 @@ const AssetManageTree = (props) => {
const id = getQueryParam(AnchorId, props?.location?.search);
const did = getQueryParam(AnchorDirId, props?.location?.search);
const app = useContext(AppContext);
const treeDataRef = useRef([]);
const dataListRef = useRef([]);
......@@ -704,6 +707,34 @@ const AssetManageTree = (props) => {
'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 (
<Card
className={classes}
......@@ -716,8 +747,12 @@ const AssetManageTree = (props) => {
justifyContent: 'space-around',
}}
>
<Tooltip title="新增目录">
<PlusOutlined className={(currentDir?.resourceType==='custom')?'disable': 'default'} onClick={addDir} style={{ fontSize:16,cursor: (currentDirType==='custom')?'not-allowed':'pointer' }}/>
<Tooltip title={addTip}>
<PlusOutlined className={!addAble?'disable': 'default'} onClick={() => {
if (addAble) {
addDir();
}
}} style={{ fontSize:16,cursor: !addAble?'not-allowed':'pointer' }}/>
</Tooltip>
<Tooltip title="刷新目录">
<ReloadOutlined className='default' onClick={refreshTree} style={{ fontSize:16,cursor:'pointer' }} />
......@@ -791,6 +826,7 @@ const AssetManageTree = (props) => {
onCancel={ onUpdateDirectoryCancel }
action={ updateDirectoryAction }
dirId={ (updateDirectoryAction==='add')?currentDirId:currentRightClickDir.nodeId }
level={currentRightClickDir?.level}
/>
<ImportDirectory
visible={ importDirectoryVisible }
......@@ -806,7 +842,7 @@ const AssetManageTree = (props) => {
{
(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)?'修改栏目':'修改目录' }
</RcItem>
}
......@@ -817,7 +853,7 @@ const AssetManageTree = (props) => {
{ (currentRightClickDir.level===1)?'下移栏目':'下移目录' }
</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)?'删除栏目':'删除目录' }
</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 { dispatch } from '../../../../model';
import { showMessage } from '../../../../util';
import { showMessage, getAssetCatalogAuths } from '../../../../util';
import { AppContext } from '../../../../App';
const resourceTypes = [
// { key: 'innerSource', name: '内部资源' },
......@@ -13,13 +14,15 @@ const resourceTypes = [
const UpdateDirectoryModal = (props) => {
const { visible, onCancel, dirId, action } = props;
const { visible, onCancel, dirId, action, level } = props;
const [ form ] = Form.useForm();
const [ dir, setDir ] = useState(null);
const [ confirmLoading, setConfirmLoading ] = useState(false);
const [ isThemeAdd, setIsThemeAdd ] = useState(false);
const app = useContext(AppContext);
useEffect(() => {
if (visible) {
......@@ -133,8 +136,10 @@ const UpdateDirectoryModal = (props) => {
const onValuesChange = (changedValues, allValues) => {
if (action==='add') {
if (changedValues.type === 'theme') {
form.setFieldsValue({ remarks: 'L1' });
setIsThemeAdd(true);
} else if (changedValues.type === 'directory') {
form.setFieldsValue({ remarks: `L${++level}` });
setIsThemeAdd(false);
}
}
......@@ -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 (
<Modal
forceRender
......@@ -174,8 +188,8 @@ const UpdateDirectoryModal = (props) => {
rules={[{ required: true, message: '必填项' }]}
>
<Radio.Group>
<Radio value='theme'>栏目</Radio>
<Radio value='directory' disabled={ dirId===null }>目录</Radio>
<Radio value='theme' disabled={!themeAble}>栏目</Radio>
<Radio value='directory' disabled={!catalogAble}>目录</Radio>
</Radio.Group>
</Form.Item>
}
......@@ -228,10 +242,10 @@ const UpdateDirectoryModal = (props) => {
<Input.TextArea placeholder="请输入描述" autoSize={{ minRows: 4, maxRows: 4 }} />
</Form.Item>
<Form.Item
label="备注"
label="目录等级"
name="remarks"
>
<Input.TextArea placeholder="请输入备注" autoSize={{ minRows: 4, maxRows: 4 }} />
<Input placeholder="请输入目录等级" disabled={true} />
</Form.Item>
</Form>
</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