From 5568c4c5df3bd6e36414e5c7705c14d88f7092d2 Mon Sep 17 00:00:00 2001 From: Bai Date: Sun, 4 Dec 2022 14:44:30 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E4=BF=AE=E6=94=B9=20CommandFilterACL?= =?UTF-8?q?=20Account=20=E5=8F=AA=E5=8C=B9=E9=85=8D=20username=20=E5=AD=97?= =?UTF-8?q?=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/acls/models/base.py | 15 +++++---------- apps/acls/serializers/command_filter.py | 8 +++++--- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/apps/acls/models/base.py b/apps/acls/models/base.py index 98036ec92..43577d44c 100644 --- a/apps/acls/models/base.py +++ b/apps/acls/models/base.py @@ -56,14 +56,9 @@ class UserAssetAccountACLQuerySet(BaseACLQuerySet): queryset = queryset.filter(id__in=ids) return queryset - def filter_account(self, name=None, username=None): - q = Q() - if name: - q &= Q(accounts__name_group__contains=name) | \ - Q(accounts__name_group__contains='*') - if username: - q &= Q(accounts__username_group__contains=username) | \ - Q(accounts__username_group__contains='*') + def filter_account(self, username): + q = Q(accounts__username_group__contains=username) | \ + Q(accounts__username_group__contains='*') return self.filter(q) @@ -96,7 +91,7 @@ class UserAssetAccountBaseACL(BaseACL, OrgModelMixin): users = models.JSONField(verbose_name=_('User')) # name_group, address_group assets = models.JSONField(verbose_name=_('Asset')) - # name_group, username_group + # username_group accounts = models.JSONField(verbose_name=_('Account')) objects = ACLManager.from_queryset(UserAssetAccountACLQuerySet)() @@ -115,7 +110,7 @@ class UserAssetAccountBaseACL(BaseACL, OrgModelMixin): queryset = queryset.filter_asset(asset.name, asset.address) if account: org_id = account.org_id - queryset = queryset.filter_account(account.name, account.username) + queryset = queryset.filter_account(account.username) if account_username: queryset = queryset.filter_account(username=account_username) if org_id: diff --git a/apps/acls/serializers/command_filter.py b/apps/acls/serializers/command_filter.py index 934d38198..a8e62da41 100644 --- a/apps/acls/serializers/command_filter.py +++ b/apps/acls/serializers/command_filter.py @@ -11,12 +11,14 @@ __all__ = ["CommandFilterACLSerializer", "CommandGroupSerializer"] class CommandGroupSerializer(BulkOrgResourceModelSerializer): class Meta: model = CommandGroup - fields = ['id', 'name', 'type', 'content', 'comment'] + fields = ['id', 'name', 'type', 'content', 'ignore_case', 'comment'] class CommandFilterACLSerializer(BaseSerializer, BulkOrgResourceModelSerializer): - commands = ObjectRelatedField(queryset=CommandGroup.objects, many=True, required=False, label=_('Commands')) + command_groups = ObjectRelatedField( + queryset=CommandGroup.objects, many=True, required=False, label=_('Commands') + ) class Meta(BaseSerializer.Meta): model = CommandFilterACL - fields = BaseSerializer.Meta.fields + ['commands'] + fields = BaseSerializer.Meta.fields + ['command_groups']