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