Fakultas Ilmu Komputer UI
Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
ppl-fasilkom-ui
2020
PPL-C
PPTI-Mobile Apps Monitoring Wabah Tuberkolosis
Neza-Backend
Commits
efb9f5a5
Commit
efb9f5a5
authored
May 07, 2020
by
Dave Nathanael
Browse files
Implement email notification on Account deactivation
parent
5d65973f
Changes
3
Hide whitespace changes
Inline
Side-by-side
apps/accounts/tests/test_units/test_accounts.py
View file @
efb9f5a5
...
...
@@ -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
)
+
"/"
...
...
apps/accounts/views.py
View file @
efb9f5a5
...
...
@@ -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
)
...
...
apps/constants.py
View file @
efb9f5a5
...
...
@@ -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.
"""
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment