2020-12-29 16:19:59 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
#
|
|
|
|
from rest_framework import viewsets
|
|
|
|
|
|
|
|
from common.permissions import IsValidUser
|
|
|
|
from common.exceptions import JMSException
|
2021-01-01 23:47:43 +00:00
|
|
|
from users.models import User
|
2021-03-03 03:20:40 +00:00
|
|
|
from orgs.models import Organization
|
2020-12-29 16:19:59 +00:00
|
|
|
from .. import serializers
|
|
|
|
|
|
|
|
|
|
|
|
class AssigneeViewSet(viewsets.ReadOnlyModelViewSet):
|
|
|
|
permission_classes = (IsValidUser,)
|
|
|
|
serializer_class = serializers.AssigneeSerializer
|
2021-01-07 02:53:10 +00:00
|
|
|
filterset_fields = ('id', 'name', 'username', 'email', 'source')
|
|
|
|
search_fields = filterset_fields
|
2020-12-29 16:19:59 +00:00
|
|
|
|
|
|
|
def get_org(self):
|
|
|
|
org_id = self.request.query_params.get('org_id')
|
2021-03-03 03:20:40 +00:00
|
|
|
org = Organization.get_instance(org_id)
|
2020-12-29 16:19:59 +00:00
|
|
|
if not org:
|
2021-01-01 23:47:43 +00:00
|
|
|
error = ('The organization `{}` does not exist'.format(org_id))
|
|
|
|
raise JMSException(error)
|
2020-12-29 16:19:59 +00:00
|
|
|
return org
|
|
|
|
|
|
|
|
def get_queryset(self):
|
|
|
|
org = self.get_org()
|
|
|
|
queryset = User.get_super_and_org_admins(org=org)
|
|
|
|
return queryset
|