From e805e9cede95974587a2daf3352ed8ae29123756 Mon Sep 17 00:00:00 2001 From: BaiJiangJie Date: Tue, 24 Sep 2019 16:36:46 +0800 Subject: [PATCH] =?UTF-8?q?[Update]=20=E4=BC=98=E5=8C=96=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E6=8E=88=E6=9D=83=E7=9A=84=20RemoteApp=20API=20=E8=BF=87?= =?UTF-8?q?=E6=BB=A4=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/perms/api/user_remote_app_permission.py | 11 +++--- apps/perms/mixins.py | 37 +------------------- 2 files changed, 6 insertions(+), 42 deletions(-) diff --git a/apps/perms/api/user_remote_app_permission.py b/apps/perms/api/user_remote_app_permission.py index 84518c875..030e760b5 100644 --- a/apps/perms/api/user_remote_app_permission.py +++ b/apps/perms/api/user_remote_app_permission.py @@ -14,7 +14,6 @@ from ..utils import ( parse_remote_app_to_tree_node, ) from ..hands import User, RemoteApp, RemoteAppSerializer, UserGroup, SystemUser -from ..mixins import RemoteAppFilterMixin from .mixin import UserPermissionMixin from .. import serializers @@ -26,10 +25,11 @@ __all__ = [ ] -class UserGrantedRemoteAppsApi(RemoteAppFilterMixin, ListAPIView): +class UserGrantedRemoteAppsApi(ListAPIView): permission_classes = (IsOrgAdminOrAppUser,) serializer_class = RemoteAppSerializer - filter_fields = ['id'] + filter_fields = ['name', 'id'] + search_fields = ['name'] def get_object(self): user_id = self.kwargs.get('pk', '') @@ -54,15 +54,14 @@ class UserGrantedRemoteAppsAsTreeApi(UserGrantedRemoteAppsApi): serializer_class = TreeNodeSerializer permission_classes = (IsOrgAdminOrAppUser,) - def get_serializer(self, *args, **kwargs): + def get_serializer(self, remote_apps=None, *args, **kwargs): only_remote_app = self.request.query_params.get('only', '0') == '1' tree_root = None data = [] if not only_remote_app: tree_root = construct_remote_apps_tree_root() data.append(tree_root) - queryset = super().get_queryset() - for remote_app in queryset: + for remote_app in remote_apps: node = parse_remote_app_to_tree_node(tree_root, remote_app) data.append(node) data.sort() diff --git a/apps/perms/mixins.py b/apps/perms/mixins.py index f1d7fac1e..30a588ffd 100644 --- a/apps/perms/mixins.py +++ b/apps/perms/mixins.py @@ -4,7 +4,7 @@ from orgs.utils import set_to_root_org __all__ = [ - 'AssetsFilterMixin', 'RemoteAppFilterMixin', 'ChangeOrgIfNeedMixin', + 'AssetsFilterMixin', 'ChangeOrgIfNeedMixin', ] @@ -68,41 +68,6 @@ class AssetsFilterMixin(object): return _queryset -class RemoteAppFilterMixin(object): - """ - 对RemoteApp进行过滤(查询,排序) - """ - - def filter_queryset(self, queryset): - queryset = self.search_remote_apps(queryset) - queryset = self.sort_remote_apps(queryset) - return queryset - - def search_remote_apps(self, queryset): - value = self.request.query_params.get('search') - if not value: - return queryset - queryset = [ - remote_app for remote_app in queryset if value in remote_app.name - ] - return queryset - - def sort_remote_apps(self, queryset): - order_by = self.request.query_params.get('order') - if not order_by: - order_by = 'name' - if order_by.startswith('-'): - order_by = order_by.lstrip('-') - reverse = True - else: - reverse = False - - queryset = sorted( - queryset, key=lambda x: getattr(x, order_by), reverse=reverse - ) - return queryset - - class ChangeOrgIfNeedMixin(object): @staticmethod