Skip to content

Commit

Permalink
fix(search): correct type_id usage in CI relation filtering (#633)
Browse files Browse the repository at this point in the history
  • Loading branch information
thexqn authored Nov 11, 2024
1 parent 5e7c619 commit 57d4bf5
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions cmdb-api/api/lib/cmdb/search/ci_relation/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -391,22 +391,23 @@ def _get_id2name(_type_id):
id2children[str(i)] = item['children']

for lv in range(1, self.level):
type_id = type_ids[lv]

if len(type_ids or []) >= lv and type2filter_perms.get(type_ids[lv]):
id_filter_limit, _ = self._get_ci_filter(type2filter_perms[type_ids[lv]])
if len(type_ids or []) >= lv and type2filter_perms.get(type_id):
id_filter_limit, _ = self._get_ci_filter(type2filter_perms[type_id])
else:
id_filter_limit = {}

if self.has_m2m and lv != 1:
key, prefix = [i for i in level_ids], REDIS_PREFIX_CI_RELATION2
else:
key, prefix = [i.split(',')[-1] for i in level_ids], REDIS_PREFIX_CI_RELATION

res = [json.loads(x).items() for x in [i or '{}' for i in rd.get(key, prefix) or []]]
res = [[i for i in x if (not id_filter_limit or (key[idx] not in id_filter_limit or
res = [[i for i in x if i[1] == type_id and (not id_filter_limit or (key[idx] not in id_filter_limit or
int(i[0]) in id_filter_limit[key[idx]]) or
int(i[0]) in id_filter_limit)] for idx, x in enumerate(res)]
_level_ids = []
type_id = type_ids[lv]
id2name = _get_id2name(type_id)
for idx, node_path in enumerate(level_ids):
for child_id, _ in (res[idx] or []):
Expand Down

0 comments on commit 57d4bf5

Please sign in to comment.