Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove example.com text from html emails #884

Merged
merged 3 commits into from
Apr 22, 2021
Merged

Remove example.com text from html emails #884

merged 3 commits into from
Apr 22, 2021

Conversation

OmarIthawi
Copy link

@OmarIthawi OmarIthawi commented Apr 22, 2021

Remove example.com from email

This resolved by replacing:

Site.objects.get_current() (Django) --> get_current_site() (edX's)

Because the Django get_current returns the default site (with settings.SITE_ID) always.

The edX function is more site aware and returns the current site by using the request.site value which is the desired behaviour and would prevent the HTML emails from showing example.com in the email body as described in RED-1886.

Refactor account activation email context logic

Both Site.objects.get_current() and theming_helpers.get_current_site() should be run in request context to get the site reliably.

Running either in celery context is error-prone and not multi-tenant.

This commit fixes the errors that were introduced in the three upstream PRs below:

  • edx#22091
  • edx#22042
  • edx#18928

The problem is that using emulate_http_request will not get the real site the had original issue, but instead the settings.SITE_ID.

The fix to use get_current_site() outside the celery context, and pass the get_base_template_context which ensures that
emulate_http_request is no longer needed.

I've also removed a couple of duplicate context variables from generate_activation_email_context since they were provided by
get_base_template_context.

TODO

@OmarIthawi OmarIthawi marked this pull request as draft April 22, 2021 10:13
This resolved by replacing:

`Site.objects.get_current()` (Django) --> `get_current_site()` (edX's)

Because the Django `get_current` returns the default site (with
settings.SITE_ID) _always_.

The edX function is more site aware and returns the current site by
using the `request.site` value which is the desired behaviour and would
prevent the HTML emails from showing `example.com` in the email body as
described in RED-1886.
Both Site.objects.get_current() and theming_helpers.get_current_site()
should be run in request context to get the site reliably.

Running either in celery context is error-prone and not multi-tenant.

This commit fixes the errors that were introduced in the two PRs below:

 - https://github.com/edx/edx-platform/pull/22091
 - https://github.com/edx/edx-platform/pull/22042
 - https://github.com/edx/edx-platform/pull/18928

The problem is that using `emulate_http_request` will not get the real
site the had original issue, but instead the `settings.SITE_ID`.

The fix to use `get_current_site()` _outside_ the celery context, and
pass the `get_base_template_context` which ensures that
`emulate_http_request` is no longer needed.

I've also removed a couple of duplicate context variables from
`generate_activation_email_context` since they were provided by
`get_base_template_context`.
@OmarIthawi OmarIthawi marked this pull request as ready for review April 22, 2021 11:33
@coveralls
Copy link

Coverage Status

Coverage decreased (-0.02%) to 40.215% when pulling f5e99a7 on omar/crs into 4db668b on main.

@OmarIthawi OmarIthawi merged commit 45e0e9b into main Apr 22, 2021
@OmarIthawi OmarIthawi deleted the omar/crs branch April 22, 2021 14:48
OmarIthawi added a commit that referenced this pull request May 27, 2021
The error happened because of the incomplete fix in #884

This commit fixes the issue by getting back the mandatory
`emulate_http_request` but now with a better method to know the site
using our `appsembler.sites.utils` helpers.

This should work on celery tasks while printing the correct site domain
instead of `example.com` as it used to do before RED-1886 was fixed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants