Unverified Commit 02087e00 authored by BaiJiangJie's avatar BaiJiangJie Committed by GitHub

Merge pull request #3267 from jumpserver/dev_ra

[Update] 优化用户授权 RemoteApp API 逻辑
parents ffb4a262 e805e9ce
......@@ -49,7 +49,7 @@ function initTable() {
$(td).html(hostname);
}},
{targets: 5, createdCell: function (td, cellData, rowData) {
var conn_btn = '<a href="{% url "luna-view" %}?login_to=' + cellData +'" class="btn btn-xs btn-primary">{% trans "Connect" %}</a>'.replace("{{ DEFAULT_PK }}", cellData);
var conn_btn = '<a href="{% url "luna-view" %}?type=remote_app&login_to=' + cellData +'" class="btn btn-xs btn-primary">{% trans "Connect" %}</a>'.replace("{{ DEFAULT_PK }}", cellData);
$(td).html(conn_btn)
}}
],
......
......@@ -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()
......
......@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment