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