From 785b375f4a3e4e425fed13cf41f02759b6dd7225 Mon Sep 17 00:00:00 2001 From: ibuler Date: Thu, 8 Aug 2019 18:32:44 +0800 Subject: [PATCH] =?UTF-8?q?[Bugfix]=20=E4=BF=AE=E5=A4=8D=E6=8E=88=E6=9D=83?= =?UTF-8?q?=E5=88=97=E8=A1=A8=E7=94=A8=E6=88=B7=E6=97=A0=E6=B3=95=E6=90=9C?= =?UTF-8?q?=E7=B4=A2=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/perms/api/asset_permission.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/apps/perms/api/asset_permission.py b/apps/perms/api/asset_permission.py index d4f6e7c85..0bbb81e4e 100644 --- a/apps/perms/api/asset_permission.py +++ b/apps/perms/api/asset_permission.py @@ -115,6 +115,7 @@ class AssetPermissionViewSet(viewsets.ModelViewSet): def filter_user(self, queryset): user_id = self.request.query_params.get('user_id') username = self.request.query_params.get('username') + query_group = self.request.query_params.get('all') if user_id: user = get_object_or_none(User, pk=user_id) elif username: @@ -123,6 +124,15 @@ class AssetPermissionViewSet(viewsets.ModelViewSet): return queryset if not user: return queryset.none() + else: + kwargs = {} + args = [] + if query_group: + groups = user.groups.all() + args.append(Q(users=user) | Q(user_groups__in=groups)) + else: + kwargs["users"] = user + return queryset.filter(*args, **kwargs).distinct() def filter_user_group(self, queryset): user_group_id = self.request.query_params.get('user_group_id') @@ -148,6 +158,7 @@ class AssetPermissionViewSet(viewsets.ModelViewSet): def filter_queryset(self, queryset): queryset = super().filter_queryset(queryset) queryset = self.filter_valid(queryset) + queryset = self.filter_user(queryset) queryset = self.filter_keyword(queryset) queryset = self.filter_asset(queryset) queryset = self.filter_node(queryset)