From 9b14eedb1876286bdf7e96be30176bd58ec71c68 Mon Sep 17 00:00:00 2001 From: jain Date: Mon, 4 Sep 2023 16:49:18 +0530 Subject: [PATCH 1/2] handle scenerio for task after disassociate --- account/templates/templated_email/support_mail.email | 2 +- account/utils.py | 3 +-- account/views.py | 5 ++--- base/messages.py | 5 ++++- guardian/views.py | 2 ++ junior/views.py | 9 +++++++-- 6 files changed, 17 insertions(+), 9 deletions(-) diff --git a/account/templates/templated_email/support_mail.email b/account/templates/templated_email/support_mail.email index 34d6156..20fcdb1 100644 --- a/account/templates/templated_email/support_mail.email +++ b/account/templates/templated_email/support_mail.email @@ -1,7 +1,7 @@ {% extends "templated_email/email_base.email" %} {% block subject %} - {{subject}} + Support Mail {% endblock %} {% block plain %} diff --git a/account/utils.py b/account/utils.py index 353042a..9ef0106 100644 --- a/account/utils.py +++ b/account/utils.py @@ -167,7 +167,7 @@ def user_device_details(user, device_id): return False -def send_support_email(name, sender, subject, message): +def send_support_email(name, sender, message): """Send otp on email with template""" to_email = [settings.EMAIL_FROM_ADDRESS] from_email = settings.DEFAULT_ADDRESS @@ -179,7 +179,6 @@ def send_support_email(name, sender, subject, message): context={ 'name': name.title(), 'sender': sender, - 'subject': subject, 'message': message } ) diff --git a/account/views.py b/account/views.py index ff0a6e6..a76693e 100644 --- a/account/views.py +++ b/account/views.py @@ -689,11 +689,10 @@ class SendSupportEmail(views.APIView): def post(self, request): name = request.data.get('name') sender = request.data.get('email') - subject = request.data.get('subject') message = request.data.get('message') - if name and sender and subject and message: + if name and sender and message: try: - send_support_email(name, sender, subject, message) + send_support_email(name, sender, message) return custom_response(SUCCESS_CODE['3019'], response_status=status.HTTP_200_OK) except Exception as e: return custom_error_response(str(e), response_status=status.HTTP_400_BAD_REQUEST) diff --git a/base/messages.py b/base/messages.py index feed804..0af15a1 100644 --- a/base/messages.py +++ b/base/messages.py @@ -111,7 +111,10 @@ ERROR_CODE = { "2080": "Can not add App version", "2081": "A junior can only be associated with a maximum of 3 guardian", # guardian code not exist - "2082": "Guardian code does not exist" + "2082": "Guardian code does not exist", + "2083": "You can not start this task because guardian is not associate with you", + "2084": "You can not complete this task because guardian is not associate with you", + "2085": "You can not take action on this task because junior is not associate with you" } """Success message code""" diff --git a/guardian/views.py b/guardian/views.py index 082a9d7..e083708 100644 --- a/guardian/views.py +++ b/guardian/views.py @@ -357,6 +357,8 @@ class ApproveTaskAPIView(viewsets.ModelViewSet): task_queryset = JuniorTask.objects.filter(id=self.request.data.get('task_id'), guardian=guardian, junior=self.request.data.get('junior_id')).last() + if task_queryset and guardian.guardian_code not in task_queryset.junior.guardian_code: + return custom_error_response(ERROR_CODE['2084'], response_status=status.HTTP_400_BAD_REQUEST) if task_queryset and (task_queryset.junior.is_deleted or not task_queryset.junior.is_active): return custom_error_response(ERROR_CODE['2072'], response_status=status.HTTP_400_BAD_REQUEST) # use ApproveJuniorSerializer serializer diff --git a/junior/views.py b/junior/views.py index fd917d2..9a49345 100644 --- a/junior/views.py +++ b/junior/views.py @@ -409,10 +409,12 @@ class CompleteJuniorTaskAPIView(views.APIView): task_queryset = JuniorTask.objects.filter(id=task_id, junior__auth__email=self.request.user ).select_related('guardian', 'junior').last() if task_queryset: - if task_queryset.junior.is_deleted or not task_queryset.junior.is_active: + if task_queryset.guardian.guardian_code not in task_queryset.junior.guardian_code: + return custom_error_response(ERROR_CODE['2085'], response_status=status.HTTP_400_BAD_REQUEST) + elif task_queryset.junior.is_deleted or not task_queryset.junior.is_active: return custom_error_response(ERROR_CODE['2074'], response_status=status.HTTP_400_BAD_REQUEST) # use CompleteTaskSerializer serializer - if task_queryset.task_status in [str(NUMBER['four']), str(NUMBER['five'])]: + elif task_queryset.task_status in [str(NUMBER['four']), str(NUMBER['five'])]: """Already request send """ return custom_error_response(ERROR_CODE['2049'], response_status=status.HTTP_400_BAD_REQUEST) serializer = CompleteTaskSerializer(task_queryset, data={'image': image_url}, partial=True) @@ -517,7 +519,10 @@ class StartTaskAPIView(views.APIView): try: task_id = self.request.data.get('task_id') task_queryset = JuniorTask.objects.filter(id=task_id, junior__auth__email=self.request.user).last() + print("task_queryset==>",task_queryset) if task_queryset and task_queryset.task_status == str(NUMBER['one']): + if task_queryset.guardian.guardian_code not in task_queryset.junior.guardian_code: + return custom_error_response(ERROR_CODE['2083'], response_status=status.HTTP_400_BAD_REQUEST) # use StartTaskSerializer serializer serializer = StartTaskSerializer(task_queryset, data=request.data, partial=True) if serializer.is_valid(): From 65d0932893abe3bcb1dd1b511a1a67f43cd59431 Mon Sep 17 00:00:00 2001 From: jain Date: Mon, 4 Sep 2023 16:52:50 +0530 Subject: [PATCH 2/2] sonar issues --- guardian/serializers.py | 1 + guardian/views.py | 3 ++- notifications/constants.py | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/guardian/serializers.py b/guardian/serializers.py index bd2e43d..0058bdd 100644 --- a/guardian/serializers.py +++ b/guardian/serializers.py @@ -237,6 +237,7 @@ class TaskSerializer(serializers.ModelSerializer): tasks_created = [] for junior_id in junior_data: + # create task task_data = validated_data.copy() task_data['guardian'] = guardian task_data['default_image'] = images diff --git a/guardian/views.py b/guardian/views.py index e083708..e832ec5 100644 --- a/guardian/views.py +++ b/guardian/views.py @@ -208,7 +208,8 @@ class CreateTaskAPIView(viewsets.ModelViewSet): else: filename = f"images/{image}" if image and image.size == NUMBER['zero']: - return custom_error_response(ERROR_CODE['2035'], response_status=status.HTTP_400_BAD_REQUEST) + return custom_error_response(ERROR_CODE['2035'], + response_status=status.HTTP_400_BAD_REQUEST) image_url = upload_image_to_alibaba(image, filename) image_data = image_url data.pop('default_image') diff --git a/notifications/constants.py b/notifications/constants.py index 85b0d2d..c22f246 100644 --- a/notifications/constants.py +++ b/notifications/constants.py @@ -22,7 +22,7 @@ ARTICLE_REWARD_POINTS = 17 REMOVE_JUNIOR = 18 TEST_NOTIFICATION = 99 - +# notification dictionary NOTIFICATION_DICT = { REGISTRATION: { "title": "Successfully registered!",