mirror of
https://github.com/jumpserver/jumpserver.git
synced 2025-09-24 21:08:30 +00:00
perf: remove system user
This commit is contained in:
@@ -2,4 +2,3 @@
|
||||
#
|
||||
|
||||
from .asset import *
|
||||
from .system_user_permission import *
|
||||
|
@@ -8,7 +8,7 @@ from django.utils.decorators import method_decorator
|
||||
from rest_framework.views import APIView, Response
|
||||
from rest_framework import status
|
||||
from rest_framework.generics import (
|
||||
ListAPIView, get_object_or_404, RetrieveAPIView, DestroyAPIView
|
||||
ListAPIView, get_object_or_404, RetrieveAPIView
|
||||
)
|
||||
|
||||
from orgs.utils import tmp_to_root_org
|
||||
@@ -16,7 +16,7 @@ from perms.utils.asset.permission import get_asset_system_user_ids_with_actions_
|
||||
from common.permissions import IsValidUser
|
||||
from common.utils import get_logger, lazyproperty
|
||||
|
||||
from perms.hands import User, Asset, SystemUser
|
||||
from perms.hands import User, Asset
|
||||
from perms import serializers
|
||||
|
||||
logger = get_logger(__name__)
|
||||
@@ -25,7 +25,6 @@ __all__ = [
|
||||
'UserGrantedAssetSystemUsersForAdminApi',
|
||||
'ValidateUserAssetPermissionApi',
|
||||
'GetUserAssetPermissionActionsApi',
|
||||
'UserAssetPermissionsCacheApi',
|
||||
'MyGrantedAssetSystemUsersApi',
|
||||
]
|
||||
|
||||
@@ -45,19 +44,18 @@ class GetUserAssetPermissionActionsApi(RetrieveAPIView):
|
||||
|
||||
def get_object(self):
|
||||
asset_id = self.request.query_params.get('asset_id', '')
|
||||
system_id = self.request.query_params.get('system_user_id', '')
|
||||
account = self.request.query_params.get('account', '')
|
||||
|
||||
try:
|
||||
asset_id = uuid.UUID(asset_id)
|
||||
system_id = uuid.UUID(system_id)
|
||||
except ValueError:
|
||||
return Response({'msg': False}, status=403)
|
||||
|
||||
asset = get_object_or_404(Asset, id=asset_id)
|
||||
system_user = get_object_or_404(SystemUser, id=system_id)
|
||||
|
||||
system_users_actions = get_asset_system_user_ids_with_actions_by_user(self.get_user(), asset)
|
||||
actions = system_users_actions.get(system_user.id)
|
||||
# actions = system_users_actions.get(system_user.id)
|
||||
actions = system_users_actions.get(account)
|
||||
return {"actions": actions}
|
||||
|
||||
|
||||
@@ -70,7 +68,7 @@ class ValidateUserAssetPermissionApi(APIView):
|
||||
def get(self, request, *args, **kwargs):
|
||||
user_id = self.request.query_params.get('user_id', '')
|
||||
asset_id = request.query_params.get('asset_id', '')
|
||||
system_id = request.query_params.get('system_user_id', '')
|
||||
account = request.query_params.get('account', '')
|
||||
action_name = request.query_params.get('action_name', '')
|
||||
|
||||
data = {
|
||||
@@ -79,14 +77,13 @@ class ValidateUserAssetPermissionApi(APIView):
|
||||
'actions': []
|
||||
}
|
||||
|
||||
if not all((user_id, asset_id, system_id, action_name)):
|
||||
if not all((user_id, asset_id, account, action_name)):
|
||||
return Response(data)
|
||||
|
||||
user = User.objects.get(id=user_id)
|
||||
asset = Asset.objects.valid().get(id=asset_id)
|
||||
system_user = SystemUser.objects.get(id=system_id)
|
||||
|
||||
has_perm, actions, expire_at = validate_permission(user, asset, system_user, action_name)
|
||||
has_perm, actions, expire_at = validate_permission(user, asset, account, action_name)
|
||||
status_code = status.HTTP_200_OK if has_perm else status.HTTP_403_FORBIDDEN
|
||||
data = {
|
||||
'has_permission': has_perm,
|
||||
@@ -97,8 +94,6 @@ class ValidateUserAssetPermissionApi(APIView):
|
||||
|
||||
|
||||
class UserGrantedAssetSystemUsersForAdminApi(ListAPIView):
|
||||
serializer_class = serializers.AssetSystemUserSerializer
|
||||
only_fields = serializers.AssetSystemUserSerializer.Meta.only_fields
|
||||
rbac_perms = {
|
||||
'list': 'perms.view_userassets'
|
||||
}
|
||||
@@ -117,13 +112,6 @@ class UserGrantedAssetSystemUsersForAdminApi(ListAPIView):
|
||||
def get_asset_system_user_ids_with_actions(self, asset):
|
||||
return get_asset_system_user_ids_with_actions_by_user(self.user, asset)
|
||||
|
||||
def get_queryset(self):
|
||||
system_user_ids = self.system_users_with_actions.keys()
|
||||
system_users = SystemUser.objects.filter(id__in=system_user_ids) \
|
||||
.only(*self.serializer_class.Meta.only_fields) \
|
||||
.order_by('name')
|
||||
return system_users
|
||||
|
||||
def paginate_queryset(self, queryset):
|
||||
page = super().paginate_queryset(queryset)
|
||||
|
||||
@@ -148,8 +136,3 @@ class MyGrantedAssetSystemUsersApi(UserGrantedAssetSystemUsersForAdminApi):
|
||||
def user(self):
|
||||
return self.request.user
|
||||
|
||||
|
||||
# TODO 删除
|
||||
class UserAssetPermissionsCacheApi(DestroyAPIView):
|
||||
def destroy(self, request, *args, **kwargs):
|
||||
return Response(status=204)
|
||||
|
@@ -1,21 +0,0 @@
|
||||
from rest_framework import generics
|
||||
|
||||
from assets.models import SystemUser
|
||||
from common.permissions import IsValidUser
|
||||
from perms.utils.asset.user_permission import get_user_all_asset_perm_ids
|
||||
from .. import serializers
|
||||
|
||||
|
||||
class SystemUserPermission(generics.ListAPIView):
|
||||
permission_classes = (IsValidUser,)
|
||||
serializer_class = serializers.SystemUserSerializer
|
||||
|
||||
def get_queryset(self):
|
||||
user = self.request.user
|
||||
|
||||
asset_perm_ids = get_user_all_asset_perm_ids(user)
|
||||
queryset = SystemUser.objects.filter(
|
||||
granted_by_permissions__id__in=asset_perm_ids
|
||||
).distinct()
|
||||
|
||||
return queryset
|
Reference in New Issue
Block a user