diff --git a/apps/assets/models/protocol.py b/apps/assets/models/protocol.py index a2aa2283f..d42ee2754 100644 --- a/apps/assets/models/protocol.py +++ b/apps/assets/models/protocol.py @@ -5,7 +5,3 @@ from django.utils.translation import gettext_lazy as _ class Protocol(models.Model): name = models.CharField(max_length=32, verbose_name=_("Name")) port = models.IntegerField(verbose_name=_("Port")) - - def save(self, force_insert=False, force_update=False, using=None, - update_fields=None): - pass diff --git a/apps/perms/api/asset_permission_relation.py b/apps/perms/api/asset_permission_relation.py index 41a6f083f..a3b65f3f3 100644 --- a/apps/perms/api/asset_permission_relation.py +++ b/apps/perms/api/asset_permission_relation.py @@ -40,8 +40,7 @@ class AssetPermissionUserRelationViewSet(RelationMixin): def get_queryset(self): queryset = super().get_queryset() - queryset = queryset \ - .annotate(user_display=F('user__name')) + queryset = queryset.annotate(user_display=F('user__name')) return queryset @@ -69,8 +68,7 @@ class AssetPermissionUserGroupRelationViewSet(RelationMixin): def get_queryset(self): queryset = super().get_queryset() - queryset = queryset \ - .annotate(usergroup_display=F('usergroup__name')) + queryset = queryset.annotate(usergroup_display=F('usergroup__name')) return queryset @@ -84,8 +82,7 @@ class AssetPermissionAssetRelationViewSet(RelationMixin): def get_queryset(self): queryset = super().get_queryset() - queryset = queryset \ - .annotate(asset_display=F('asset__name')) + queryset = queryset.annotate(asset_display=F('asset__name')) return queryset @@ -111,7 +108,6 @@ class AssetPermissionNodeRelationViewSet(RelationMixin): def get_queryset(self): queryset = super().get_queryset() - queryset = queryset \ - .annotate(node_key=F('node__key')) + queryset = queryset.annotate(node_key=F('node__key')) return queryset diff --git a/apps/perms/api/user_permission/assets/mixin.py b/apps/perms/api/user_permission/assets/mixin.py index 743881eba..096bd21b3 100644 --- a/apps/perms/api/user_permission/assets/mixin.py +++ b/apps/perms/api/user_permission/assets/mixin.py @@ -32,15 +32,15 @@ class UserDirectGrantedAssetsQuerysetMixin: class UserAllGrantedAssetsQuerysetMixin: only_fields = serializers.AssetGrantedSerializer.Meta.only_fields pagination_class = AllGrantedAssetPagination - user: User ordering_fields = ("hostname", "ip", "port", "cpu_cores") ordering = ('hostname', ) - + + user: User + def get_queryset(self): if getattr(self, 'swagger_fake_view', False): return Asset.objects.none() - queryset = UserGrantedAssetsQueryUtils(self.user) \ - .get_all_granted_assets() + queryset = UserGrantedAssetsQueryUtils(self.user).get_all_granted_assets() queryset = queryset.prefetch_related('platform').only(*self.only_fields) return queryset diff --git a/apps/perms/serializers/permission.py b/apps/perms/serializers/permission.py index 5a4bf5105..18fa96563 100644 --- a/apps/perms/serializers/permission.py +++ b/apps/perms/serializers/permission.py @@ -111,7 +111,7 @@ class AssetPermissionSerializer(BulkOrgResourceModelSerializer): # 资产 assets_to_set = Asset.objects.filter( Q(ip__in=kwargs.get('assets_display')) | - Q(hostname__in=kwargs.get('assets_display')) + Q(name__in=kwargs.get('assets_display')) ).distinct() instance.assets.add(*assets_to_set) # 节点 diff --git a/apps/perms/urls/asset_permission.py b/apps/perms/urls/asset_permission.py index a39f61a80..4258a2698 100644 --- a/apps/perms/urls/asset_permission.py +++ b/apps/perms/urls/asset_permission.py @@ -5,6 +5,7 @@ from rest_framework_bulk.routes import BulkRouter from .. import api +# v3 Done router = BulkRouter() router.register('asset-permissions', api.AssetPermissionViewSet, 'asset-permission') router.register('asset-permissions-users-relations', api.AssetPermissionUserRelationViewSet, 'asset-permissions-users-relation') @@ -86,6 +87,8 @@ user_group_permission_urlpatterns = [ ] permission_urlpatterns = [ + # Todo: 获取规则中授权的所有账号列表 + # # 授权规则中授权的资产 path('/assets/all/', api.AssetPermissionAllAssetListApi.as_view(), name='asset-permission-all-assets'), path('/users/all/', api.AssetPermissionAllUserListApi.as_view(), name='asset-permission-all-users'),