1616from cases .tasks import send_email_to_assigned_user
1717from common .models import Attachments , Comment , Profile
1818
19- # from common.custom_auth import JSONWebTokenAuthentication
19+ from common .external_auth import CustomDualAuthentication
2020from common .serializer import AttachmentsSerializer , CommentSerializer
2121from common .utils import CASE_TYPE , PRIORITY_CHOICE , STATUS_CHOICE
2222from contacts .models import Contact
2525
2626
2727class CaseListView (APIView , LimitOffsetPagination ):
28- # authentication_classes = (JSONWebTokenAuthentication ,)
28+ authentication_classes = (CustomDualAuthentication ,)
2929 permission_classes = (IsAuthenticated ,)
3030 model = Case
3131
@@ -37,13 +37,13 @@ def get_context_data(self, **kwargs):
3737 profiles = Profile .objects .filter (is_active = True , org = self .request .profile .org )
3838 if self .request .profile .role != "ADMIN" and not self .request .profile .is_admin :
3939 queryset = queryset .filter (
40- Q (created_by = self .request .profile ) | Q (assigned_to = self .request .profile )
40+ Q (created_by = self .request .profile . user ) | Q (assigned_to = self .request .profile )
4141 ).distinct ()
4242 accounts = accounts .filter (
43- Q (created_by = self .request .profile ) | Q (assigned_to = self .request .profile )
43+ Q (created_by = self .request .profile . user ) | Q (assigned_to = self .request .profile )
4444 ).distinct ()
4545 contacts = contacts .filter (
46- Q (created_by = self .request .profile ) | Q (assigned_to = self .request .profile )
46+ Q (created_by = self .request .profile . user ) | Q (assigned_to = self .request .profile )
4747 ).distinct ()
4848 profiles = profiles .filter (role = "ADMIN" )
4949
@@ -97,26 +97,26 @@ def post(self, request, *args, **kwargs):
9797 serializer = CaseCreateSerializer (data = params , request_obj = request )
9898 if serializer .is_valid ():
9999 cases_obj = serializer .save (
100- created_by = request .profile ,
100+ created_by = request .profile . user ,
101101 org = request .profile .org ,
102102 closed_on = params .get ("closed_on" ),
103103 case_type = params .get ("case_type" ),
104104 )
105105
106106 if params .get ("contacts" ):
107- contacts_list = json . loads ( params .get ("contacts" ) )
107+ contacts_list = params .get ("contacts" )
108108 contacts = Contact .objects .filter (id__in = contacts_list , org = request .profile .org )
109109 if contacts :
110110 cases_obj .contacts .add (* contacts )
111111
112112 if params .get ("teams" ):
113- teams_list = json . loads ( params .get ("teams" ) )
113+ teams_list = params .get ("teams" )
114114 teams = Teams .objects .filter (id__in = teams_list , org = request .profile .org )
115115 if teams .exists ():
116116 cases_obj .teams .add (* teams )
117117
118118 if params .get ("assigned_to" ):
119- assinged_to_list = json . loads ( params .get ("assigned_to" ) )
119+ assinged_to_list = params .get ("assigned_to" )
120120 profiles = Profile .objects .filter (
121121 id__in = assinged_to_list , org = request .profile .org , is_active = True
122122 )
@@ -125,7 +125,7 @@ def post(self, request, *args, **kwargs):
125125
126126 if self .request .FILES .get ("case_attachment" ):
127127 attachment = Attachments ()
128- attachment .created_by = self .request .profile
128+ attachment .created_by = self .request .profile . user
129129 attachment .file_name = self .request .FILES .get ("case_attachment" ).name
130130 attachment .cases = cases_obj
131131 attachment .attachment = self .request .FILES .get ("case_attachment" )
@@ -148,7 +148,7 @@ def post(self, request, *args, **kwargs):
148148
149149
150150class CaseDetailView (APIView ):
151- # authentication_classes = (JSONWebTokenAuthentication ,)
151+ authentication_classes = (CustomDualAuthentication ,)
152152 permission_classes = (IsAuthenticated ,)
153153 model = Case
154154
@@ -194,21 +194,21 @@ def put(self, request, pk, format=None):
194194 )
195195 cases_object .contacts .clear ()
196196 if params .get ("contacts" ):
197- contacts_list = json . loads ( params .get ("contacts" ) )
197+ contacts_list = params .get ("contacts" )
198198 contacts = Contact .objects .filter (id__in = contacts_list , org = request .profile .org )
199199 if contacts :
200200 cases_object .contacts .add (* contacts )
201201
202202 cases_object .teams .clear ()
203203 if params .get ("teams" ):
204- teams_list = json . loads ( params .get ("teams" ) )
204+ teams_list = params .get ("teams" )
205205 teams = Teams .objects .filter (id__in = teams_list , org = request .profile .org )
206206 if teams .exists ():
207207 cases_object .teams .add (* teams )
208208
209209 cases_object .assigned_to .clear ()
210210 if params .get ("assigned_to" ):
211- assinged_to_list = json . loads ( params .get ("assigned_to" ) )
211+ assinged_to_list = params .get ("assigned_to" )
212212 profiles = Profile .objects .filter (
213213 id__in = assinged_to_list , org = request .profile .org , is_active = True
214214 )
@@ -217,7 +217,7 @@ def put(self, request, pk, format=None):
217217
218218 if self .request .FILES .get ("case_attachment" ):
219219 attachment = Attachments ()
220- attachment .created_by = self .request .profile
220+ attachment .created_by = self .request .profile . user
221221 attachment .file_name = self .request .FILES .get ("case_attachment" ).name
222222 attachment .case = cases_object
223223 attachment .attachment = self .request .FILES .get ("case_attachment" )
@@ -366,7 +366,7 @@ def post(self, request, pk, **kwargs):
366366
367367 if self .request .FILES .get ("case_attachment" ):
368368 attachment = Attachments ()
369- attachment .created_by = self .request .profile
369+ attachment .created_by = self .request .profile . user
370370 attachment .file_name = self .request .FILES .get ("case_attachment" ).name
371371 attachment .case = self .cases_obj
372372 attachment .attachment = self .request .FILES .get ("case_attachment" )
@@ -387,7 +387,7 @@ def post(self, request, pk, **kwargs):
387387
388388class CaseCommentView (APIView ):
389389 model = Comment
390- # authentication_classes = (JSONWebTokenAuthentication ,)
390+ authentication_classes = (CustomDualAuthentication ,)
391391 permission_classes = (IsAuthenticated ,)
392392
393393 def get_object (self , pk ):
@@ -450,7 +450,7 @@ def delete(self, request, pk, format=None):
450450
451451class CaseAttachmentView (APIView ):
452452 model = Attachments
453- # authentication_classes = (JSONWebTokenAuthentication ,)
453+ authentication_classes = (CustomDualAuthentication ,)
454454 permission_classes = (IsAuthenticated ,)
455455
456456 @extend_schema (
0 commit comments