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

Email for saved searches #1619

Merged
merged 14 commits into from
Oct 1, 2024
Merged

Email for saved searches #1619

merged 14 commits into from
Oct 1, 2024

Conversation

shanbady
Copy link
Contributor

@shanbady shanbady commented Sep 27, 2024

What are the relevant tickets?

Closes https://github.com/mitodl/hq/issues/5578

Description (What does it do?)

This PR tweaks the emails sent out for search subscription emails and also activates the search subscription email as a celery task.

Screenshots (if appropriate):

Screenshot 2024-09-27 at 4 33 07 PM Screenshot 2024-09-27 at 4 33 15 PM

How can this be tested?

  1. checkout this branch.
  2. go to RC env var settings in heroku and copy down the following into your local settings:
    MAILGUN_SENDER_DOMAIN
    MAILGUN_KEY
    MAILGUN_FROM_EMAIL
    NOTIFICATION_EMAIL_BACKEND
  3. restart celery via docker compose restart celery
  4. created a saved search subscription that catches learning resources from any provider via the following django shell script (replace user with your own email)
from django.contrib.auth import get_user_model
from learning_resources_search.models import PercolateQuery
from learning_resources_search.api import subscribe_user_to_search_query

User = get_user_model()
migrated_user = User.objects.get(email='[email protected]')
subscribe_user_to_search_query(migrated_user, {"offered_by": ["mitpe", "mitx", "ocw", "see"]}, PercolateQuery.SEARCH_SUBSCRIPTION_TYPE)
  1. Change the "created_on" date locally for a few learning resources. I usually manually do it via this django script:
import datetime
delta = datetime.timedelta(days=1)
since = now_in_utc() - delta


resources = LearningResource.objects.filter(published=True)[50:53]

for resource in resources:
	resource.created_on = since  +  datetime.timedelta(hours=1)
	resource.save()
  1. manually send out subscription emails for search subscriptions (make sure the email you have locally is an inbox you have access to):
from learning_resources_search.models import PercolateQuery
from learning_resources_search.tasks import send_subscription_emails
send_subscription_emails(PercolateQuery.SEARCH_SUBSCRIPTION_TYPE)

@shanbady shanbady changed the title Shanbady/email for saved searches Email for saved searches Sep 27, 2024
@shanbady shanbady marked this pull request as ready for review September 30, 2024 17:25
@shanbady shanbady added Needs Review An open Pull Request that is ready for review and removed Work in Progress labels Sep 30, 2024
@mbertrand mbertrand self-assigned this Oct 1, 2024
Copy link
Member

@mbertrand mbertrand left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, just one suggestion to add a docstring to a function. Also, I noticed that heroku mitopen-rc has an MITOPEN_NOTIFICATION_EMAIL_BACKEND setting but I think it should be MITOL_NOTIFICATION_EMAIL_BACKEND instead.

@@ -884,20 +887,24 @@ def _generate_subscription_digest_subject(
prefix = "" if shortform else "MIT Learn: "

if sample_course["source_channel_type"] == "saved_search":
if shortform:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When would this shortform be used? Would be helpful to add a dosctring to this function with Args and Returns sections

@mbertrand mbertrand added Waiting on author and removed Needs Review An open Pull Request that is ready for review labels Oct 1, 2024
@shanbady shanbady merged commit c20662a into main Oct 1, 2024
11 checks passed
@odlbot odlbot mentioned this pull request Oct 1, 2024
3 tasks
mbertrand pushed a commit that referenced this pull request Oct 4, 2024
* fixing subject for saved search

* changes for formatting search subscription emails

* returning channel only if channel subscription type

* fixing tests

* grouping by individual queries

* adding search subscription email sending to celery tasks

* reverting iterating through individual queries

* removing unused template

* fixing resource type display in emails

* adding docstring and fixing resource type description

* fixing test

* fixing test

* fixing test
@shanbady shanbady deleted the shanbady/email-for-saved-searches branch October 9, 2024 19:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants