Skip to content

Commit f332bdb

Browse files
authored
feat(api): Fixed an issue where relationship searches were abnormal after changing the alias of CITYPE. (#730)
1 parent 3baa4e3 commit f332bdb

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

cmdb-api/api/lib/cmdb/ci_type.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,8 +215,21 @@ def update(cls, type_id, **kwargs):
215215

216216
CITypeCache.clean(type_id)
217217

218-
if kwargs.get('name') and kwargs['name'] != ci_type2['name'] and current_app.config.get("USE_ACL"):
219-
ACLManager().update_resource(ci_type2['name'], kwargs['name'], ResourceTypeEnum.CI)
218+
new_name = kwargs.get('name')
219+
new_alias = kwargs.get('alias')
220+
new_unique_id = kwargs.get('unique_id')
221+
222+
name_changed = bool(new_name) and new_name != ci_type2['name']
223+
alias_changed = bool(new_alias) and new_alias != ci_type2.get('alias')
224+
unique_changed = bool(new_unique_id) and new_unique_id != ci_type2.get('unique_id')
225+
if name_changed or alias_changed or unique_changed:
226+
from api.tasks.cmdb import batch_ci_cache
227+
ci_ids = [i.id for i in CI.get_by(type_id=type_id, to_dict=False)]
228+
if ci_ids:
229+
batch_ci_cache.apply_async(args=(ci_ids,), queue=CMDB_QUEUE)
230+
231+
if name_changed and current_app.config.get("USE_ACL"):
232+
ACLManager().update_resource(ci_type2['name'], new_name, ResourceTypeEnum.CI)
220233

221234
CITypeHistoryManager.add(CITypeOperateType.UPDATE, ci_type.id,
222235
change=dict(old=ci_type2, new=new.to_dict()))

0 commit comments

Comments
 (0)