forked from HHS/TANF-app
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
2561 Deactivating inactive user automatically (#3145)
* Added logic and test for deactivating the user automatically * 2561- linting * added admin notification * linting * [2561] added sending email to admin * Update tdrs-backend/tdpservice/email/helpers/admin_notifications.py Co-authored-by: Alex P. <[email protected]> --------- Co-authored-by: Alex P. <[email protected]>
- Loading branch information
1 parent
abd8609
commit edeaac7
Showing
7 changed files
with
103 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
tdrs-backend/tdpservice/email/helpers/admin_notifications.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
"""helper functions to administer user accounts.""" | ||
|
||
def email_admin_deactivated_user(user): | ||
"""Send an email to OFA Admins when a user is deactivated.""" | ||
from tdpservice.users.models import User | ||
from tdpservice.email.email_enums import EmailType | ||
from tdpservice.email.email import automated_email, log | ||
from tdpservice.email.tasks import get_ofa_admin_user_emails | ||
|
||
recipient_emails = get_ofa_admin_user_emails() | ||
logger_context = { | ||
'user_id': user.id, | ||
'object_id': user.id, | ||
'object_repr': user.username, | ||
'content_type': User, | ||
} | ||
|
||
template_path = EmailType.ACCOUNT_DEACTIVATED_ADMIN.value | ||
text_message = 'A user account has been deactivated.' | ||
subject = ' TDP User Account Deactivated due to Inactivity' | ||
context = { | ||
'user': user, | ||
} | ||
|
||
log(f"Preparing email to OFA Admins for deactivated user {user.username}", logger_context=logger_context) | ||
|
||
for recipient_email in recipient_emails: | ||
automated_email( | ||
email_path=template_path, | ||
recipient_email=recipient_email, | ||
subject=subject, | ||
email_context=context, | ||
text_message=text_message, | ||
logger_context=logger_context | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
tdrs-backend/tdpservice/email/templates/account-deactivated-admin.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{% extends 'base.html' %} | ||
{% block content %} | ||
<!-- Body copy --> | ||
<p style="color: #000000;"> | ||
|
||
<p>The following user account for the TANF Data Portal (TDP) has been deactivated.</p> | ||
|
||
<p>Account Information:</p> | ||
<ul> | ||
<li>Name: {{ user.first_name }}</li> | ||
<li>Last name: {{ user.last_name }}</li> | ||
<li>Email: {{ user.email }}</li> | ||
</ul> | ||
|
||
<p>Thank you,</p> | ||
TDP Team | ||
</p> | ||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters