diff --git a/apps/acls/models/base.py b/apps/acls/models/base.py index c29fec096..6b7a5af37 100644 --- a/apps/acls/models/base.py +++ b/apps/acls/models/base.py @@ -110,11 +110,11 @@ class UserAssetAccountBaseACL(OrgModelMixin, UserBaseACL): @classmethod def filter_queryset(cls, user=None, asset=None, account=None, account_username=None, **kwargs): queryset = cls.objects.all() - org_id = None if user: q = cls.users.get_filter_q(user) queryset = queryset.filter(q) + if asset: org_id = asset.org_id with tmp_to_org(org_id): @@ -127,8 +127,6 @@ class UserAssetAccountBaseACL(OrgModelMixin, UserBaseACL): models.Q(accounts__contains='*') | \ models.Q(accounts__contains='@ALL') queryset = queryset.filter(q) - if org_id: - kwargs['org_id'] = org_id if kwargs: queryset = queryset.filter(**kwargs) return queryset.valid().distinct() diff --git a/apps/assets/migrations/0098_auto_20220430_2126.py b/apps/assets/migrations/0098_auto_20220430_2126.py index 64a85ecb6..f388ca731 100644 --- a/apps/assets/migrations/0098_auto_20220430_2126.py +++ b/apps/assets/migrations/0098_auto_20220430_2126.py @@ -90,8 +90,10 @@ def create_app_nodes(apps, org_id): next_value = max([int(k[1]) for k in node_key_split]) + 1 parent_key = node_key_split[0][0] else: - root_node = node_model.objects.filter(org_id=org_id)\ - .filter(parent_key='', key__regex=r'^[0-9]+$').exclude(key__startswith='-').first() + root_node = node_model.objects.filter(org_id=org_id) \ + .filter(parent_key='', key__regex=r'^[0-9]+$') \ + .exclude(key__startswith='-') \ + .first() if not root_node: return parent_key = root_node.key diff --git a/apps/common/db/fields.py b/apps/common/db/fields.py index 9ebd149c9..3e1b1ac98 100644 --- a/apps/common/db/fields.py +++ b/apps/common/db/fields.py @@ -295,7 +295,13 @@ class RelatedManager: self.instance.__dict__[self.field.name] = value @classmethod - def get_filter_q(cls, value, to_model): + def _get_filter_q(cls, value, to_model): + """ + 这个是 instance 去查找 to_model 的 queryset 的 Q + :param value: + :param to_model: + :return: + """ if not value or not isinstance(value, dict): return Q() @@ -314,7 +320,7 @@ class RelatedManager: queryset = to_model.get_queryset() else: queryset = to_model.objects.all() - q = cls.get_filter_q(value, to_model) + q = cls._get_filter_q(value, to_model) return queryset.filter(q).distinct() @staticmethod