diff --git a/spug_api/apps/account/views.py b/spug_api/apps/account/views.py
index afb9675..1ad9246 100644
--- a/spug_api/apps/account/views.py
+++ b/spug_api/apps/account/views.py
@@ -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
})
diff --git a/spug_web/src/layout/index.js b/spug_web/src/layout/index.js
index 691ca3c..0a57e64 100644
--- a/spug_web/src/layout/index.js
+++ b/spug_web/src/layout/index.js
@@ -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() {
diff --git a/spug_web/src/libs/functools.js b/spug_web/src/libs/functools.js
index 04d0ed2..10b5932 100644
--- a/spug_web/src/libs/functools.js
+++ b/spug_web/src/libs/functools.js
@@ -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') : ''
diff --git a/spug_web/src/pages/login/index.js b/spug_web/src/pages/login/index.js
index b0ab671..55d7753 100644
--- a/spug_web/src/pages/login/index.js
+++ b/spug_web/src/pages/login/index.js
@@ -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 {
diff --git a/spug_web/src/pages/monitor/Form.js b/spug_web/src/pages/monitor/Form.js
index 714d09c..b413266 100644
--- a/spug_web/src/pages/monitor/Form.js
+++ b/spug_web/src/pages/monitor/Form.js
@@ -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 => (