Skip to content

Commit

Permalink
[#1635] Rename dashboard_mark_activities_old
Browse files Browse the repository at this point in the history
Change long name dashboard_mark_all_new_activities_as_old ->
dashboard_mark_activities_old, also move it from get.py to update.py where it
belongs.
  • Loading branch information
Sean Hammond committed Nov 25, 2012
1 parent edc833e commit 097cb91
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 27 deletions.
2 changes: 1 addition & 1 deletion ckan/controllers/user.py
Expand Up @@ -505,7 +505,7 @@ def dashboard(self, id=None):

# Mark the user's new activities as old whenever they view their
# dashboard page.
get_action('dashboard_mark_all_new_activities_as_old')(context, {})
get_action('dashboard_mark_activities_old')(context, {})

return render('user/dashboard.html')

Expand Down
13 changes: 0 additions & 13 deletions ckan/logic/action/get.py
Expand Up @@ -2269,19 +2269,6 @@ def dashboard_new_activities_count(context, data_dict):
return len([activity for activity in activities if activity['is_new']])


def dashboard_mark_all_new_activities_as_old(context, data_dict):
'''Mark all the authorized user's new dashboard activities as old.
This will reset dashboard_new_activities_count to 0.
'''
_check_access('dashboard_mark_all_new_activities_as_old', context,
data_dict)
model = context['model']
user_id = model.User.get(context['user']).id
model.Dashboard.update_activity_stream_last_viewed(user_id)


def dashboard_email_notification_last_sent(context, data_dict):
model = context['model']
user = model.User.get(context['user']) # The authorized user.
Expand Down
15 changes: 15 additions & 0 deletions ckan/logic/action/update.py
Expand Up @@ -943,3 +943,18 @@ 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.
This will reset dashboard_new_activities_count to 0.
'''
_check_access('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)


7 changes: 0 additions & 7 deletions ckan/logic/auth/get.py
Expand Up @@ -206,10 +206,3 @@ def dashboard_new_activities_count(context, data_dict):
# directly, but wait until 2939-orgs is merged before fixing this.
return ckan.new_authz.is_authorized('dashboard_activity_list',
context, data_dict)


def dashboard_mark_all_new_activities_as_old(context, data_dict):
# FIXME: This should go through check_access() not call is_authorized()
# directly, but wait until 2939-orgs is merged before fixing this.
return ckan.new_authz.is_authorized('dashboard_activity_list',
context, data_dict)
2 changes: 1 addition & 1 deletion ckan/logic/auth/publisher/get.py
Expand Up @@ -8,7 +8,7 @@
from ckan.logic.auth.get import (
dashboard_new_activities_count,
dashboard_activity_list,
dashboard_mark_all_new_activities_as_old,
dashboard_mark_activities_old,
)

def site_read(context, data_dict):
Expand Down
9 changes: 9 additions & 0 deletions ckan/logic/auth/update.py
Expand Up @@ -5,6 +5,7 @@
from ckan.logic.auth.create import _check_group_auth, package_relationship_create
from ckan.authz import Authorizer
from ckan.lib.base import _
import ckan.new_authz

def make_latest_pending_package_active(context, data_dict):
return package_update(context, data_dict)
Expand Down Expand Up @@ -179,6 +180,14 @@ def term_translation_update(context, data_dict):
else:
return {'success': True}


def dashboard_mark_activities_old(context, data_dict):
# FIXME: This should go through check_access() not call is_authorized()
# directly, but wait until 2939-orgs is merged before fixing this.
return ckan.new_authz.is_authorized('dashboard_activity_list',
context, data_dict)


## Modifications for rest api

def package_update_rest(context, data_dict):
Expand Down
10 changes: 5 additions & 5 deletions ckan/tests/functional/api/test_dashboard.py
Expand Up @@ -79,8 +79,8 @@ def dashboard_new_activities(self, user):
activity_list = self.dashboard_activity_list(user)
return [activity for activity in activity_list if activity['is_new']]

def dashboard_mark_all_new_activities_as_old(self, user):
self.post('dashboard_mark_all_new_activities_as_old',
def dashboard_mark_activities_old(self, user):
self.post('dashboard_mark_activities_old',
apikey=user['apikey'])

def test_00_dashboard_activity_list_not_logged_in(self):
Expand All @@ -90,7 +90,7 @@ def test_00_dashboard_new_activities_count_not_logged_in(self):
self.post('dashboard_new_activities_count', status=403)

def test_00_dashboard_mark_new_activities_not_logged_in(self):
self.post('dashboard_mark_all_new_activities_as_old', status=403)
self.post('dashboard_mark_activities_old', status=403)

def test_01_new_activities_count_for_new_user(self):
'''Test that a newly registered user's new activities count is 0.'''
Expand All @@ -114,7 +114,7 @@ def test_02_own_activities_do_not_count_as_new(self):
# We would have to do this if, when you follow something, you only get
# the activities from that object since you started following it, and
# not all its past activities as well.
self.dashboard_mark_all_new_activities_as_old(self.new_user)
self.dashboard_mark_activities_old(self.new_user)

# Create a new dataset.
params = json.dumps({
Expand Down Expand Up @@ -199,7 +199,7 @@ def test_06_mark_new_activities_as_read(self):
her dashboard activity stream.'''
assert self.dashboard_new_activities_count(self.new_user) > 0
assert len(self.dashboard_new_activities(self.new_user)) > 0
self.dashboard_mark_all_new_activities_as_old(self.new_user)
self.dashboard_mark_activities_old(self.new_user)
assert self.dashboard_new_activities_count(self.new_user) == 0
assert len(self.dashboard_new_activities(self.new_user)) == 0

Expand Down

0 comments on commit 097cb91

Please sign in to comment.