From ad4d782e726a4799398c557c4ab96abc19818371 Mon Sep 17 00:00:00 2001 From: abutalib-kiwi Date: Tue, 3 Oct 2023 18:54:47 +0530 Subject: [PATCH] added mail for user activation, handled fcm token for deleted user --- .../templated_email/user_activate.email | 22 +++++++++++++++++++ base/tasks.py | 1 + notifications/utils.py | 1 + web_admin/views/user_management.py | 12 +++++++--- 4 files changed, 33 insertions(+), 3 deletions(-) create mode 100644 account/templates/templated_email/user_activate.email diff --git a/account/templates/templated_email/user_activate.email b/account/templates/templated_email/user_activate.email new file mode 100644 index 0000000..24ba5f8 --- /dev/null +++ b/account/templates/templated_email/user_activate.email @@ -0,0 +1,22 @@ +{% extends "templated_email/email_base.email" %} + +{% block subject %} + Account Activated +{% endblock %} + +{% block plain %} + + +

+ Hi User, +

+ + + + +

+ We're pleased to inform you that your account has been successfully reactivated by our admin team. Welcome back to ZOD !

You can now access all the features and services as before. If you have any questions or need assistance, please feel free to reach out to our support team.

Thank you for being a valued member of our community. +

+ + +{% endblock %} diff --git a/base/tasks.py b/base/tasks.py index ebc6672..edd3dd1 100644 --- a/base/tasks.py +++ b/base/tasks.py @@ -48,6 +48,7 @@ def notify_task_expiry(): :return: """ all_pending_tasks = JuniorTask.objects.filter( + junior__is_verified=True, task_status__in=[PENDING, IN_PROGRESS], due_date__range=[datetime.datetime.now().date(), (datetime.datetime.now().date() + datetime.timedelta(days=1))]) diff --git a/notifications/utils.py b/notifications/utils.py index 0ad6cda..46509eb 100644 --- a/notifications/utils.py +++ b/notifications/utils.py @@ -24,6 +24,7 @@ User = get_user_model() def register_fcm_token(user_id, registration_id, device_id, device_type): """ used to register the fcm device token""" + FCMDevice.objects.filter(registration_id=registration_id).delete() device, _ = FCMDevice.objects.update_or_create(user_id=user_id, defaults={'device_id': device_id, 'type': device_type, 'active': True, diff --git a/web_admin/views/user_management.py b/web_admin/views/user_management.py index 6980a7a..b0b611e 100644 --- a/web_admin/views/user_management.py +++ b/web_admin/views/user_management.py @@ -120,17 +120,23 @@ class UserManagementViewSet(GenericViewSet, mixins.ListModelMixin, if user_type not in [GUARDIAN, JUNIOR]: return custom_error_response(ERROR_CODE['2067'], status.HTTP_400_BAD_REQUEST) - email_template = 'user_deactivate.email' - if user_type == GUARDIAN: obj = Guardian.objects.filter(user_id=kwargs['pk'], is_verified=True).select_related('user').first() elif user_type == JUNIOR: obj = Junior.objects.filter(auth_id=kwargs['pk'], is_verified=True).select_related('auth').first() + if not obj: + return custom_error_response(ERROR_CODE['2004'], status.HTTP_400_BAD_REQUEST) + if obj.is_active: + deactivate_email_template = 'user_deactivate.email' obj.is_active = False - send_email([obj.user.email if user_type == GUARDIAN else obj.auth.email], email_template) + send_email([obj.user.email if user_type == GUARDIAN else obj.auth.email], + deactivate_email_template) else: + activate_email_template = 'user_activate.email' obj.is_active = True + send_email([obj.user.email if user_type == GUARDIAN else obj.auth.email], + activate_email_template) obj.save() return custom_response(SUCCESS_CODE['3038'])