mirror of
https://github.com/jumpserver/jumpserver.git
synced 2025-06-25 06:21:58 +00:00
ipython
This commit is contained in:
parent
b064be3ec0
commit
e43da3d6e1
@ -8,7 +8,7 @@ from django.conf import settings
|
|||||||
from django.shortcuts import get_object_or_404
|
from django.shortcuts import get_object_or_404
|
||||||
from rest_framework.views import APIView, Response
|
from rest_framework.views import APIView, Response
|
||||||
from rest_framework.generics import (
|
from rest_framework.generics import (
|
||||||
ListAPIView, get_object_or_404,
|
ListAPIView, get_object_or_404, GenericAPIView, RetrieveAPIView
|
||||||
)
|
)
|
||||||
from rest_framework.pagination import LimitOffsetPagination
|
from rest_framework.pagination import LimitOffsetPagination
|
||||||
|
|
||||||
@ -433,13 +433,14 @@ class ValidateUserAssetPermissionApi(UserPermissionCacheMixin, APIView):
|
|||||||
return Response({'msg': True}, status=200)
|
return Response({'msg': True}, status=200)
|
||||||
|
|
||||||
|
|
||||||
class GetUserAssetPermissionActionsApi(UserPermissionCacheMixin, APIView):
|
class GetUserAssetPermissionActionsApi(UserPermissionCacheMixin, RetrieveAPIView):
|
||||||
permission_classes = (IsOrgAdminOrAppUser,)
|
permission_classes = (IsOrgAdminOrAppUser,)
|
||||||
|
serializers_class = serializers.ActionsSerializer
|
||||||
|
|
||||||
def get(self, request, *args, **kwargs):
|
def get_object(self):
|
||||||
user_id = request.query_params.get('user_id', '')
|
user_id = self.request.query_params.get('user_id', '')
|
||||||
asset_id = request.query_params.get('asset_id', '')
|
asset_id = self.request.query_params.get('asset_id', '')
|
||||||
system_id = request.query_params.get('system_user_id', '')
|
system_id = self.request.query_params.get('system_user_id', '')
|
||||||
|
|
||||||
user = get_object_or_404(User, id=user_id)
|
user = get_object_or_404(User, id=user_id)
|
||||||
asset = get_object_or_404(Asset, id=asset_id)
|
asset = get_object_or_404(Asset, id=asset_id)
|
||||||
@ -447,12 +448,8 @@ class GetUserAssetPermissionActionsApi(UserPermissionCacheMixin, APIView):
|
|||||||
|
|
||||||
util = AssetPermissionUtil(user, cache_policy=self.cache_policy)
|
util = AssetPermissionUtil(user, cache_policy=self.cache_policy)
|
||||||
granted_assets = util.get_assets()
|
granted_assets = util.get_assets()
|
||||||
granted_system_users = granted_assets.get(asset, [])
|
granted_system_users = granted_assets.get(asset, {})
|
||||||
_su = next((s for s in granted_system_users if s.id == su.id), None)
|
|
||||||
if not _su:
|
|
||||||
return Response({'actions': []}, status=403)
|
|
||||||
|
|
||||||
actions = [action.name for action in getattr(_su, 'actions', [])]
|
|
||||||
return Response({'actions': actions}, status=200)
|
|
||||||
|
|
||||||
|
|
||||||
|
if su not in granted_system_users:
|
||||||
|
return {"actions": 0}
|
||||||
|
return granted_system_users[su]
|
||||||
|
@ -11,6 +11,7 @@ from .asset_permission import ActionField
|
|||||||
__all__ = [
|
__all__ = [
|
||||||
'AssetPermissionNodeSerializer', 'GrantedNodeSerializer',
|
'AssetPermissionNodeSerializer', 'GrantedNodeSerializer',
|
||||||
'NodeGrantedSerializer', 'AssetGrantedSerializer',
|
'NodeGrantedSerializer', 'AssetGrantedSerializer',
|
||||||
|
'ActionsSerializer',
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
@ -111,3 +112,7 @@ class GrantedNodeSerializer(serializers.ModelSerializer):
|
|||||||
fields = [
|
fields = [
|
||||||
'id', 'name', 'key', 'value',
|
'id', 'name', 'key', 'value',
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
class ActionsSerializer(serializers.Serializer):
|
||||||
|
actions = ActionField(read_only=True)
|
Loading…
Reference in New Issue
Block a user