mirror of
https://github.com/jumpserver/jumpserver.git
synced 2025-09-08 18:59:47 +00:00
perf: 资产授权添加协议
This commit is contained in:
@@ -4,9 +4,10 @@ from rest_framework.generics import ListAPIView, get_object_or_404
|
||||
from common.utils import get_logger, lazyproperty
|
||||
from perms import serializers
|
||||
from perms.hands import Asset
|
||||
from perms.utils import PermAccountUtil
|
||||
from perms.utils import PermAssetDetailUtil
|
||||
from .mixin import SelfOrPKUserMixin
|
||||
from ...models import AssetPermission
|
||||
|
||||
logger = get_logger(__name__)
|
||||
|
||||
__all__ = [
|
||||
@@ -26,5 +27,5 @@ class UserPermedAssetAccountsApi(SelfOrPKUserMixin, ListAPIView):
|
||||
return asset
|
||||
|
||||
def get_queryset(self):
|
||||
accounts = PermAccountUtil().get_permed_accounts_for_user(self.user, self.asset)
|
||||
accounts = PermAssetDetailUtil(self.user, self.asset).get_permed_accounts_for_user()
|
||||
return accounts
|
||||
|
@@ -1,14 +1,15 @@
|
||||
import abc
|
||||
|
||||
from rest_framework.generics import ListAPIView
|
||||
from rest_framework.generics import ListAPIView, RetrieveAPIView
|
||||
|
||||
from assets.api.asset.asset import AssetFilterSet
|
||||
from assets.models import Asset, Node
|
||||
from common.utils import get_logger, lazyproperty, is_uuid
|
||||
from orgs.utils import tmp_to_root_org
|
||||
from perms import serializers
|
||||
from perms.pagination import AllPermedAssetPagination
|
||||
from perms.pagination import NodePermedAssetPagination
|
||||
from perms.utils import UserPermAssetUtil
|
||||
from perms.utils import UserPermAssetUtil, PermAssetDetailUtil
|
||||
from .mixin import (
|
||||
SelfOrPKUserMixin
|
||||
)
|
||||
@@ -18,11 +19,25 @@ __all__ = [
|
||||
'UserDirectPermedAssetsApi',
|
||||
'UserFavoriteAssetsApi',
|
||||
'UserPermedNodeAssetsApi',
|
||||
'UserPermedAssetRetrieveApi',
|
||||
]
|
||||
|
||||
logger = get_logger(__name__)
|
||||
|
||||
|
||||
class UserPermedAssetRetrieveApi(SelfOrPKUserMixin, RetrieveAPIView):
|
||||
serializer_class = serializers.AssetPermedDetailSerializer
|
||||
|
||||
def get_object(self):
|
||||
with tmp_to_root_org():
|
||||
asset_id = self.kwargs.get('pk')
|
||||
util = PermAssetDetailUtil(self.user, asset_id)
|
||||
asset = util.asset
|
||||
asset.permed_accounts = util.get_permed_accounts_for_user()
|
||||
asset.permed_protocols = util.get_permed_protocols_for_user()
|
||||
return asset
|
||||
|
||||
|
||||
class BaseUserPermedAssetsApi(SelfOrPKUserMixin, ListAPIView):
|
||||
ordering = ('name',)
|
||||
search_fields = ('name', 'address', 'comment')
|
||||
@@ -30,12 +45,6 @@ class BaseUserPermedAssetsApi(SelfOrPKUserMixin, ListAPIView):
|
||||
filterset_class = AssetFilterSet
|
||||
serializer_class = serializers.AssetPermedSerializer
|
||||
|
||||
def get_serializer_class(self):
|
||||
serializer_class = super().get_serializer_class()
|
||||
if self.request.query_params.get('id'):
|
||||
serializer_class = serializers.AssetPermedDetailSerializer
|
||||
return serializer_class
|
||||
|
||||
def get_queryset(self):
|
||||
if getattr(self, 'swagger_fake_view', False):
|
||||
return Asset.objects.none()
|
||||
|
@@ -21,7 +21,7 @@ from common.utils import get_object_or_none, lazyproperty
|
||||
from common.utils.common import timeit
|
||||
from perms.hands import Node
|
||||
from perms.models import PermNode
|
||||
from perms.utils import PermAccountUtil, UserPermNodeUtil
|
||||
from perms.utils import PermAssetDetailUtil, UserPermNodeUtil
|
||||
from perms.utils import UserPermAssetUtil
|
||||
from .mixin import RebuildTreeMixin
|
||||
from ..mixin import SelfOrPKUserMixin
|
||||
@@ -225,8 +225,8 @@ class UserGrantedK8sAsTreeApi(SelfOrPKUserMixin, ListAPIView):
|
||||
return token
|
||||
|
||||
def get_account_secret(self, token: ConnectionToken):
|
||||
util = PermAccountUtil()
|
||||
accounts = util.get_permed_accounts_for_user(self.user, token.asset)
|
||||
util = PermAssetDetailUtil(self.user, token.asset)
|
||||
accounts = util.get_permed_accounts_for_user()
|
||||
account_name = token.account
|
||||
|
||||
if account_name in [AliasAccount.INPUT, AliasAccount.USER]:
|
||||
|
Reference in New Issue
Block a user