Browse Source

perf: 查看用户授权

pull/8931/head
feng626 2 years ago
parent
commit
b2991362f1
  1. 2
      apps/acls/serializers/login_asset_acl.py
  2. 1
      apps/assets/serializers/asset/common.py
  3. 7
      apps/perms/api/user_permission/assets/mixin.py

2
apps/acls/serializers/login_asset_acl.py

@ -57,7 +57,7 @@ class LoginAssetACLAccountsSerializer(serializers.Serializer):
class LoginAssetACLSerializer(BulkOrgResourceModelSerializer):
users = LoginAssetACLUsersSerializer()
assets = LoginAssetACLAssestsSerializer()
account = LoginAssetACLAccountsSerializer()
accounts = LoginAssetACLAccountsSerializer()
reviewers_amount = serializers.IntegerField(read_only=True, source='reviewers.count')
action_display = serializers.ReadOnlyField(source='get_action_display', label=_('Action'))

1
apps/assets/serializers/asset/common.py

@ -108,7 +108,6 @@ class AssetSerializer(JMSWritableNestedModelSerializer):
instance.nodes.set(nodes_to_set)
def validate_nodes(self, nodes):
print("Nodes: ", nodes)
if nodes:
return nodes
request = self.context.get('request')

7
apps/perms/api/user_permission/assets/mixin.py

@ -32,8 +32,8 @@ class UserDirectGrantedAssetsQuerysetMixin:
class UserAllGrantedAssetsQuerysetMixin:
only_fields = serializers.AssetGrantedSerializer.Meta.only_fields
pagination_class = AllGrantedAssetPagination
ordering_fields = ("hostname", "address", "port", "cpu_cores")
ordering = ('hostname', )
ordering_fields = ("name", "address", "port", "cpu_cores")
ordering = ('name', )
user: User
@ -41,7 +41,8 @@ class UserAllGrantedAssetsQuerysetMixin:
if getattr(self, 'swagger_fake_view', False):
return Asset.objects.none()
queryset = UserGrantedAssetsQueryUtils(self.user).get_all_granted_assets()
queryset = queryset.prefetch_related('platform').only(*self.only_fields)
only_fields = [i for i in self.only_fields if i not in ['protocols']]
queryset = queryset.prefetch_related('platform', 'protocols').only(*only_fields)
return queryset

Loading…
Cancel
Save