From 14f48c459c68f5609cf618128fd01bd754e5fa87 Mon Sep 17 00:00:00 2001 From: "Jiangjie.Bai" Date: Thu, 29 Sep 2022 20:41:40 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=8E=88=E6=9D=83=E8=A7=84=E5=88=99?= =?UTF-8?q?=E5=88=9B=E5=BB=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/perms/serializers/permission.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/apps/perms/serializers/permission.py b/apps/perms/serializers/permission.py index 18fa96563..fd393f990 100644 --- a/apps/perms/serializers/permission.py +++ b/apps/perms/serializers/permission.py @@ -87,6 +87,18 @@ class AssetPermissionSerializer(BulkOrgResourceModelSerializer): 'is_valid': {'label': _('Is valid')}, } + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + self.set_actions_field() + + def set_actions_field(self): + actions = self.fields.get('actions') + if not actions: + return + choices = actions._choices + actions._choices = choices + actions.default = list(choices.keys()) + @classmethod def setup_eager_loading(cls, queryset): """ Perform necessary eager loading of data. """ @@ -110,7 +122,7 @@ class AssetPermissionSerializer(BulkOrgResourceModelSerializer): instance.user_groups.add(*user_groups_to_set) # 资产 assets_to_set = Asset.objects.filter( - Q(ip__in=kwargs.get('assets_display')) | + Q(address__in=kwargs.get('assets_display')) | Q(name__in=kwargs.get('assets_display')) ).distinct() instance.assets.add(*assets_to_set)