Fakultas Ilmu Komputer UI

Commit aa2462ba authored by Dave Nathanael's avatar Dave Nathanael
Browse files

Merge branch 'dave/email-notif-on-account-nonactivate' into 'staging'

Implement email notification on Account deactivation

See merge request !49
parents 5d65973f efb9f5a5
Pipeline #46175 failed with stages
in 4 minutes and 14 seconds
......@@ -208,6 +208,29 @@ class AccountViewTest(APITestCase):
# Activation email sent
self.assertEqual(current_outbox_count, prev_outbox_count + 1)
def test_edit_account_deactivate_send_email(self):
url = self.BASE_URL + str(self.officer.id) + "/"
data = {
"id": str(self.officer.id),
"name": self.faker.name(),
"email": self.faker.email(),
"phone_number": self.faker.phone_number(),
"area": self.faker.city(),
"is_admin": False,
"is_verified": True,
"is_active": False,
}
prev_outbox_count = len(mail.outbox)
self.client = APIClient(HTTP_AUTHORIZATION=HEADER_PREFIX + self.token_2.key)
response = self.client.put(path=url, data=data, format="json",)
current_outbox_count = len(mail.outbox)
# Account deactivation email sent
self.assertEqual(current_outbox_count, prev_outbox_count + 1)
def test_edit_account_fail_without_complete_fields(self):
url = self.BASE_URL + str(self.officer.id) + "/"
......
......@@ -30,6 +30,9 @@ from apps.constants import (
EMAIL_ACCOUNT_ACTIVATION_SENDER,
EMAIL_ACCOUNT_ACTIVATION_CONTENT,
EMAIL_ACCOUNT_ACTIVATION_SUBJECT,
EMAIL_ACCOUNT_DEACTIVATION_SENDER,
EMAIL_ACCOUNT_DEACTIVATION_CONTENT,
EMAIL_ACCOUNT_DEACTIVATION_SUBJECT,
)
......@@ -78,13 +81,22 @@ class AccountViewSet(viewsets.ModelViewSet):
def perform_update(self, serializer):
serializer.save()
if serializer.data["is_verified"] and serializer.data["is_active"]:
is_verified = serializer.data.get("is_verified", None)
is_active = serializer.data.get("is_active", None)
if is_verified and is_active:
send_mail(EMAIL_ACCOUNT_ACTIVATION_SUBJECT,
EMAIL_ACCOUNT_ACTIVATION_CONTENT.format(name=serializer.data["name"]),
EMAIL_ACCOUNT_ACTIVATION_SENDER,
[serializer.data["email"]],
fail_silently=False,
)
elif is_active is False:
send_mail(EMAIL_ACCOUNT_DEACTIVATION_SUBJECT,
EMAIL_ACCOUNT_DEACTIVATION_CONTENT.format(name=serializer.data["name"]),
EMAIL_ACCOUNT_DEACTIVATION_SENDER,
[serializer.data["email"]],
fail_silently=False,
)
def perform_destroy(self, instance):
instance.delete(author=self.request.user.account)
......
......@@ -28,3 +28,11 @@ EMAIL_ACCOUNT_ACTIVATION_CONTENT = """Halo {name},
Akun TBCare Anda telah aktif dan dapat digunakan.
Silahkan buka aplikasi TBCare dan log in menggunakan email dan password yang Anda daftarkan.
"""
EMAIL_ACCOUNT_DEACTIVATION_SENDER = "nezappl@gmail.com"
EMAIL_ACCOUNT_DEACTIVATION_SUBJECT = "TBCare - Akun Non-aktif"
EMAIL_ACCOUNT_DEACTIVATION_CONTENT = """Halo {name},
Akun TBCare Anda telah dinon-aktifkan oleh pengurus.
Silahkan kontak pengurus jika Anda merasa tidak menon-aktifkan akun Anda.
"""
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment