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

4486 email pray and pay #4498

Merged
merged 30 commits into from
Sep 30, 2024
Merged

Conversation

v-anne
Copy link
Contributor

@v-anne v-anne commented Sep 26, 2024

This PR is to add email alerts to #1346, the pray and pay project. It follows up on #4386, which implemented much of the logic for the backend in terms of the Prayer model.

The logic for the email alerts is as follows:
When a document is confirmed to be available on CourtListener, the backend will identify whether any users had requested purchase of that document, and if so, will send all of them an email together informing them of its availability using BCC. The Prayer model will be updated to confirm that the document is now available, which will remove the document from the publicly available display of open requests.

@v-anne v-anne marked this pull request as ready for review September 26, 2024 20:13
@v-anne v-anne marked this pull request as draft September 26, 2024 20:13
@v-anne
Copy link
Contributor Author

v-anne commented Sep 26, 2024

@mlissner @albertisfu

Some progress has been made on the email functionality. I looked at cl/alerts/management/commands/cl_send_alerts.py to see how emails are implemented in other parts of CourtListener. I do have some questions:

  • Could you confirm that I have correctly implemented how to extract the url link to the file?
  • Should I include text similar to the following from alert_email.txt?

 - View this item on our site: https://www.courtlistener.com{{result.absolute_url}}
{% if result.download_url %} - Download original from the court: {{result.download_url}}
{% endif %}{% if result.local_path %} - Download the original from our backup: https://storage.courtlistener.com/{{ result.local_path }}{% endif %}{% endfor %}

@mlissner
Copy link
Member

Everything looks basically right to me, but I'll let Alberto take a more careful look.

@albertisfu
Copy link
Contributor

albertisfu commented Sep 27, 2024

@v-anne I've applied some tweaks to the PR so that email sending works properly.

One of the changes is to use email bulk sending, allowing us to send one email per recipient instead of using BCC. I think this is better due to AWS restrictions of 50 recipients when using the BCC or CC fields:
https://docs.aws.amazon.com/ses/latest/dg/quotas.html

This way, even if we have more than 50 users who need to be notified after a prayer is granted, all of them can receive the message.

  • I also added tests to confirm that email sending works properly.

@mlissner I think the only thing left to confirm is whether the email template is complete or if it requires some tweaks. Currently, the emails look as follows:

Text version:

CourtListener.com
*****************
-------------------------------------------------------
We have news regarding your alerts at CourtListener.com
-------------------------------------------------------

A document you requested to be purchased is now available on CourtListener.
-------------------------------------------------------

 - View this item on our site: https://www.courtlistener.com/docket/121/1/hoffman-v-mason-yu/


************************
This alert brought to you by the 501(c)(3) non-profit Free Law Project
 - Blog: https://free.law
 - BlueSky: https://bsky.app/profile/free.law
 - X: https://x.com/freelawproject
 - Donate: https://donate.free.law/forms/supportflp
 - Become a Member: https://donate.free.law/forms/membership

Please donate to support our work.

HTML version:
Screenshot 2024-09-27 at 3 04 19 p m

There are some CI actions failing related to authentication. I believe it can be something temporary. I'll retry them later.

@mlissner
Copy link
Member

I made a little template that cribs from the alert email:

https://docs.google.com/document/d/1jGjdZPueFXRHILqgI3Pp606EzrEaxvNTkcLdWNJdHTs/edit?usp=sharing

I think it should be pretty easy, but some parts of it might be tricky and it probably isn't worth spending a ton of time on all of it. So consider it a notion, but hopefully one that gives some direction!

Thank you both!

@v-anne
Copy link
Contributor Author

v-anne commented Sep 27, 2024

@mlissner, I left some comments on your Google doc.

@v-anne
Copy link
Contributor Author

v-anne commented Sep 30, 2024

I added three things as you suggested in the Google Doc:

  • price of the document
  • date requested
  • how many people were waiting for it.

Despite our initial hesitance about the date requested component, I decided to include it. I think limiting the query for dates to the QuerySet described below makes this relatively efficient and is a minor use of resources. If you disagree, I'm happy to remove it.

open_prayers = Prayer.objects.filter(
            recap_document=instance, status=Prayer.WAITING
        ).select_related("user")

@v-anne
Copy link
Contributor Author

v-anne commented Sep 30, 2024

@mlissner @albertisfu

I attempted adding the case name and court number to the alerts. I think the case name works but the court name doesn't. I couldn't quite figure out how {{ result.court_citation_string|nbsp|safe }} works in the alert_email.html file.

Otherwise, I think this is almost ready to merge, after one more review.

@mlissner
Copy link
Member

You just have to follow the FK chain. So if you have a RECAPDocument, the full chain would be:

rd.docket_entry.docket.court.whatever_field

I think the correct field on Court is full_name, but I'm not sure. Want to try that?

- Added additional test assertions
@albertisfu
Copy link
Contributor

I've tweaked the templates and email context to make them look more like the email template Mike shared.

Added additional test assertions.

Email subject remains as: A document you requested is now on CourtListener

Screenshot 2024-09-30 at 11 58 33 a m

*****************
CourtListener.com
*****************
-------------------------------------------------------
Your Wish Has Been Granted!
-------------------------------------------------------

The document you were waiting for is now available in RECAP.
-------------------------------------------------------

Velazquez-Watts v. Roberts (4:59-ms-57576)
Thirteenth circuit of the Zoo
~~~
View Docket: https://www.courtlistener.com/docket/342/velazquez-watts-v-roberts/?order_by=desc

Document Number: 6
Date Filed: Aug 16, 2015
Description: Dismissing Case
View Document: https://www.courtlistener.com/docket/342/1/velazquez-watts-v-roberts/
~~~
You requested it on Sep 30, 2024
2 people were also waiting for it.
Somebody paid $1.00 to make it available to all of us.

************************
This alert brought to you by the 501(c)(3) non-profit Free Law Project
 - Blog: https://free.law
 - BlueSky: https://bsky.app/profile/free.law
 - X: https://x.com/freelawproject
 - Donate: https://donate.free.law/forms/supportflp
 - Become a Member: https://donate.free.law/forms/membership

@v-anne v-anne marked this pull request as ready for review September 30, 2024 18:20
@v-anne
Copy link
Contributor Author

v-anne commented Sep 30, 2024

I think this is good to go. Thank you for your work on this, Alberto!

Copy link
Member

@mlissner mlissner left a comment

Choose a reason for hiding this comment

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

One quick comment from me, but Alberto, I leave it to you for full review.

cl/search/signals.py Outdated Show resolved Hide resolved
@mlissner
Copy link
Member

Thank you @v-anne for sticking with this big feature!

@albertisfu albertisfu self-requested a review September 30, 2024 22:45
Copy link
Contributor

@albertisfu albertisfu left a comment

Choose a reason for hiding this comment

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

In addition to Mike's suggestion, I would also recommend moving prayer_email.html and prayer_email.txt to favorites/templates.

With those changes, I think this is good to go.

Thanks @v-anne

cl/search/signals.py Outdated Show resolved Hide resolved
@v-anne
Copy link
Contributor Author

v-anne commented Sep 30, 2024

Both of your comments have now been resolved.

@albertisfu
Copy link
Contributor

Both of your comments have now been resolved.

Thanks LGTM!

Copy link
Member

@mlissner mlissner left a comment

Choose a reason for hiding this comment

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

Very cool. Thank you both.

@v-anne, deployments are blocked atm, but this will go live some time tomorrow, I expect.

Onward to the last pieces!

@mlissner mlissner merged commit 1830fb0 into freelawproject:main Sep 30, 2024
9 checks passed
@v-anne v-anne mentioned this pull request Oct 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

3 participants