mirror of https://github.com/jumpserver/jumpserver
pref: 修改授权规则
parent
2d479d1ffa
commit
1ffcf8f39c
|
@ -14,16 +14,15 @@ __all__ = [
|
|||
'MyFavoriteGrantedAssetsApi', 'UserDirectGrantedAssetsAsTreeApi',
|
||||
'MyUngroupAssetsAsTreeApi',
|
||||
'UserAllGrantedAssetsApi', 'MyAllGrantedAssetsApi', 'MyAllAssetsAsTreeApi',
|
||||
'UserGrantedNodeAssetsApi',
|
||||
'MyGrantedNodeAssetsApi',
|
||||
'UserGrantedNodeAssetsApi', 'MyGrantedNodeAssetsApi',
|
||||
]
|
||||
|
||||
logger = get_logger(__name__)
|
||||
|
||||
|
||||
class UserDirectGrantedAssetsApi(
|
||||
AssetRoleAdminMixin,
|
||||
UserDirectGrantedAssetsQuerysetMixin, AssetsSerializerFormatMixin, ListAPIView
|
||||
AssetRoleAdminMixin, UserDirectGrantedAssetsQuerysetMixin,
|
||||
AssetsSerializerFormatMixin, ListAPIView
|
||||
):
|
||||
""" 直接授权给用户的资产 """
|
||||
pass
|
||||
|
@ -35,8 +34,8 @@ class MyDirectGrantedAssetsApi(AssetRoleUserMixin, UserDirectGrantedAssetsApi):
|
|||
|
||||
|
||||
class UserFavoriteGrantedAssetsApi(
|
||||
AssetRoleAdminMixin,
|
||||
UserFavoriteGrantedAssetsMixin, AssetsSerializerFormatMixin, ListAPIView
|
||||
AssetRoleAdminMixin, UserFavoriteGrantedAssetsMixin,
|
||||
AssetsSerializerFormatMixin, ListAPIView
|
||||
):
|
||||
""" 用户收藏的授权资产 """
|
||||
pass
|
||||
|
@ -63,8 +62,8 @@ class MyUngroupAssetsAsTreeApi(AssetRoleUserMixin, UserDirectGrantedAssetsAsTree
|
|||
|
||||
|
||||
class UserAllGrantedAssetsApi(
|
||||
AssetRoleAdminMixin,
|
||||
UserAllGrantedAssetsQuerysetMixin, AssetsSerializerFormatMixin, ListAPIView
|
||||
AssetRoleAdminMixin, UserAllGrantedAssetsQuerysetMixin,
|
||||
AssetsSerializerFormatMixin, ListAPIView
|
||||
):
|
||||
""" 授权给用户的所有资产 """
|
||||
pass
|
||||
|
@ -81,7 +80,8 @@ class MyAllAssetsAsTreeApi(AssetsTreeFormatMixin, MyAllGrantedAssetsApi):
|
|||
|
||||
|
||||
class UserGrantedNodeAssetsApi(
|
||||
AssetRoleAdminMixin, UserGrantedNodeAssetsMixin, AssetsSerializerFormatMixin, ListAPIView
|
||||
AssetRoleAdminMixin, UserGrantedNodeAssetsMixin,
|
||||
AssetsSerializerFormatMixin, ListAPIView
|
||||
):
|
||||
""" 授权给用户的节点资产 """
|
||||
pass
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
from rest_framework.response import Response
|
||||
from rest_framework.request import Request
|
||||
|
||||
from common.utils import get_logger
|
||||
from users.models import User
|
||||
from assets.api.mixin import SerializeToTreeNodeMixin
|
||||
from common.utils import get_logger
|
||||
from perms.pagination import NodeGrantedAssetPagination, AllGrantedAssetPagination
|
||||
from assets.models import Asset, Node
|
||||
from perms.pagination import NodeGrantedAssetPagination, AllGrantedAssetPagination
|
||||
from perms import serializers
|
||||
from perms.utils.user_permission import UserGrantedAssetsQueryUtils
|
||||
|
||||
|
@ -21,8 +21,7 @@ class UserDirectGrantedAssetsQuerysetMixin:
|
|||
def get_queryset(self):
|
||||
if getattr(self, 'swagger_fake_view', False):
|
||||
return Asset.objects.none()
|
||||
user = self.user
|
||||
assets = UserGrantedAssetsQueryUtils(user) \
|
||||
assets = UserGrantedAssetsQueryUtils(self.user) \
|
||||
.get_direct_granted_assets() \
|
||||
.prefetch_related('platform') \
|
||||
.only(*self.only_fields)
|
||||
|
@ -32,7 +31,7 @@ class UserDirectGrantedAssetsQuerysetMixin:
|
|||
class UserAllGrantedAssetsQuerysetMixin:
|
||||
only_fields = serializers.AssetGrantedSerializer.Meta.only_fields
|
||||
pagination_class = AllGrantedAssetPagination
|
||||
ordering_fields = ("name", "address", "port", "cpu_cores")
|
||||
ordering_fields = ("name", "address")
|
||||
ordering = ('name', )
|
||||
|
||||
user: User
|
||||
|
|
|
@ -4,14 +4,14 @@
|
|||
from rest_framework import serializers
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from common.drf.fields import ObjectRelatedField, LabeledChoiceField
|
||||
from assets.models import Node, Asset, Platform, Account
|
||||
from assets.const import Category, AllTypes
|
||||
from perms.serializers.permission import ActionsField
|
||||
|
||||
__all__ = [
|
||||
'NodeGrantedSerializer',
|
||||
'AssetGrantedSerializer',
|
||||
'ActionsSerializer',
|
||||
'AccountsGrantedSerializer'
|
||||
'NodeGrantedSerializer', 'AssetGrantedSerializer',
|
||||
'ActionsSerializer', 'AccountsGrantedSerializer'
|
||||
]
|
||||
|
||||
|
||||
|
@ -20,14 +20,18 @@ class AssetGrantedSerializer(serializers.ModelSerializer):
|
|||
platform = serializers.SlugRelatedField(
|
||||
slug_field='name', queryset=Platform.objects.all(), label=_("Platform")
|
||||
)
|
||||
protocols = ObjectRelatedField(read_only=True, many=True)
|
||||
category = LabeledChoiceField(choices=Category.choices, read_only=True, label=_('Category'))
|
||||
type = LabeledChoiceField(choices=AllTypes.choices(), read_only=True, label=_('Type'))
|
||||
|
||||
class Meta:
|
||||
model = Asset
|
||||
only_fields = [
|
||||
"id", "name", "address", "protocols", 'domain',
|
||||
"platform", "comment", "org_id", "is_active"
|
||||
"id", "name", "address", "protocols",
|
||||
'domain', 'platform',
|
||||
"comment", "org_id", "is_active",
|
||||
]
|
||||
fields = only_fields + ['org_name']
|
||||
fields = only_fields + ['category', 'type'] + ['org_name']
|
||||
read_only_fields = fields
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue