From b0e6248cd1bc590fdcb09413a521db152120c39e Mon Sep 17 00:00:00 2001 From: pycook Date: Tue, 3 Dec 2019 21:57:44 +0800 Subject: [PATCH] fix delete ci relation --- api/lib/cmdb/ci.py | 2 +- api/lib/cmdb/preference.py | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/api/lib/cmdb/ci.py b/api/lib/cmdb/ci.py index f55ac47..ef51902 100644 --- a/api/lib/cmdb/ci.py +++ b/api/lib/cmdb/ci.py @@ -548,7 +548,7 @@ class CIRelationManager(object): @staticmethod def delete(cr_id): cr = CIRelation.get_by_id(cr_id) or abort(404, "CIRelation <{0}> is not existed".format(cr_id)) - cr.soft_delete() + cr.delete() his_manager = CIRelationHistoryManager() his_manager.add(cr, operate_type=OperateType.DELETE) diff --git a/api/lib/cmdb/preference.py b/api/lib/cmdb/preference.py index f519ae1..f4a1fac 100644 --- a/api/lib/cmdb/preference.py +++ b/api/lib/cmdb/preference.py @@ -1,5 +1,7 @@ # -*- coding:utf-8 -*- + +import copy import json import six @@ -129,11 +131,26 @@ class PreferenceManager(object): leaf = list(set(toposort.toposort_flatten(topo)) - set([j for i in topo.values() for j in i])) leaf2show_types = {i: [t['child_id'] for t in CITypeRelation.get_by(parent_id=i)] for i in leaf} + node2show_types = copy.deepcopy(leaf2show_types) + + def _find_parent(node_id): + parents = topo.get(node_id, {}) + for parent in parents: + node2show_types.setdefault(parent, []).extend(node2show_types.get(node_id, [])) + _find_parent(parent) + if not parents: + return + for l in leaf: + _find_parent(l) + + for node_id in node2show_types: + node2show_types[node_id] = [CITypeCache.get(i).to_dict() for i in set(node2show_types[node_id])] result[view_name] = dict(topo=list(map(list, toposort.toposort(topo))), topo_flatten=list(toposort.toposort_flatten(topo)), leaf=leaf, leaf2show_types=leaf2show_types, + node2show_types=node2show_types, show_types=[CITypeCache.get(j).to_dict() for i in leaf2show_types.values() for j in i])