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

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