2019-12-05 07:09:25 +00:00
|
|
|
from django.db.models import Count
|
2018-02-06 10:32:02 +00:00
|
|
|
|
2021-07-08 06:23:18 +00:00
|
|
|
from orgs.mixins.api import OrgBulkModelViewSet
|
2018-02-06 10:32:02 +00:00
|
|
|
from common.utils import get_logger
|
2018-07-23 04:55:13 +00:00
|
|
|
from ..hands import IsOrgAdmin
|
2021-07-08 06:23:18 +00:00
|
|
|
from ..models import SystemUser
|
2018-02-06 10:32:02 +00:00
|
|
|
from .. import serializers
|
|
|
|
|
|
|
|
|
|
|
|
logger = get_logger(__file__)
|
2021-07-08 06:23:18 +00:00
|
|
|
__all__ = ['AdminUserViewSet']
|
2018-02-06 10:32:02 +00:00
|
|
|
|
|
|
|
|
2021-07-08 06:23:18 +00:00
|
|
|
# 兼容一下老的 api
|
2019-08-21 12:27:21 +00:00
|
|
|
class AdminUserViewSet(OrgBulkModelViewSet):
|
2018-02-06 10:32:02 +00:00
|
|
|
"""
|
|
|
|
Admin user api set, for add,delete,update,list,retrieve resource
|
|
|
|
"""
|
2021-07-08 06:23:18 +00:00
|
|
|
model = SystemUser
|
2021-01-07 02:53:10 +00:00
|
|
|
filterset_fields = ("name", "username")
|
|
|
|
search_fields = filterset_fields
|
2018-02-06 10:32:02 +00:00
|
|
|
serializer_class = serializers.AdminUserSerializer
|
2018-07-23 04:55:13 +00:00
|
|
|
permission_classes = (IsOrgAdmin,)
|
2021-10-22 06:27:54 +00:00
|
|
|
ordering_fields = ('name',)
|
|
|
|
ordering = ('name', )
|
2018-02-06 10:32:02 +00:00
|
|
|
|
2019-12-05 07:09:25 +00:00
|
|
|
def get_queryset(self):
|
2021-07-08 06:23:18 +00:00
|
|
|
queryset = super().get_queryset().filter(type=SystemUser.Type.admin)
|
2020-04-23 03:14:02 +00:00
|
|
|
queryset = queryset.annotate(assets_amount=Count('assets'))
|
2019-12-05 07:09:25 +00:00
|
|
|
return queryset
|