From 783c163324d8d413b47ec11eedd6d41653cbfe5a Mon Sep 17 00:00:00 2001 From: "Jiangjie.Bai" Date: Fri, 18 Feb 2022 20:19:21 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E8=8E=B7=E5=8F=96?= =?UTF-8?q?=E5=91=BD=E4=BB=A4=E8=BF=87=E6=BB=A4=E8=A7=84=E5=88=99=E6=97=B6?= =?UTF-8?q?=E6=8C=89=E7=85=A7=E6=9C=89=E7=BB=84=E7=BB=87=E7=9A=84=E8=B5=84?= =?UTF-8?q?=E6=BA=90=E8=BF=9B=E8=A1=8C=E7=BB=84=E7=BB=87=E8=BF=87=E6=BB=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/assets/models/cmd_filter.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/apps/assets/models/cmd_filter.py b/apps/assets/models/cmd_filter.py index d7eac13eb..82fd50e89 100644 --- a/apps/assets/models/cmd_filter.py +++ b/apps/assets/models/cmd_filter.py @@ -186,13 +186,15 @@ class CommandFilterRule(OrgModelMixin): return ticket @classmethod - def get_queryset(cls, user_id=None, user_group_id=None, system_user_id=None, asset_id=None, application_id=None): + def get_queryset(cls, user_id=None, user_group_id=None, system_user_id=None, + asset_id=None, application_id=None, org_id=None): user_groups = [] user = get_object_or_none(User, pk=user_id) if user: user_groups.extend(list(user.groups.all())) user_group = get_object_or_none(UserGroup, pk=user_group_id) if user_group: + org_id = user_group.org_id user_groups.append(user_group) system_user = get_object_or_none(SystemUser, pk=system_user_id) asset = get_object_or_none(Asset, pk=asset_id) @@ -203,13 +205,18 @@ class CommandFilterRule(OrgModelMixin): if user_groups: q |= Q(user_groups__in=set(user_groups)) if system_user: + org_id = system_user.org_id q |= Q(system_users=system_user) if asset: + org_id = asset.org_id q |= Q(assets=asset) if application: + org_id = application.org_id q |= Q(applications=application) if q: cmd_filters = CommandFilter.objects.filter(q).filter(is_active=True) + if org_id: + cmd_filters = cmd_filters.filter(org_id=org_id) rule_ids = cmd_filters.values_list('rules', flat=True) rules = cls.objects.filter(id__in=rule_ids) else: