Skip to content
This repository has been archived by the owner on Nov 4, 2024. It is now read-only.

Commit

Permalink
Ent 4282 offer emails (#122)
Browse files Browse the repository at this point in the history
* Update emails to accept base_enterprise_url

and pass it to the sailthru template

* Ignore virtual enviroments

* Bump version
  • Loading branch information
Lael Birch authored Mar 10, 2021
1 parent f7791f1 commit b3083e5
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 13 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,6 @@ private.py

# pyenv
.python-version

# virtual env
.venv/
60 changes: 48 additions & 12 deletions ecommerce_worker/sailthru/v1/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,14 @@ def send_offer_assignment_email(self, user_email, offer_assignment_id, subject,
self, user_email, offer_assignment_id, subject, email_body, sender_alias, site_code, base_enterprise_url)
else:
_send_offer_assignment_email_via_sailthru(
self, user_email, offer_assignment_id, subject, email_body, sender_alias, site_code, base_enterprise_url)
self, user_email,
offer_assignment_id,
subject,
email_body,
sender_alias,
site_code=site_code,
base_enterprise_url=base_enterprise_url
)


def _update_assignment_email_status(offer_assignment_id, send_id, status, site_code=None):
Expand Down Expand Up @@ -551,7 +558,7 @@ def _send_offer_update_email_via_braze(self, user_email, subject, email_body, se
)


def _send_offer_update_email_via_sailthru(self, user_email, subject, email_body, sender_alias, site_code=None):
def _send_offer_update_email_via_sailthru(self, user_email, subject, email_body, sender_alias, site_code=None, base_enterprise_url=''):
"""
Sends the offer emails after assignment via sailthru, either for revoking or reminding.
Expand All @@ -571,6 +578,7 @@ def _send_offer_update_email_via_sailthru(self, user_email, subject, email_body,
'subject': subject,
'email_body': email_body,
'sender_alias': sender_alias,
'base_enterprise_url': base_enterprise_url
},
logger_prefix='Offer Assignment',
site_code=site_code,
Expand All @@ -582,7 +590,7 @@ def _send_offer_update_email_via_sailthru(self, user_email, subject, email_body,


@shared_task(bind=True, ignore_result=True)
def send_offer_update_email(self, user_email, subject, email_body, sender_alias, site_code=None):
def send_offer_update_email(self, user_email, subject, email_body, sender_alias, site_code=None, base_enterprise_url=''):
"""
Sends the offer emails after assignment, either for revoking or reminding.
Expand All @@ -593,13 +601,21 @@ def send_offer_update_email(self, user_email, subject, email_body, sender_alias,
email_body (str): The body of the email.
site_code (str): Identifier of the site sending the email.
sender_alias (str): Enterprise Customer sender alias used as From Name.
base_enterprise_url (str): Enterprise learner portal url.
"""
config = get_braze_configuration(site_code)
braze_enable = config.get('BRAZE_ENABLE')
if braze_enable:
_send_offer_update_email_via_braze(self, user_email, subject, email_body, sender_alias, site_code)
else:
_send_offer_update_email_via_sailthru(self, user_email, subject, email_body, sender_alias, site_code)
_send_offer_update_email_via_sailthru(self,
user_email,
subject,
email_body,
sender_alias,
site_code=site_code,
base_enterprise_url=base_enterprise_url
)


def _send_offer_usage_email_via_braze(self, emails, subject, email_body, site_code=None):
Expand Down Expand Up @@ -632,7 +648,7 @@ def _send_offer_usage_email_via_braze(self, emails, subject, email_body, site_co
)


def _send_offer_usage_email_via_sailthru(self, emails, subject, email_body, site_code=None):
def _send_offer_usage_email_via_sailthru(self, emails, subject, email_body, site_code=None, base_enterprise_url=''):
"""
Sends the offer usage email via sailthru.
Expand All @@ -642,26 +658,28 @@ def _send_offer_usage_email_via_sailthru(self, emails, subject, email_body, site
subject (str): Email subject.
email_body (str): The body of the email.
site_code (str): Identifier of the site sending the email.
base_enterprise_url (str): Url for the enterprise's learner portal
"""
config = get_sailthru_configuration(site_code)
notification = Notification(
config=config,
emails=emails,
email_vars={
'subject': subject,
'email_body': email_body
'email_body': email_body,
'base_enteprise_url': base_enterprise_url
},
logger_prefix='Offer Usage',
site_code=site_code,
template='assignment_email'
template='assignment_email',
)
_, is_eligible_for_retry = notification.send(is_multi_send=True)
if is_eligible_for_retry:
schedule_retry(self, config)


@shared_task(bind=True, ignore_result=True)
def send_offer_usage_email(self, emails, subject, email_body, site_code=None):
def send_offer_usage_email(self, emails, subject, email_body, site_code=None, base_enterprise_url=''):
"""
Sends the offer usage email.
Expand All @@ -671,13 +689,21 @@ def send_offer_usage_email(self, emails, subject, email_body, site_code=None):
subject (str): Email subject.
email_body (str): The body of the email.
site_code (str): Identifier of the site sending the email.
base_enterprise_url (str): Url of the enterprise's learner portal
"""
config = get_braze_configuration(site_code)
braze_enable = config.get('BRAZE_ENABLE')
if braze_enable:
_send_offer_usage_email_via_braze(self, emails, subject, email_body, site_code)
else:
_send_offer_usage_email_via_sailthru(self, emails, subject, email_body, site_code)
_send_offer_usage_email_via_sailthru(
self,
emails,
subject,
email_body,
site_code=site_code,
base_enterprise_url=base_enterprise_url
)


def _send_code_assignment_nudge_email_via_braze(self, email, subject, email_body, sender_alias, site_code=None):
Expand Down Expand Up @@ -712,7 +738,7 @@ def _send_code_assignment_nudge_email_via_braze(self, email, subject, email_body
)


def _send_code_assignment_nudge_email_via_sailthru(self, email, subject, email_body, sender_alias, site_code=None):
def _send_code_assignment_nudge_email_via_sailthru(self, email, subject, email_body, sender_alias, site_code=None, base_enterprise_url=''):
"""
Sends the code assignment nudge email via sailthru.
Expand All @@ -723,6 +749,7 @@ def _send_code_assignment_nudge_email_via_sailthru(self, email, subject, email_b
email_body (str): The body of the email.
sender_alias (str): Enterprise Customer sender alias used as From Name.
site_code (str): Identifier of the site sending the email.
base_enterprise_url (str): Enterprise learner portal url
"""
config = get_sailthru_configuration(site_code)
notification = Notification(
Expand All @@ -732,6 +759,7 @@ def _send_code_assignment_nudge_email_via_sailthru(self, email, subject, email_b
'subject': subject,
'email_body': email_body,
'sender_alias': sender_alias,
'base_enteprise_url': base_enterprise_url,
},
logger_prefix='Code Assignment Nudge Email',
site_code=site_code,
Expand All @@ -743,7 +771,7 @@ def _send_code_assignment_nudge_email_via_sailthru(self, email, subject, email_b


@shared_task(bind=True, ignore_result=True)
def send_code_assignment_nudge_email(self, email, subject, email_body, sender_alias, site_code=None):
def send_code_assignment_nudge_email(self, email, subject, email_body, sender_alias, site_code=None, base_enterprise_url=''):
"""
Sends the code assignment nudge email.
Expand All @@ -754,10 +782,18 @@ def send_code_assignment_nudge_email(self, email, subject, email_body, sender_al
email_body (str): The body of the email.
sender_alias (str): Enterprise Customer sender alias used as From Name.
site_code (str): Identifier of the site sending the email.
base_enterprise_url (str): Enterprise learner portal url.
"""
config = get_braze_configuration(site_code)
braze_enable = config.get('BRAZE_ENABLE')
if braze_enable:
_send_code_assignment_nudge_email_via_braze(self, email, subject, email_body, sender_alias, site_code)
else:
_send_code_assignment_nudge_email_via_sailthru(self, email, subject, email_body, sender_alias, site_code)
_send_code_assignment_nudge_email_via_sailthru(self,
email,
subject,
email_body,
sender_alias,
site_code=site_code,
base_enterprise_url=base_enterprise_url
)
3 changes: 3 additions & 0 deletions ecommerce_worker/sailthru/v1/tests/test_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -713,19 +713,22 @@ class SendOfferEmailsTests(BaseSendEmailTests):
'user_email': USER_EMAIL,
'subject': SUBJECT,
'email_body': EMAIL_BODY,
'base_enterprise_url': BASE_ENTERPRISE_URL,
'sender_alias': SENDER_ALIAS,
}

USAGE_TASK_KWARGS = {
'emails': EMAILS,
'subject': SUBJECT,
'base_enterprise_url': BASE_ENTERPRISE_URL,
'email_body': EMAIL_BODY,
}

NUDGE_TASK_KWARGS = {
'email': USER_EMAIL,
'subject': SUBJECT,
'email_body': EMAIL_BODY,
'base_enterprise_url': BASE_ENTERPRISE_URL,
'sender_alias': SENDER_ALIAS,
}

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def is_requirement(line):

setup(
name='edx-ecommerce-worker',
version='1.1.11',
version='1.1.12',
description='Celery tasks supporting the operations of edX\'s ecommerce service',
long_description=long_description,
classifiers=[
Expand Down

0 comments on commit b3083e5

Please sign in to comment.