mirror of https://github.com/veops/cmdb.git
relation view bugfix
This commit is contained in:
parent
f424ad6864
commit
d5fbe42ed7
|
@ -9,6 +9,7 @@ from flask import session, abort
|
|||
from api.lib.cmdb.const import ResourceTypeEnum as CmdbResourceType
|
||||
from api.lib.cmdb.const import RoleEnum
|
||||
from api.lib.perm.acl.cache import AppCache
|
||||
from api.lib.perm.acl.cache import RoleCache
|
||||
from api.lib.perm.acl.cache import UserCache
|
||||
from api.lib.perm.acl.permission import PermissionCRUD
|
||||
from api.lib.perm.acl.resource import ResourceCRUD
|
||||
|
@ -123,6 +124,10 @@ def is_app_admin():
|
|||
if RoleEnum.CONFIG in session.get("acl", {}).get("parentRoles", []):
|
||||
return True
|
||||
|
||||
for role in session.get("acl", {}).get("parentRoles", []):
|
||||
if RoleCache.get(role).is_app_admin:
|
||||
return True
|
||||
|
||||
return False
|
||||
|
||||
|
||||
|
|
|
@ -81,6 +81,9 @@ class RoleRelationCRUD(object):
|
|||
def add(parent_id, child_id):
|
||||
RoleRelation.get_by(parent_id=parent_id, child_id=child_id) and abort(400, "It's already existed")
|
||||
|
||||
RoleRelationCache.clean(parent_id)
|
||||
RoleRelationCache.clean(child_id)
|
||||
|
||||
return RoleRelation.create(parent_id=parent_id, child_id=child_id)
|
||||
|
||||
@classmethod
|
||||
|
@ -91,6 +94,9 @@ class RoleRelationCRUD(object):
|
|||
for child_id in child_ids:
|
||||
role_rebuild.apply_async(args=(child_id,), queue=ACL_QUEUE)
|
||||
|
||||
RoleRelationCache.clean(existed.parent_id)
|
||||
RoleRelationCache.clean(existed.child_id)
|
||||
|
||||
existed.soft_delete()
|
||||
|
||||
@classmethod
|
||||
|
@ -102,6 +108,9 @@ class RoleRelationCRUD(object):
|
|||
for child_id in child_ids:
|
||||
role_rebuild.apply_async(args=(child_id,), queue=ACL_QUEUE)
|
||||
|
||||
RoleRelationCache.clean(existed.parent_id)
|
||||
RoleRelationCache.clean(existed.child_id)
|
||||
|
||||
existed.soft_delete()
|
||||
|
||||
|
||||
|
|
|
@ -20,6 +20,7 @@ class GetUserInfoView(APIView):
|
|||
name = session.get("CAS_USERNAME") or current_user.nickname
|
||||
role = dict(permissions=session.get("acl", {}).get("parentRoles", []))
|
||||
avatar = current_user.avatar
|
||||
|
||||
return self.jsonify(result=dict(name=name,
|
||||
role=role,
|
||||
avatar=avatar))
|
||||
|
|
|
@ -15,8 +15,10 @@
|
|||
:wrapper-col="formItemLayout.wrapperCol"
|
||||
label="角色列表"
|
||||
>
|
||||
<a-select name="otherID" v-decorator="['otherID', {rules: [{ required: true, message: '请选择另一个角色'}]} ]">
|
||||
<a-select-option v-for="role in allRoles" v-if="role.id != current_record.id" :key="role.id">{{ role.name }}</a-select-option>
|
||||
<a-select name="otherID" :filterOption="filterOption" v-decorator="['otherID', {rules: [{ required: true, message: '请选择另一个角色'}]} ]">
|
||||
<template v-for="role in allRoles">
|
||||
<a-select-option v-if="role.id != current_record.id" :key="role.id">{{ role.name }}</a-select-option>
|
||||
</template>
|
||||
</a-select>
|
||||
</a-form-item>
|
||||
|
||||
|
@ -97,10 +99,13 @@ export default {
|
|||
} : {}
|
||||
}
|
||||
|
||||
},
|
||||
mounted () {
|
||||
},
|
||||
methods: {
|
||||
filterOption (input, option) {
|
||||
return (
|
||||
option.componentOptions.children[0].text.toLowerCase().indexOf(input.toLowerCase()) >= 0
|
||||
)
|
||||
},
|
||||
onClose () {
|
||||
this.form.resetFields()
|
||||
this.drawerVisible = false
|
||||
|
|
|
@ -151,7 +151,6 @@ export default {
|
|||
|
||||
handleEdit (record) {
|
||||
this.drawerVisible = true
|
||||
console.log(record)
|
||||
this.$nextTick(() => {
|
||||
this.form.setFieldsValue({
|
||||
id: record.id,
|
||||
|
@ -165,8 +164,6 @@ export default {
|
|||
e.preventDefault()
|
||||
this.form.validateFields((err, values) => {
|
||||
if (!err) {
|
||||
console.log('Received values of form: ', values)
|
||||
|
||||
values.app_id = this.$route.name.split('_')[0]
|
||||
values.perms = this.perms
|
||||
if (values.id) {
|
||||
|
|
|
@ -138,8 +138,6 @@ export default {
|
|||
e.preventDefault()
|
||||
this.form.validateFields((err, values) => {
|
||||
if (!err) {
|
||||
console.log('Received values of form: ', values)
|
||||
|
||||
values.app_id = this.$route.name.split('_')[0]
|
||||
if (values.id) {
|
||||
this.updateResource(values.id, values)
|
||||
|
|
|
@ -132,7 +132,6 @@ export default {
|
|||
|
||||
handleEdit (record) {
|
||||
this.drawerVisible = true
|
||||
console.log(record)
|
||||
this.perms = record.perms
|
||||
this.$nextTick(() => {
|
||||
this.form.setFieldsValue({
|
||||
|
@ -147,8 +146,6 @@ export default {
|
|||
e.preventDefault()
|
||||
this.form.validateFields((err, values) => {
|
||||
if (!err) {
|
||||
console.log('Received values of form: ', values)
|
||||
|
||||
values.app_id = this.$route.name.split('_')[0]
|
||||
values.perms = this.perms
|
||||
if (values.id) {
|
||||
|
|
|
@ -29,8 +29,11 @@
|
|||
<a-select
|
||||
v-model="selectedParents"
|
||||
placeholder="可选择继承角色"
|
||||
mode="multiple">
|
||||
<a-select-option v-for="role in allRoles" v-if="current_id !== role.id" :key="role.id">{{ role.name }}</a-select-option>
|
||||
mode="multiple"
|
||||
:filterOption="filterOption">
|
||||
<template v-for="role in allRoles">
|
||||
<a-select-option v-if="current_id !== role.id" :key="role.id">{{ role.name }}</a-select-option>
|
||||
</template>
|
||||
</a-select>
|
||||
</a-form-item>
|
||||
<a-form-item
|
||||
|
@ -119,11 +122,13 @@ export default {
|
|||
} : {}
|
||||
}
|
||||
|
||||
},
|
||||
mounted () {
|
||||
},
|
||||
methods: {
|
||||
|
||||
filterOption (input, option) {
|
||||
return (
|
||||
option.componentOptions.children[0].text.toLowerCase().indexOf(input.toLowerCase()) >= 0
|
||||
)
|
||||
},
|
||||
handleCreate () {
|
||||
this.drawerTitle = '新增'
|
||||
this.drawerVisible = true
|
||||
|
@ -162,7 +167,6 @@ export default {
|
|||
e.preventDefault()
|
||||
this.form.validateFields((err, values) => {
|
||||
if (!err) {
|
||||
console.log('Received values of form: ', values)
|
||||
values.app_id = this.$route.name.split('_')[0]
|
||||
if (values.id) {
|
||||
this.updateRole(values.id, values)
|
||||
|
|
|
@ -205,7 +205,6 @@ export default {
|
|||
|
||||
handleEdit (record) {
|
||||
this.drawerVisible = true
|
||||
console.log(record)
|
||||
this.$nextTick(() => {
|
||||
this.form.setFieldsValue({
|
||||
id: record.uid,
|
||||
|
@ -225,8 +224,6 @@ export default {
|
|||
e.preventDefault()
|
||||
this.form.validateFields((err, values) => {
|
||||
if (!err) {
|
||||
console.log('Received values of form: ', values)
|
||||
|
||||
if (values.id) {
|
||||
this.updateUser(values.id, values)
|
||||
} else {
|
||||
|
|
|
@ -155,7 +155,6 @@ export default {
|
|||
delete parameter.pageNo
|
||||
delete parameter.pageSize
|
||||
Object.assign(parameter, this.queryParam)
|
||||
console.log('loadData.parameter', parameter)
|
||||
|
||||
return searchResourceType(parameter)
|
||||
.then(res => {
|
||||
|
@ -165,7 +164,6 @@ export default {
|
|||
res.totalPage = Math.ceil(res.numfound / parameter.pageSize)
|
||||
res.data = res.groups
|
||||
this.id2perms = res.id2perms
|
||||
console.log('loadData.res', res)
|
||||
return res
|
||||
})
|
||||
},
|
||||
|
|
|
@ -155,7 +155,6 @@ export default {
|
|||
delete parameter.pageNo
|
||||
delete parameter.pageSize
|
||||
Object.assign(parameter, this.queryParam)
|
||||
console.log('loadData.parameter', parameter)
|
||||
|
||||
return searchResourceType(parameter)
|
||||
.then(res => {
|
||||
|
@ -165,7 +164,6 @@ export default {
|
|||
res.totalPage = Math.ceil(res.numfound / parameter.pageSize)
|
||||
res.data = res.groups
|
||||
this.id2perms = res.id2perms
|
||||
console.log('loadData.res', res)
|
||||
return res
|
||||
})
|
||||
},
|
||||
|
@ -249,7 +247,6 @@ export default {
|
|||
}
|
||||
}
|
||||
record.perms = perms
|
||||
console.log(record)
|
||||
this.$refs.resourceTypeForm.handleEdit(record)
|
||||
},
|
||||
handleDelete (record) {
|
||||
|
|
|
@ -155,7 +155,6 @@ export default {
|
|||
delete parameter.pageNo
|
||||
delete parameter.pageSize
|
||||
Object.assign(parameter, this.queryParam)
|
||||
console.log('loadData.parameter', parameter)
|
||||
|
||||
return searchRole(parameter)
|
||||
.then(res => {
|
||||
|
@ -165,7 +164,6 @@ export default {
|
|||
res.totalPage = Math.ceil(res.numfound / parameter.pageSize)
|
||||
res.data = res.roles
|
||||
|
||||
console.log('loadData.res', res)
|
||||
this.allRoles = res.roles
|
||||
this.id2parents = res.id2parents
|
||||
return res
|
||||
|
|
|
@ -218,7 +218,6 @@ export default {
|
|||
delete parameter.pageNo
|
||||
delete parameter.pageSize
|
||||
Object.assign(parameter, this.queryParam)
|
||||
console.log('loadData.parameter', parameter)
|
||||
|
||||
return searchUser(parameter)
|
||||
.then(res => {
|
||||
|
@ -228,7 +227,6 @@ export default {
|
|||
res.totalPage = Math.ceil(res.numfound / parameter.pageSize)
|
||||
res.data = res.users
|
||||
|
||||
console.log('loadData.res', res)
|
||||
this.allUsers = res.users
|
||||
return res
|
||||
})
|
||||
|
|
|
@ -62,7 +62,9 @@ export default {
|
|||
relationViews: {},
|
||||
levels: [],
|
||||
showTypeIds: [],
|
||||
origShowTypeIds: [],
|
||||
showTypes: [],
|
||||
origShowTypes: [],
|
||||
leaf2showTypes: {},
|
||||
node2ShowTypes: {},
|
||||
leaf: [],
|
||||
|
@ -84,7 +86,7 @@ export default {
|
|||
console.log(parameter, 'load instances')
|
||||
this.parameter = parameter
|
||||
const params = Object.assign(parameter || {}, this.$refs.search.queryParam)
|
||||
let q = `q=_type:${this.currentTypeId[0]}`
|
||||
let q = ''
|
||||
Object.keys(params).forEach(key => {
|
||||
if (!['pageNo', 'pageSize', 'sortField', 'sortOrder'].includes(key) && params[key] + '' !== '') {
|
||||
if (typeof params[key] === 'object' && params[key].length > 1) {
|
||||
|
@ -109,8 +111,13 @@ export default {
|
|||
}
|
||||
q += `&sort=${order}${params['sortField']}`
|
||||
}
|
||||
if (q && q[0] === ',') {
|
||||
q = q.slice(1)
|
||||
}
|
||||
|
||||
if (this.treeKeys.length === 0) {
|
||||
this.judgeCITypes(q)
|
||||
q = `q=_type:${this.currentTypeId[0]},` + q
|
||||
return searchCI(q).then(res => {
|
||||
const result = {}
|
||||
result.pageNo = res.page
|
||||
|
@ -123,7 +130,7 @@ export default {
|
|||
setTimeout(() => {
|
||||
this.setColumnWidth()
|
||||
console.log('set column')
|
||||
}, 300)
|
||||
}, 100)
|
||||
}
|
||||
this.loadRoot()
|
||||
return result
|
||||
|
@ -133,13 +140,6 @@ export default {
|
|||
q += `&root_id=${this.treeKeys[this.treeKeys.length - 1].split('_')[0]}`
|
||||
const typeId = parseInt(this.treeKeys[this.treeKeys.length - 1].split('_')[1])
|
||||
|
||||
this.showTypes = this.node2ShowTypes[typeId + '']
|
||||
const showTypeIds = []
|
||||
this.showTypes.forEach(item => {
|
||||
showTypeIds.push(item.id)
|
||||
})
|
||||
this.showTypeIds = showTypeIds
|
||||
|
||||
let level = []
|
||||
if (!this.leaf.includes(typeId)) {
|
||||
let startIdx = 0
|
||||
|
@ -160,9 +160,8 @@ export default {
|
|||
level = [1]
|
||||
}
|
||||
q += `&level=${level.join(',')}`
|
||||
if (q[0] === '&') {
|
||||
q = q.slice(1)
|
||||
}
|
||||
this.judgeCITypes(q)
|
||||
q = `q=_type:${this.currentTypeId[0]},` + q
|
||||
return searchCIRelation(q).then(res => {
|
||||
const result = {}
|
||||
result.pageNo = res.page
|
||||
|
@ -176,7 +175,7 @@ export default {
|
|||
setTimeout(() => {
|
||||
this.setColumnWidth()
|
||||
console.log('set column')
|
||||
}, 300)
|
||||
}, 100)
|
||||
this.loadNoRoot(this.treeKeys[this.treeKeys.length - 1], level)
|
||||
}
|
||||
return result
|
||||
|
@ -212,6 +211,55 @@ export default {
|
|||
}, 100)
|
||||
},
|
||||
|
||||
async judgeCITypes (q) {
|
||||
const showTypeIds = []
|
||||
let _showTypes = []
|
||||
let _showTypeIds = []
|
||||
|
||||
if (this.treeKeys.length) {
|
||||
const typeId = parseInt(this.treeKeys[this.treeKeys.length - 1].split('_')[1])
|
||||
|
||||
_showTypes = this.node2ShowTypes[typeId + '']
|
||||
_showTypes.forEach(item => {
|
||||
_showTypeIds.push(item.id)
|
||||
})
|
||||
} else {
|
||||
_showTypeIds = JSON.parse(JSON.stringify(this.origShowTypeIds))
|
||||
_showTypes = JSON.parse(JSON.stringify(this.origShowTypes))
|
||||
}
|
||||
|
||||
const promises = _showTypeIds.map(typeId => {
|
||||
const _q = (`q=_type:${typeId},` + q).replace(/count=\d*/, 'count=1')
|
||||
if (this.treeKeys.length === 0) {
|
||||
return searchCI(_q).then(res => {
|
||||
if (res.numfound !== 0) {
|
||||
showTypeIds.push(typeId)
|
||||
}
|
||||
})
|
||||
} else {
|
||||
return searchCIRelation(_q).then(res => {
|
||||
if (res.numfound !== 0) {
|
||||
showTypeIds.push(typeId)
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
await Promise.all(promises)
|
||||
if (showTypeIds.length && showTypeIds.length !== this.showTypeIds.length) {
|
||||
const showTypes = []
|
||||
_showTypes.forEach(item => {
|
||||
if (showTypeIds.includes(item.id)) {
|
||||
showTypes.push(item)
|
||||
}
|
||||
})
|
||||
this.showTypes = showTypes
|
||||
this.showTypeIds = showTypeIds
|
||||
if (this.currentTypeId.length && !this.showTypeIds.includes(this.currentTypeId[0])) {
|
||||
this.currentTypeId = this.showTypeIds[0]
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
async loadRoot () {
|
||||
searchCI(`q=_type:(${this.levels[0].join(';')})&count=10000`).then(async res => {
|
||||
const facet = []
|
||||
|
@ -335,17 +383,17 @@ export default {
|
|||
}
|
||||
})
|
||||
this.levels = this.relationViews.views[this.viewName].topo
|
||||
this.showTypes = this.relationViews.views[this.viewName].show_types
|
||||
this.origShowTypes = this.relationViews.views[this.viewName].show_types
|
||||
const showTypeIds = []
|
||||
this.showTypes.forEach(item => {
|
||||
this.origShowTypes.forEach(item => {
|
||||
showTypeIds.push(item.id)
|
||||
})
|
||||
this.showTypeIds = showTypeIds
|
||||
this.origShowTypeIds = showTypeIds
|
||||
this.leaf2showTypes = this.relationViews.views[this.viewName].leaf2show_types
|
||||
this.node2ShowTypes = this.relationViews.views[this.viewName].node2show_types
|
||||
this.leaf = this.relationViews.views[this.viewName].leaf
|
||||
this.currentView = [this.viewId]
|
||||
this.currentTypeId = [this.showTypeIds[0]]
|
||||
this.currentTypeId = [this.origShowTypeIds[0]]
|
||||
this.typeId = this.levels[0][0]
|
||||
this.loadColumns()
|
||||
this.$refs.table && this.$refs.table.refresh(true)
|
||||
|
|
Loading…
Reference in New Issue