mirror of https://github.com/veops/cmdb.git
fix(api): ci relations search
This commit is contained in:
parent
07a097eba2
commit
eb69029a51
|
@ -709,13 +709,18 @@ class CIManager(object):
|
||||||
elif fields:
|
elif fields:
|
||||||
_res = []
|
_res = []
|
||||||
for d in res:
|
for d in res:
|
||||||
|
if isinstance(fields, dict) and d.get("_type") not in fields:
|
||||||
|
_res.append(d)
|
||||||
|
continue
|
||||||
|
|
||||||
_d = dict()
|
_d = dict()
|
||||||
_d["_id"], _d["_type"] = d.get("_id"), d.get("_type")
|
_d["_id"], _d["_type"] = d.get("_id"), d.get("_type")
|
||||||
_d["ci_type"] = d.get("ci_type")
|
_d["ci_type"] = d.get("ci_type")
|
||||||
if unique_required:
|
if unique_required:
|
||||||
_d[d.get('unique')] = d.get(d.get('unique'))
|
_d[d.get('unique')] = d.get(d.get('unique'))
|
||||||
|
|
||||||
for field in fields + ['ci_type_alias', 'unique', 'unique_alias']:
|
_fields = list(fields.get(_d['_type']) or []) if isinstance(fields, dict) else fields
|
||||||
|
for field in _fields + ['ci_type_alias', 'unique', 'unique_alias']:
|
||||||
_d[field] = d.get(field)
|
_d[field] = d.get(field)
|
||||||
_res.append(_d)
|
_res.append(_d)
|
||||||
return _res
|
return _res
|
||||||
|
@ -732,9 +737,8 @@ class CIManager(object):
|
||||||
from api.lib.cmdb.search.ci.db.query_sql import QUERY_CIS_BY_IDS
|
from api.lib.cmdb.search.ci.db.query_sql import QUERY_CIS_BY_IDS
|
||||||
from api.lib.cmdb.search.ci.db.query_sql import QUERY_CIS_BY_VALUE_TABLE
|
from api.lib.cmdb.search.ci.db.query_sql import QUERY_CIS_BY_VALUE_TABLE
|
||||||
|
|
||||||
if not fields:
|
filter_fields_sql = ""
|
||||||
filter_fields_sql = ""
|
if fields and isinstance(fields, list):
|
||||||
else:
|
|
||||||
_fields = list()
|
_fields = list()
|
||||||
for field in fields:
|
for field in fields:
|
||||||
attr = AttributeCache.get(field)
|
attr = AttributeCache.get(field)
|
||||||
|
@ -776,6 +780,10 @@ class CIManager(object):
|
||||||
ci_set.add(ci_id)
|
ci_set.add(ci_id)
|
||||||
res[ci2pos[ci_id]] = ci_dict
|
res[ci2pos[ci_id]] = ci_dict
|
||||||
|
|
||||||
|
if isinstance(fields, dict) and fields.get(type_id):
|
||||||
|
if attr_name not in fields[type_id]:
|
||||||
|
continue
|
||||||
|
|
||||||
if ret_key == RetKey.NAME:
|
if ret_key == RetKey.NAME:
|
||||||
attr_key = attr_name
|
attr_key = attr_name
|
||||||
elif ret_key == RetKey.ALIAS:
|
elif ret_key == RetKey.ALIAS:
|
||||||
|
@ -813,7 +821,7 @@ class CIManager(object):
|
||||||
if not ci_ids:
|
if not ci_ids:
|
||||||
return []
|
return []
|
||||||
|
|
||||||
fields = [] if fields is None or not isinstance(fields, list) else fields
|
fields = [] if not fields else fields
|
||||||
|
|
||||||
ci_id_tuple = tuple(map(int, ci_ids))
|
ci_id_tuple = tuple(map(int, ci_ids))
|
||||||
res = cls._get_cis_from_cache(ci_id_tuple, ret_key, fields, unique_required, excludes=excludes)
|
res = cls._get_cis_from_cache(ci_id_tuple, ret_key, fields, unique_required, excludes=excludes)
|
||||||
|
|
|
@ -106,10 +106,11 @@ class Search(object):
|
||||||
|
|
||||||
def _type_query_handler(self, v, queries):
|
def _type_query_handler(self, v, queries):
|
||||||
new_v = v[1:-1].split(";") if v.startswith("(") and v.endswith(")") else [v]
|
new_v = v[1:-1].split(";") if v.startswith("(") and v.endswith(")") else [v]
|
||||||
|
type_num = len(new_v)
|
||||||
for _v in new_v:
|
for _v in new_v:
|
||||||
ci_type = CITypeCache.get(_v)
|
ci_type = CITypeCache.get(_v)
|
||||||
|
|
||||||
if len(new_v) == 1 and not self.sort and ci_type and ci_type.default_order_attr:
|
if type_num == 1 and not self.sort and ci_type and ci_type.default_order_attr:
|
||||||
self.sort = ci_type.default_order_attr
|
self.sort = ci_type.default_order_attr
|
||||||
|
|
||||||
if ci_type is not None:
|
if ci_type is not None:
|
||||||
|
@ -129,10 +130,15 @@ class Search(object):
|
||||||
queries.append(dict(operator="&", queries=sub))
|
queries.append(dict(operator="&", queries=sub))
|
||||||
|
|
||||||
if self.type2filter_perms[ci_type.id].get('attr_filter'):
|
if self.type2filter_perms[ci_type.id].get('attr_filter'):
|
||||||
if not self.fl:
|
if type_num == 1:
|
||||||
self.fl = set(self.type2filter_perms[ci_type.id]['attr_filter'])
|
if not self.fl:
|
||||||
|
self.fl = set(self.type2filter_perms[ci_type.id]['attr_filter'])
|
||||||
|
else:
|
||||||
|
self.fl = set(self.fl) & set(self.type2filter_perms[ci_type.id]['attr_filter'])
|
||||||
else:
|
else:
|
||||||
self.fl = set(self.fl) & set(self.type2filter_perms[ci_type.id]['attr_filter'])
|
self.fl = self.fl or {}
|
||||||
|
if not self.fl or isinstance(self.fl, dict):
|
||||||
|
self.fl[ci_type.id] = set(self.type2filter_perms[ci_type.id]['attr_filter'])
|
||||||
|
|
||||||
if self.type2filter_perms[ci_type.id].get('id_filter') and self.use_id_filter:
|
if self.type2filter_perms[ci_type.id].get('id_filter') and self.use_id_filter:
|
||||||
|
|
||||||
|
@ -585,13 +591,15 @@ class Search(object):
|
||||||
return facet_result
|
return facet_result
|
||||||
|
|
||||||
def _fl_build(self):
|
def _fl_build(self):
|
||||||
_fl = list()
|
if isinstance(self.fl, list):
|
||||||
for f in self.fl:
|
_fl = list()
|
||||||
k, _, _, _ = self._attr_name_proc(f)
|
for f in self.fl:
|
||||||
if k:
|
k, _, _, _ = self._attr_name_proc(f)
|
||||||
_fl.append(k)
|
if k:
|
||||||
|
_fl.append(k)
|
||||||
return _fl
|
return _fl
|
||||||
|
else:
|
||||||
|
return self.fl
|
||||||
|
|
||||||
def search(self):
|
def search(self):
|
||||||
numfound, ci_ids = self._query_build_raw()
|
numfound, ci_ids = self._query_build_raw()
|
||||||
|
|
Loading…
Reference in New Issue