diff --git a/ckan/lib/email_notifications.py b/ckan/lib/email_notifications.py index 4a1ab4d838d..d4001efbdfa 100644 --- a/ckan/lib/email_notifications.py +++ b/ckan/lib/email_notifications.py @@ -105,22 +105,25 @@ def send_notification(user, email_dict): try: ckan.lib.mailer.mail_recipient(user['display_name'], user['email'], email_dict['subject'], email_dict['body']) - context = {'model': model, 'session': model.Session, - 'user': user['name']} - response = logic.get_action('dashboard_update_email_notification_last_sent')( - context, {}) + # FIXME: We are accessing model from lib here but I'm not sure what + # else to do unless we add a update_activity_stream_last_viewed() + # logic function which would only be needed by this lib. + model.Dashboard.update_last_activity_stream_email_notification( + user['id']) # TODO: Do something with response? except ckan.lib.mailer.MailerException: raise def get_and_send_notifications_for_user(user): - # FIXME: Get the time that the last email notification was sent to the - # user and the time that they last viewed their dashboard, set `since` to - # whichever is more recent. - context = {'model': model, 'session': model.Session, 'user': user['name']} - since = logic.get_action('dashboard_email_notification_last_sent')( - context, {}) + # FIXME: `since` here should be the time that the last email notification + # was sent _or_ the time the user last viewed her dashboard, whichever is + # newer. + # FIXME: We are accessing model from lib here but I'm not sure what else + # to do unless we add a get_activity_stream_last_viewed() logic function + # which would only be needed by this lib. + since = model.Dashboard.get_last_activity_stream_email_notification( + user['id']) notifications = get_notifications(user['id'], since) # TODO: Handle failures from send_email_notification. diff --git a/ckan/logic/action/get.py b/ckan/logic/action/get.py index e9d797b566c..3570fb70078 100644 --- a/ckan/logic/action/get.py +++ b/ckan/logic/action/get.py @@ -2269,13 +2269,6 @@ def dashboard_new_activities_count(context, data_dict): return len([activity for activity in activities if activity['is_new']]) -def dashboard_email_notification_last_sent(context, data_dict): - model = context['model'] - user = model.User.get(context['user']) # The authorized user. - last_viewed = model.Dashboard.get_activity_stream_last_viewed(user.id) - return last_viewed - - def _unpick_search(sort, allowed_fields=None, total=None): ''' This is a helper function that takes a sort string eg 'name asc, last_modified desc' and returns a list of diff --git a/ckan/logic/action/update.py b/ckan/logic/action/update.py index 7508a4a297c..14db528bf58 100644 --- a/ckan/logic/action/update.py +++ b/ckan/logic/action/update.py @@ -939,12 +939,6 @@ def user_role_bulk_update(context, data_dict): return _get_action('roles_show')(context, data_dict) -def dashboard_update_email_notification_last_sent(context, data_dict): - model = context['model'] - user = model.User.get(context['user']) # The authorized user. - model.Dashboard.update_activity_stream_last_viewed(user.id) - - def dashboard_mark_activities_old(context, data_dict): '''Mark all the authorized user's new dashboard activities as old. @@ -956,5 +950,3 @@ def dashboard_mark_activities_old(context, data_dict): model = context['model'] user_id = model.User.get(context['user']).id model.Dashboard.update_activity_stream_last_viewed(user_id) - -