Skip to content

feat: Handle incoming user confirmation for newsletter subscription

stephen requested to merge newsletter-signup-post-click into main

After a user confirms their intent to subscribe to the Tor newsletter, the donate site must handle that confirmation by performing a few actions:

  1. Retrieving the token from the URL params
  2. Using that token as a key to retrieve data from Redis, should it still exist
  3. Deserializing the data and ensuring it still unpacks into a JSON object that can be parsed as a dict, containing "first_name", "last_name", and "email_address" keys
  4. Passing off that data to Resque to be sent to CiviCRM
  5. Iterating the subscriber counter upwards
  6. Redirecting the user to an appropriate thank-you page - or, in the event that any of the prior steps encountered an error, serving them a Tor newsletter signup form instead

The purpose of this MR is to extend the CiviCRM repository with this functionality. (Note that the contents and functionality of the signup form are intended to be fulfilled by a near-future MR of its own, and so are not included with this commit. Instead, a stub page is included for functional purposes.)

This commit contains nearly all of the content which this MR is intended to contain:

  • tordonate/urls.py was created and urlpatterns expanded to hold three routes - /confirm-subscription, for incoming traffic from newsletter-signup confirmation email, /subscribed/, for users who successfully authenticate their confirmation by passing a valid token, and /subscribe/, for users whose link doesn't work for one reason or another.
  • tordonate/views.py was created and expanded to serve three views: Two straightforward template-serving views for /subscribed/ and /subscribe/, and confirm_subscription(), which simply serves the HttpRequest returned by CivicrmRepositoryProtocol.confirm_subscription.
  • tordonate/repository.py has been expanded to contain confirm_subscription(), which handles all of the logic described in the above numbered list, with the exception of #5 (closed).
  • The templates subscribed.html.jinja and subscribe.html.jinja have been created.
  • tordonate/urls.py was extended to include civicrm routes.
  • tordonate/apps.py was modified to accomodate the DI occurring in CiviCRM's views.py.

Merge request reports

Loading