Skip to content

Commit

Permalink
Add error handling for Fernet key value EDLY-6732 (#542)
Browse files Browse the repository at this point in the history
  • Loading branch information
mfarhan943 authored May 22, 2024
1 parent 8ada0e6 commit 8aedaa5
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions openedx/features/edly/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -764,7 +764,10 @@ def has_not_unsubscribe_user_email(site, email):
except EdlySubOrganization.DoesNotExist:
edly_sub_org = site.edly_sub_org_for_studio

return not EdlyMultiSiteAccess.objects.get(sub_org=edly_sub_org, user__email=email).has_unsubscribed_email
try:
return not EdlyMultiSiteAccess.objects.get(sub_org=edly_sub_org, user__email=email).has_unsubscribed_email
except EdlyMultiSiteAccess.DoesNotExist:
return True


def create_user_unsubscribe_url(email, site):
Expand All @@ -788,15 +791,20 @@ def create_user_unsubscribe_url(email, site):
if not panel_backend_url:
return None

fernet = Fernet(settings.EMAIL_UNSUBSCRIPTION_ENCRYPTION_KEY)
encrypted_user_data = fernet.encrypt(
json.dumps(
{
"email": email,
"sub_org": edly_sub_org.slug,
}
).encode()
).decode()
try:
fernet = Fernet(settings.EMAIL_UNSUBSCRIPTION_ENCRYPTION_KEY)
encrypted_user_data = fernet.encrypt(
json.dumps(
{
"email": email,
"sub_org": edly_sub_org.slug,
}
).encode()
).decode()

except (ValueError, TypeError) as Error:
LOGGER.error('Error encrypting email unsubscribe parameter %s', Error)
return None

url = "{base_url}{sub_url}?param={param}".format(
base_url=panel_backend_url,
Expand Down

0 comments on commit 8aedaa5

Please sign in to comment.