2020-06-16 08:12:59 +00:00
|
|
|
from rest_framework import generics
|
2020-08-16 15:08:58 +00:00
|
|
|
from django.db.models import Q
|
|
|
|
from django.utils.decorators import method_decorator
|
|
|
|
|
|
|
|
from assets.models import SystemUser
|
2020-06-16 08:12:59 +00:00
|
|
|
from common.permissions import IsValidUser
|
|
|
|
from orgs.utils import tmp_to_root_org
|
|
|
|
from .. import serializers
|
|
|
|
|
|
|
|
|
2020-08-16 15:08:58 +00:00
|
|
|
@method_decorator(tmp_to_root_org(), name='list')
|
2020-06-16 08:12:59 +00:00
|
|
|
class SystemUserPermission(generics.ListAPIView):
|
|
|
|
permission_classes = (IsValidUser,)
|
|
|
|
serializer_class = serializers.SystemUserSerializer
|
|
|
|
|
|
|
|
def get_queryset(self):
|
|
|
|
user = self.request.user
|
2020-08-16 15:08:58 +00:00
|
|
|
|
|
|
|
queryset = SystemUser.objects.filter(
|
|
|
|
Q(granted_by_permissions__users=user) |
|
|
|
|
Q(granted_by_permissions__user_groups__users=user)
|
|
|
|
).distinct()
|
|
|
|
|
|
|
|
return queryset
|