mirror of https://github.com/openspug/spug
U 优化任务计划和监控中心主机权限控制
parent
028fd2532b
commit
aea01f4c86
|
@ -193,6 +193,7 @@ def handle_user_info(user, x_real_ip):
|
|||
'nickname': user.nickname,
|
||||
'is_supper': user.is_supper,
|
||||
'has_real_ip': True if x_real_ip else False,
|
||||
'host_perms': [] if user.is_supper else user.host_perms,
|
||||
'permissions': [] if user.is_supper else user.page_perms
|
||||
})
|
||||
|
||||
|
|
|
@ -24,8 +24,9 @@ export default class extends React.Component {
|
|||
|
||||
initPermissions() {
|
||||
const data = localStorage.getItem('permissions');
|
||||
const hostPerms = localStorage.getItem('host_perms');
|
||||
const isSuper = localStorage.getItem('is_supper') === 'true';
|
||||
data && updatePermissions(isSuper, JSON.parse(data))
|
||||
data && updatePermissions(isSuper, JSON.parse(hostPerms), JSON.parse(data))
|
||||
}
|
||||
|
||||
render() {
|
||||
|
|
|
@ -5,11 +5,13 @@
|
|||
*/
|
||||
let Permission = {
|
||||
isSuper: false,
|
||||
hostPerms: [],
|
||||
permissions: []
|
||||
};
|
||||
|
||||
export function updatePermissions(isSupper, data) {
|
||||
export function updatePermissions(isSupper, hostPerms, data) {
|
||||
Permission.isSuper = isSupper;
|
||||
Permission.hostPerms = hostPerms;
|
||||
Permission.permissions = data;
|
||||
}
|
||||
|
||||
|
@ -26,6 +28,11 @@ export function hasPermission(strCode) {
|
|||
return false
|
||||
}
|
||||
|
||||
export function hasHostPermission(id) {
|
||||
const {isSuper, hostPerms} = Permission;
|
||||
return isSuper || hostPerms.includes(id)
|
||||
}
|
||||
|
||||
// 清理输入的命令中包含的\r符号
|
||||
export function cleanCommand(text) {
|
||||
return text ? text.replace(/\r\n/g, '\n') : ''
|
||||
|
|
|
@ -61,7 +61,8 @@ class LoginIndex extends React.Component {
|
|||
localStorage.setItem('nickname', data['nickname']);
|
||||
localStorage.setItem('is_supper', data['is_supper']);
|
||||
localStorage.setItem('permissions', JSON.stringify(data['permissions']));
|
||||
updatePermissions(data['is_supper'], data['permissions']);
|
||||
localStorage.setItem('host_perms', JSON.stringify(data['host_perms']));
|
||||
updatePermissions(data['is_supper'], data['host_perms'], data['permissions']);
|
||||
if (history.location.state && history.location.state['from']) {
|
||||
history.push(history.location.state['from'])
|
||||
} else {
|
||||
|
|
|
@ -8,7 +8,7 @@ import { observer } from 'mobx-react';
|
|||
import { Modal, Form, Input, Select, Radio, message, Steps, Button, Transfer, Checkbox } from 'antd';
|
||||
import TemplateSelector from '../exec/task/TemplateSelector';
|
||||
import { LinkButton, ACEditor } from 'components';
|
||||
import { http, cleanCommand } from 'libs';
|
||||
import { http, cleanCommand, hasHostPermission } from 'libs';
|
||||
import store from './store';
|
||||
import hostStore from '../host/store';
|
||||
import groupStore from '../alarm/group/store';
|
||||
|
@ -152,7 +152,7 @@ class ComForm extends React.Component {
|
|||
optionFilterProp="children"
|
||||
filterOption={(input, option) => option.props.children.toLowerCase().indexOf(input.toLowerCase()) >= 0}
|
||||
onChange={v => this.handleAddr('3', v)}>
|
||||
{hostStore.records.map(item => (
|
||||
{hostStore.records.filter(x => x.id === Number(addr['3']) || hasHostPermission(x.id)).map(item => (
|
||||
<Select.Option value={String(item.id)} key={item.id}>
|
||||
{`${item.name}(${item.hostname}:${item.port})`}
|
||||
</Select.Option>
|
||||
|
|
|
@ -8,7 +8,7 @@ import { observer } from 'mobx-react';
|
|||
import { Modal, Form, Input, Select, Col, Button, Steps, Tabs, InputNumber, DatePicker, Icon, message } from 'antd';
|
||||
import { LinkButton, ACEditor } from 'components';
|
||||
import TemplateSelector from '../exec/task/TemplateSelector';
|
||||
import { http, cleanCommand } from 'libs';
|
||||
import { http, cleanCommand, hasHostPermission } from 'libs';
|
||||
import store from './store';
|
||||
import hostStore from '../host/store';
|
||||
import styles from './index.module.css';
|
||||
|
@ -184,7 +184,7 @@ class ComForm extends React.Component {
|
|||
filterOption={(input, option) => option.props.children.toLowerCase().indexOf(input.toLowerCase()) >= 0}
|
||||
onChange={v => store.editTarget(index, v)}>
|
||||
<Select.Option value="local" disabled={store.targets.includes('local')}>本机</Select.Option>
|
||||
{hostStore.records.map(item => (
|
||||
{hostStore.records.filter(x => x.id === id || hasHostPermission(x.id)).map(item => (
|
||||
<Select.Option key={item.id} value={item.id} disabled={store.targets.includes(item.id)}>
|
||||
{`${item.name}(${item['hostname']}:${item['port']})`}
|
||||
</Select.Option>
|
||||
|
@ -197,7 +197,7 @@ class ComForm extends React.Component {
|
|||
))}
|
||||
</Form.Item>
|
||||
<Form.Item wrapperCol={{span: 14, offset: 6}}>
|
||||
<Button type="dashed" style={{width: '60%'}} onClick={store.addTarget}>
|
||||
<Button type="dashed" style={{width: '80%'}} onClick={store.addTarget}>
|
||||
<Icon type="plus"/>添加执行对象
|
||||
</Button>
|
||||
</Form.Item>
|
||||
|
|
Loading…
Reference in New Issue