Skip to content

Commit

Permalink
[#1635] Remove two unwanted action functions
Browse files Browse the repository at this point in the history
Remove dashboard_email_notification_last_sent and
dashboard_update_email_notification_last_sent logic functions, instead access
the model functions  directly from the lib.

We're not supposed to access the model from the lib, but I don't want to expose
these function as action functions either because they're only needed by this
one lib, I don't want to expose them in the API.
  • Loading branch information
Sean Hammond committed Nov 27, 2012
1 parent 097cb91 commit d03f0a4
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 25 deletions.
23 changes: 13 additions & 10 deletions ckan/lib/email_notifications.py
Expand Up @@ -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.
Expand Down
7 changes: 0 additions & 7 deletions ckan/logic/action/get.py
Expand Up @@ -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
Expand Down
8 changes: 0 additions & 8 deletions ckan/logic/action/update.py
Expand Up @@ -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.
Expand All @@ -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)


0 comments on commit d03f0a4

Please sign in to comment.