Skip to content

Commit

Permalink
feat: Send action required by time to braze campaign (#482)
Browse files Browse the repository at this point in the history
* feat: Send action required by time to braze campaign

* chore: PR Feedback

* chore: PR feedback

* chore: re-added action_required_by field for continuity of data
  • Loading branch information
brobro10000 committed Jun 11, 2024
1 parent 4454ee3 commit d8b0ef3
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
2 changes: 2 additions & 0 deletions enterprise_access/apps/content_assignments/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,3 +121,5 @@ class AssignmentAutomaticExpiredReason:
NUM_DAYS_BEFORE_AUTO_EXPIRATION = 90

RETIRED_EMAIL_ADDRESS_FORMAT = 'retired_user{}@retired.invalid'

BRAZE_ACTION_REQUIRED_BY_TIMESTAMP_FORMAT = "%-I:%M %p %b %d, %Y"
20 changes: 17 additions & 3 deletions enterprise_access/apps/content_assignments/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from enterprise_access.tasks import LoggedTaskWithRetry
from enterprise_access.utils import get_automatic_expiration_date_and_reason, localized_utcnow

from .constants import LearnerContentAssignmentStateChoices
from .constants import BRAZE_ACTION_REQUIRED_BY_TIMESTAMP_FORMAT, LearnerContentAssignmentStateChoices

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -59,6 +59,7 @@ class BrazeCampaignSender:
'course_card_image',
'learner_portal_link',
'action_required_by',
'action_required_by_timestamp'
}

def __init__(self, assignment):
Expand Down Expand Up @@ -213,6 +214,19 @@ def get_action_required_by(self):
return None
return format_datetime_obj(action_required_by['date'])

def get_action_required_by_timestamp(self):
"""
Returns the minimum of this assignment's auto-expiration date,
the content's enrollment deadline, and the related policy's expiration timestamp.
"""
action_required_by_timestamp = get_automatic_expiration_date_and_reason(self.assignment)
if not action_required_by_timestamp:
return None
return format_datetime_obj(
action_required_by_timestamp['date'],
output_pattern=BRAZE_ACTION_REQUIRED_BY_TIMESTAMP_FORMAT
)

def get_course_partner(self):
return get_course_partners(self.course_metadata)

Expand Down Expand Up @@ -372,12 +386,10 @@ def send_exec_ed_enrollment_warmer(assignment_uuid, days_before_course_start_dat
'contact_admin_link',
'organization',
'course_title',
'enrollment_deadline',
'start_date',
'course_partner',
'course_card_image',
'learner_portal_link',
'action_required_by',
)

braze_trigger_properties['days_before_course_start_date'] = days_before_course_start_date
Expand Down Expand Up @@ -436,6 +448,7 @@ def send_reminder_email_for_pending_assignment(assignment_uuid):
'course_card_image',
'learner_portal_link',
'action_required_by',
'action_required_by_timestamp'
)
campaign_uuid = settings.BRAZE_ASSIGNMENT_REMINDER_NOTIFICATION_CAMPAIGN
if assignment.lms_user_id is not None:
Expand Down Expand Up @@ -479,6 +492,7 @@ def send_email_for_new_assignment(new_assignment_uuid):
'course_card_image',
'learner_portal_link',
'action_required_by',
'action_required_by_timestamp'
)
campaign_uuid = settings.BRAZE_ASSIGNMENT_NOTIFICATION_CAMPAIGN
campaign_sender.send_campaign_message(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,7 @@ def test_send_reminder_email_for_pending_assignment(
'course_card_image': 'https://itsanimage.com',
'learner_portal_link': 'http://enterprise-learner-portal.example.com/test-slug',
'action_required_by': 'Jan 01, 2021',
'action_required_by_timestamp': '12:00 PM Jan 01, 2021'
},
)

Expand Down Expand Up @@ -448,6 +449,7 @@ def test_send_email_for_new_assignment(
'course_card_image': 'https://itsanimage.com',
'learner_portal_link': '{}/{}'.format(settings.ENTERPRISE_LEARNER_PORTAL_URL, 'test-slug'),
'action_required_by': 'Jan 01, 2021',
'action_required_by_timestamp': '12:00 PM Jan 01, 2021'
},
)
assert mock_braze_client.return_value.send_campaign_message.call_count == 1
Expand Down

0 comments on commit d8b0ef3

Please sign in to comment.