perf: 资产授权添加协议

This commit is contained in:
ibuler
2023-10-26 19:19:09 +08:00
parent 996394ba29
commit f93979eb2d
18 changed files with 246 additions and 132 deletions

View File

@@ -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

View File

@@ -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()

View File

@@ -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]: