Unverified Commit 844f9bf4 authored by BaiJiangJie's avatar BaiJiangJie Committed by GitHub

Merge pull request #2815 from jumpserver/master_bugfix

[Bugfix] 修复普通用户被授权的RemoteApp列表加载为空的bug
parents 41a5a691 c17d95da
...@@ -93,19 +93,12 @@ class UserGroupGrantedNodesWithAssetsAsTreeApi(ListAPIView): ...@@ -93,19 +93,12 @@ class UserGroupGrantedNodesWithAssetsAsTreeApi(ListAPIView):
show_assets = True show_assets = True
system_user_id = None system_user_id = None
def change_org_if_need(self):
if self.request.user.is_superuser or \
self.request.user.is_app or \
self.kwargs.get('pk') is None:
set_to_root_org()
def get(self, request, *args, **kwargs): def get(self, request, *args, **kwargs):
self.show_assets = request.query_params.get('show_assets', '1') == '1' self.show_assets = request.query_params.get('show_assets', '1') == '1'
self.system_user_id = request.query_params.get('system_user') self.system_user_id = request.query_params.get('system_user')
return super().get(request, *args, **kwargs) return super().get(request, *args, **kwargs)
def get_queryset(self): def get_queryset(self):
self.change_org_if_need()
user_group_id = self.kwargs.get('pk', '') user_group_id = self.kwargs.get('pk', '')
queryset = [] queryset = []
group = get_object_or_404(UserGroup, id=user_group_id) group = get_object_or_404(UserGroup, id=user_group_id)
......
...@@ -25,7 +25,9 @@ from ..hands import ( ...@@ -25,7 +25,9 @@ from ..hands import (
NodeSerializer, RemoteAppSerializer, NodeSerializer, RemoteAppSerializer,
) )
from .. import serializers, const from .. import serializers, const
from ..mixins import AssetsFilterMixin, RemoteAppFilterMixin from ..mixins import (
AssetsFilterMixin, RemoteAppFilterMixin, ChangeOrgIfNeedMixin
)
from ..models import Action from ..models import Action
logger = get_logger(__name__) logger = get_logger(__name__)
...@@ -460,7 +462,7 @@ class GetUserAssetPermissionActionsApi(UserPermissionCacheMixin, APIView): ...@@ -460,7 +462,7 @@ class GetUserAssetPermissionActionsApi(UserPermissionCacheMixin, APIView):
# RemoteApp permission # RemoteApp permission
class UserGrantedRemoteAppsApi(RemoteAppFilterMixin, ListAPIView): class UserGrantedRemoteAppsApi(ChangeOrgIfNeedMixin, RemoteAppFilterMixin, ListAPIView):
permission_classes = (IsOrgAdminOrAppUser,) permission_classes = (IsOrgAdminOrAppUser,)
serializer_class = RemoteAppSerializer serializer_class = RemoteAppSerializer
pagination_class = LimitOffsetPagination pagination_class = LimitOffsetPagination
...@@ -485,7 +487,7 @@ class UserGrantedRemoteAppsApi(RemoteAppFilterMixin, ListAPIView): ...@@ -485,7 +487,7 @@ class UserGrantedRemoteAppsApi(RemoteAppFilterMixin, ListAPIView):
return super().get_permissions() return super().get_permissions()
class UserGrantedRemoteAppsAsTreeApi(ListAPIView): class UserGrantedRemoteAppsAsTreeApi(ChangeOrgIfNeedMixin, ListAPIView):
serializer_class = TreeNodeSerializer serializer_class = TreeNodeSerializer
permission_classes = (IsOrgAdminOrAppUser,) permission_classes = (IsOrgAdminOrAppUser,)
...@@ -517,10 +519,11 @@ class UserGrantedRemoteAppsAsTreeApi(ListAPIView): ...@@ -517,10 +519,11 @@ class UserGrantedRemoteAppsAsTreeApi(ListAPIView):
return super().get_permissions() return super().get_permissions()
class ValidateUserRemoteAppPermissionApi(APIView): class ValidateUserRemoteAppPermissionApi(ChangeOrgIfNeedMixin, APIView):
permission_classes = (IsOrgAdminOrAppUser,) permission_classes = (IsOrgAdminOrAppUser,)
def get(self, request, *args, **kwargs): def get(self, request, *args, **kwargs):
self.change_org_if_need(request, kwargs)
user_id = request.query_params.get('user_id', '') user_id = request.query_params.get('user_id', '')
remote_app_id = request.query_params.get('remote_app_id', '') remote_app_id = request.query_params.get('remote_app_id', '')
user = get_object_or_404(User, id=user_id) user = get_object_or_404(User, id=user_id)
......
# ~*~ coding: utf-8 ~*~ # ~*~ coding: utf-8 ~*~
# #
from orgs.utils import set_to_root_org
__all__ = [ __all__ = [
'AssetsFilterMixin', 'RemoteAppFilterMixin', 'AssetsFilterMixin', 'RemoteAppFilterMixin', 'ChangeOrgIfNeedMixin',
] ]
...@@ -100,3 +101,17 @@ class RemoteAppFilterMixin(object): ...@@ -100,3 +101,17 @@ class RemoteAppFilterMixin(object):
queryset, key=lambda x: getattr(x, order_by), reverse=reverse queryset, key=lambda x: getattr(x, order_by), reverse=reverse
) )
return queryset return queryset
class ChangeOrgIfNeedMixin(object):
@staticmethod
def change_org_if_need(request, kwargs):
if request.user.is_authenticated and request.user.is_superuser \
or request.user.is_app \
or kwargs.get('pk') is None:
set_to_root_org()
def get(self, request, *args, **kwargs):
self.change_org_if_need(request, kwargs)
return super().get(request, *args, **kwargs)
...@@ -39,7 +39,7 @@ class MailTestingAPI(APIView): ...@@ -39,7 +39,7 @@ class MailTestingAPI(APIView):
subject = "Test" subject = "Test"
message = "Test smtp setting" message = "Test smtp setting"
email_from = email_from or email_host_user email_from = email_from or email_host_user
send_mail(subject, message, email_from, [email_host_user]) send_mail(subject, message, email_from, [email_from])
except Exception as e: except Exception as e:
return Response({"error": str(e)}, status=401) return Response({"error": str(e)}, status=401)
......
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