mirror of https://github.com/veops/cmdb.git
fix: custom dashboard
This commit is contained in:
parent
39e38b10cd
commit
4ebaf9c102
|
@ -309,7 +309,7 @@ class CMDBCounterCache(object):
|
|||
|
||||
s = RelSearch([i[0] for i in type_id_names], level, other_filer or '')
|
||||
try:
|
||||
stats = s.statistics(type_ids)
|
||||
stats = s.statistics(type_ids, need_filter=False)
|
||||
except SearchError as e:
|
||||
current_app.logger.error(e)
|
||||
return
|
||||
|
|
|
@ -67,6 +67,7 @@ class Search(object):
|
|||
|
||||
self.valid_type_names = []
|
||||
self.type2filter_perms = dict()
|
||||
self.is_app_admin = is_app_admin('cmdb') or current_user.username == "worker"
|
||||
|
||||
@staticmethod
|
||||
def _operator_proc(key):
|
||||
|
@ -135,7 +136,7 @@ class Search(object):
|
|||
if not self.raw_ci_ids:
|
||||
self.ci_ids = list(self.type2filter_perms[ci_type.id]['id_filter'].keys())
|
||||
|
||||
if self.use_id_filter and not self.ci_ids and not is_app_admin('cmdb'):
|
||||
if self.use_id_filter and not self.ci_ids and not self.is_app_admin:
|
||||
self.raw_ci_ids = [0]
|
||||
else:
|
||||
raise SearchError(ErrFormat.no_permission.format(ci_type.alias, PermEnum.READ))
|
||||
|
@ -407,11 +408,10 @@ class Search(object):
|
|||
else:
|
||||
result.append(q)
|
||||
|
||||
_is_app_admin = is_app_admin('cmdb') or current_user.username == "worker"
|
||||
if self.parent_node_perm_passed:
|
||||
self.__get_type2filter_perms()
|
||||
self.valid_type_names = "ALL"
|
||||
elif result and not has_type and not _is_app_admin:
|
||||
elif result and not has_type and not self.is_app_admin:
|
||||
type_q = self.__get_types_has_read()
|
||||
if id_query:
|
||||
ci = CIManager.get_by_id(id_query)
|
||||
|
@ -420,7 +420,7 @@ class Search(object):
|
|||
result.insert(0, "_type:{}".format(ci.type_id))
|
||||
else:
|
||||
result.insert(0, type_q)
|
||||
elif _is_app_admin:
|
||||
elif self.is_app_admin:
|
||||
self.valid_type_names = "ALL"
|
||||
else:
|
||||
self.__get_types_has_read()
|
||||
|
|
|
@ -66,6 +66,8 @@ class Search(object):
|
|||
self.has_m2m = True
|
||||
|
||||
self.type2filter_perms = None
|
||||
|
||||
self.is_app_admin = is_app_admin('cmdb') or current_user.username == "worker"
|
||||
|
||||
def _get_ids(self, ids):
|
||||
|
||||
|
@ -133,7 +135,7 @@ class Search(object):
|
|||
self.root_parent_path.append(str(self.root_id))
|
||||
self.root_parent_path = set(self.root_parent_path)
|
||||
|
||||
if is_app_admin('cmdb'):
|
||||
if self.is_app_admin:
|
||||
self.type2filter_perms = {}
|
||||
return True
|
||||
|
||||
|
@ -222,14 +224,13 @@ class Search(object):
|
|||
|
||||
return {}, None
|
||||
|
||||
def statistics(self, type_ids):
|
||||
def statistics(self, type_ids, need_filter=True):
|
||||
self.level = int(self.level)
|
||||
|
||||
acl = ACLManager('cmdb')
|
||||
_is_app_admin = is_app_admin('cmdb') or current_user.username == "worker"
|
||||
|
||||
type2filter_perms = dict()
|
||||
if not _is_app_admin:
|
||||
if not self.is_app_admin:
|
||||
res2 = acl.get_resources(ResourceTypeEnum.CI_FILTER)
|
||||
if res2:
|
||||
type2filter_perms = CIFilterPermsCRUD().get_by_ids(list(map(int, [i['name'] for i in res2])))
|
||||
|
@ -240,17 +241,20 @@ class Search(object):
|
|||
for lv in range(1, self.level + 1):
|
||||
level2ids[lv] = []
|
||||
|
||||
id_filter_limit, ci_filter_limit = None, None
|
||||
if len(self.descendant_ids) >= lv and type2filter_perms.get(self.descendant_ids[lv - 1]):
|
||||
id_filter_limit, _ = self._get_ci_filter(type2filter_perms[self.descendant_ids[lv - 1]])
|
||||
elif type_ids and self.level == lv:
|
||||
ci_filters = [type2filter_perms[type_id] for type_id in type_ids if type_id in type2filter_perms]
|
||||
if ci_filters:
|
||||
id_filter_limit, ci_filter_limit = self._get_ci_filter({}, ci_filters=ci_filters)
|
||||
if need_filter:
|
||||
id_filter_limit, ci_filter_limit = None, None
|
||||
if len(self.descendant_ids or []) >= lv and type2filter_perms.get(self.descendant_ids[lv - 1]):
|
||||
id_filter_limit, _ = self._get_ci_filter(type2filter_perms[self.descendant_ids[lv - 1]])
|
||||
elif type_ids and self.level == lv:
|
||||
ci_filters = [type2filter_perms[type_id] for type_id in type_ids if type_id in type2filter_perms]
|
||||
if ci_filters:
|
||||
id_filter_limit, ci_filter_limit = self._get_ci_filter({}, ci_filters=ci_filters)
|
||||
else:
|
||||
id_filter_limit = {}
|
||||
else:
|
||||
id_filter_limit = {}
|
||||
else:
|
||||
id_filter_limit = {}
|
||||
id_filter_limit, ci_filter_limit = {}, {}
|
||||
|
||||
if lv == 1:
|
||||
if not self.has_m2m:
|
||||
|
|
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue