[update] 修改remote apps的serializer

pull/4019/head
ibuler 5 years ago
parent 5571651c02
commit cda677a30f

@ -1,9 +1,9 @@
# coding: utf-8
#
from django.db import models
from django.utils.translation import ugettext_lazy as _
from common.utils import lazyproperty
from .base import BasePermission
__all__ = [
@ -22,3 +22,11 @@ class RemoteAppPermission(BasePermission):
def get_all_remote_apps(self):
return set(self.remote_apps.all())
@lazyproperty
def remote_apps_amount(self):
return self.remote_apps.count()
@lazyproperty
def system_users_amount(self):
return self.system_users.count()

@ -50,6 +50,7 @@ class AssetPermissionSerializer(BulkOrgResourceModelSerializer):
'users_amount', 'user_groups_amount', 'assets_amount', 'nodes_amount', 'system_users_amount',
]
fields = small_fields + m2m_fields
read_only_fields = ['created_by', 'date_created']
@classmethod
def setup_eager_loading(cls, queryset):

@ -1,6 +1,7 @@
# coding: utf-8
#
from rest_framework import serializers
from django.db.models import Count
from common.serializers import AdaptedBulkListSerializer
from orgs.mixins.serializers import BulkOrgResourceModelSerializer
@ -25,10 +26,21 @@ class RemoteAppPermissionSerializer(BulkOrgResourceModelSerializer):
]
m2m_fields = [
'users', 'user_groups', 'remote_apps', 'system_users',
'users_amount', 'user_groups_amount', 'remote_apps_amount',
'system_users_amount'
]
fields = small_fields + m2m_fields
read_only_fields = ['created_by', 'date_created']
@classmethod
def setup_eager_loading(cls, queryset):
""" Perform necessary eager loading of data. """
queryset = queryset.annotate(
users_amount=Count('users'), user_groups_amount=Count('user_groups'),
remote_apps_amount=Count('remote_apps'), system_users_amount=Count('system_users')
)
return queryset
class RemoteAppPermissionUpdateUserSerializer(serializers.ModelSerializer):
class Meta:

Loading…
Cancel
Save