Browse Source

perf: 修改 CommandFilterACL Account 只匹配 username 字段

pull/9154/head
Bai 2 years ago
parent
commit
5568c4c5df
  1. 15
      apps/acls/models/base.py
  2. 8
      apps/acls/serializers/command_filter.py

15
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:

8
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']

Loading…
Cancel
Save