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.
* - pointing directly to the pg client directory * - Add lots of logging * - fix lint * - naming crontabs for easy understanding * - Removing log entries * - testing old method * - installing postgres client 15 * - print paths to see whats up * - fix lint * - remove all traces of postgres before installing new postgres * - disabling tests for speed * Revert "- remove all traces of postgres before installing new postgres" This reverts commit 76c4b9d. * Revert "- fix lint" This reverts commit 27ff2db. * Revert "- installing postgres client 15" This reverts commit 2097d8d. * Revert "Revert "- fix lint"" This reverts commit 64c6907. * - Add correct client to apt.yml * - making tests even shorter * - trying clietn V14 * - removing from apt and installing manually * Revert "- removing from apt and installing manually" This reverts commit a2f94d3. * - revert * - Version 12 in apt.yml - Tell terraform to specify db version * - escaping quotes * - forcing db name * Revert "- forcing db name" This reverts commit b606933. * - logging - every 5 min * - more logging * - Cleanup debug code - update tf environments to force version 12 of pg server * - Fix lint * - Adding back client search if hardcoded path doesn't exist * - fix syntax error * - fix lint * - remove extra slash * - Adding log entries to backup task * - Moving DB task to it's own file * - fix lint * - Seperate out email tasks - update crontabs * - update tests --------- Co-authored-by: Alex P <[email protected]> Co-authored-by: Andrew <[email protected]>
- Loading branch information
1 parent
c8d0934
commit d559d4f
Showing
8 changed files
with
263 additions
and
111 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
"""Shared celery email tasks for beat.""" | ||
|
||
from __future__ import absolute_import | ||
from tdpservice.users.models import User, AccountApprovalStatusChoices | ||
from django.contrib.auth.models import Group | ||
from django.conf import settings | ||
from django.urls import reverse | ||
from django.utils import timezone | ||
from celery import shared_task | ||
from datetime import datetime, timedelta | ||
import logging | ||
from tdpservice.email.helpers.account_access_requests import send_num_access_requests_email | ||
from tdpservice.email.helpers.account_deactivation_warning import send_deactivation_warning_email | ||
|
||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
@shared_task | ||
def check_for_accounts_needing_deactivation_warning(): | ||
"""Check for accounts that need deactivation warning emails.""" | ||
deactivate_in_10_days = users_to_deactivate(10) | ||
deactivate_in_3_days = users_to_deactivate(3) | ||
deactivate_in_1_day = users_to_deactivate(1) | ||
|
||
if deactivate_in_10_days: | ||
send_deactivation_warning_email(deactivate_in_10_days, 10) | ||
if deactivate_in_3_days: | ||
send_deactivation_warning_email(deactivate_in_3_days, 3) | ||
if deactivate_in_1_day: | ||
send_deactivation_warning_email(deactivate_in_1_day, 1) | ||
|
||
def users_to_deactivate(days): | ||
"""Return a list of users that have not logged in in the last {180 - days} days.""" | ||
days = 180 - days | ||
return User.objects.filter( | ||
last_login__lte=datetime.now(tz=timezone.utc) - timedelta(days=days), | ||
last_login__gte=datetime.now(tz=timezone.utc) - timedelta(days=days+1), | ||
account_approval_status=AccountApprovalStatusChoices.APPROVED, | ||
) | ||
|
||
def get_ofa_admin_user_emails(): | ||
"""Return a list of OFA System Admin and OFA Admin users.""" | ||
return User.objects.filter( | ||
groups__in=Group.objects.filter(name__in=('OFA Admin', 'OFA System Admin')) | ||
).values_list('email', flat=True).distinct() | ||
|
||
def get_num_access_requests(): | ||
"""Return the number of users requesting access.""" | ||
return User.objects.filter( | ||
account_approval_status=AccountApprovalStatusChoices.ACCESS_REQUEST, | ||
).count() | ||
|
||
@shared_task | ||
def email_admin_num_access_requests(): | ||
"""Send all OFA System Admins an email with how many users have requested access.""" | ||
recipient_email = get_ofa_admin_user_emails() | ||
text_message = '' | ||
subject = 'Number of Active Access Requests' | ||
url = f'{settings.FRONTEND_BASE_URL}{reverse("admin:users_user_changelist")}?o=-2' | ||
email_context = { | ||
'date': datetime.today(), | ||
'num_requests': get_num_access_requests(), | ||
'admin_user_pg': url, | ||
} | ||
|
||
send_num_access_requests_email(recipient_email, | ||
text_message, | ||
subject, | ||
email_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
Oops, something went wrong.