2020-10-22 09:05:47 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
#
|
|
|
|
from rest_framework.generics import ListAPIView
|
|
|
|
from rest_framework.response import Response
|
|
|
|
|
2021-01-03 21:27:03 +00:00
|
|
|
from common.mixins.api import CommonApiMixin
|
2020-11-05 03:23:32 +00:00
|
|
|
from applications.api.mixin import (
|
2021-01-05 15:39:38 +00:00
|
|
|
SerializeApplicationToTreeNodeMixin
|
2020-11-05 03:23:32 +00:00
|
|
|
)
|
2020-10-22 09:05:47 +00:00
|
|
|
from perms import serializers
|
2021-02-05 05:29:29 +00:00
|
|
|
from perms.api.asset.user_permission.mixin import RoleAdminMixin, RoleUserMixin
|
2020-10-22 10:13:14 +00:00
|
|
|
from perms.utils.application.user_permission import (
|
2020-10-22 09:05:47 +00:00
|
|
|
get_user_granted_all_applications
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
__all__ = [
|
|
|
|
'UserAllGrantedApplicationsApi',
|
|
|
|
'MyAllGrantedApplicationsApi',
|
|
|
|
'UserAllGrantedApplicationsAsTreeApi',
|
|
|
|
'MyAllGrantedApplicationsAsTreeApi',
|
|
|
|
]
|
|
|
|
|
|
|
|
|
2021-01-05 15:39:38 +00:00
|
|
|
class AllGrantedApplicationsMixin(CommonApiMixin, ListAPIView):
|
2020-10-22 09:05:47 +00:00
|
|
|
only_fields = serializers.ApplicationGrantedSerializer.Meta.only_fields
|
|
|
|
serializer_class = serializers.ApplicationGrantedSerializer
|
2021-01-07 02:53:10 +00:00
|
|
|
filterset_fields = ['id', 'name', 'category', 'type', 'comment']
|
2020-10-22 09:05:47 +00:00
|
|
|
search_fields = ['name', 'comment']
|
|
|
|
user: None
|
|
|
|
|
|
|
|
def get_queryset(self):
|
|
|
|
queryset = get_user_granted_all_applications(self.user)
|
|
|
|
return queryset.only(*self.only_fields)
|
|
|
|
|
|
|
|
|
2021-02-05 05:29:29 +00:00
|
|
|
class UserAllGrantedApplicationsApi(RoleAdminMixin, AllGrantedApplicationsMixin):
|
2020-10-30 03:50:37 +00:00
|
|
|
pass
|
2020-10-22 09:05:47 +00:00
|
|
|
|
|
|
|
|
2021-02-05 05:29:29 +00:00
|
|
|
class MyAllGrantedApplicationsApi(RoleUserMixin, AllGrantedApplicationsMixin):
|
2020-10-22 09:05:47 +00:00
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
class ApplicationsAsTreeMixin(SerializeApplicationToTreeNodeMixin):
|
|
|
|
"""
|
|
|
|
将应用序列化成树的结构返回
|
|
|
|
"""
|
|
|
|
|
|
|
|
def list(self, request, *args, **kwargs):
|
|
|
|
queryset = self.filter_queryset(self.get_queryset())
|
2020-12-08 07:33:24 +00:00
|
|
|
data = self.serialize_applications_with_org(queryset)
|
2020-10-22 09:05:47 +00:00
|
|
|
return Response(data=data)
|
|
|
|
|
|
|
|
|
|
|
|
class UserAllGrantedApplicationsAsTreeApi(ApplicationsAsTreeMixin, UserAllGrantedApplicationsApi):
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
class MyAllGrantedApplicationsAsTreeApi(ApplicationsAsTreeMixin, MyAllGrantedApplicationsApi):
|
|
|
|
pass
|