okfn/ckan — pull request #199 by seanh (2012-12-07 18:43:24+00:00)
Title: 1635 feature email notifications for activity streams

Add email notifications for activity streams.

I still need to deploy this to the pdeu staging site for further testing/QA, and I need to write docs for it.

The user stories for this are half-way down this page:

The general approach is: a cron job runs regularly and calls an email notifications function which loops over every user in the site, pulls the dashboard activity stream of the user, and sends an email to the user if they have any new activities.

Details:

* `lib/mailer.py` now accepts `starttls`, `user` and `password` options, and the SMTP-related options have been renamed to be consistent with eachother. This was so I could use my gmail account to send emails when testing.

* Two new ini file settings `ckan.email_notifications` and `ckan.email_notifications_since`

* New 'Email Notifications' user preference, when you edit your profile

* New `lib/email_notifications.py` creates and sends activity streams notification emails, designed to be extensible

* Add `email_last_sent` to dashboard model, this records when a notification email was last sent to a user, it's used to figure out which activities are 'new' (haven't been emailed about yet)

* New `send_email_notifications()` action function. This is meant to be called by cron (via `paster post ...`) to trigger sending out the email notifications. Technically it can also be called via the API.

This is done as an API function because I wanted to call it from `paster post ...` (which simulates an HTTP request) because it creates a Pylons request thread with the various Pylons objects registered. Getting around not being in a Pylons request thread was too painful.

* Apparently I also moved `get.py:dashboard_mark_all_new_activities_as_old()` -> `update.py:dashboard_mark_activities_old()`. This little bit of refactoring seems irrelevant to this feature but there it is.