Skip to content

Commit

Permalink
Merge branch 'master' into clean-config-from-jinja-templates
Browse files Browse the repository at this point in the history
  • Loading branch information
tobes committed Nov 21, 2012
2 parents 32a7e68 + 9ed808b commit a138945
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 25 deletions.
7 changes: 5 additions & 2 deletions ckan/logic/action/get.py
Expand Up @@ -1794,8 +1794,11 @@ def group_activity_list(context, data_dict):

# Get the group's activities.
query = model.Session.query(model.Activity)
query = query.filter(_or_(model.Activity.object_id == group_id,
model.Activity.object_id.in_(dataset_ids)))
if dataset_ids:
query = query.filter(_or_(model.Activity.object_id == group_id,
model.Activity.object_id.in_(dataset_ids)))
else:
query = query.filter(model.Activity.object_id == group_id)
query = query.order_by(_desc(model.Activity.timestamp))
query = query.limit(15)
activity_objects = query.all()
Expand Down
8 changes: 7 additions & 1 deletion ckan/logic/auth/get.py
Expand Up @@ -192,18 +192,24 @@ def get_site_user(context, data_dict):


def dashboard_activity_list(context, data_dict):
if 'user' in context:
# FIXME: context['user'] could be an IP address but that case is not
# handled here. Maybe add an auth helper function like is_logged_in().
if context.get('user'):
return {'success': True}
else:
return {'success': False,
'msg': _("You must be logged in to access your dashboard.")}


def dashboard_new_activities_count(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)


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)
55 changes: 33 additions & 22 deletions ckan/tests/functional/api/test_dashboard.py
Expand Up @@ -46,27 +46,32 @@ def setup_class(cls):
def teardown_class(cls):
ckan.model.repo.rebuild_db()

def post(self, action, params=None, apikey=None, status=200):
'''Post to the CKAN API and return the result.'''
if params is None:
params = {}
params = json.dumps(params)
response = self.app.post('/api/action/{0}'.format(action),
params=params,
extra_environ={'Authorization': str(apikey)},
status=status)
if status in (200,):
assert response.json['success'] is True
return response.json['result']
else:
assert response.json['success'] is False
return response.json['error']

def dashboard_new_activities_count(self, user):
'''Return the given user's new activities count from the CKAN API.'''
params = json.dumps({})
response = self.app.post('/api/action/dashboard_new_activities_count',
params=params,
extra_environ={'Authorization': str(user['apikey'])})
assert response.json['success'] is True
new_activities_count = response.json['result']
return new_activities_count
return self.post('dashboard_new_activities_count',
apikey=user['apikey'])

def dashboard_activity_list(self, user):
'''Return the given user's dashboard activity list from the CKAN API.
'''
params = json.dumps({})
response = self.app.post('/api/action/dashboard_activity_list',
params=params,
extra_environ={'Authorization': str(user['apikey'])})
assert response.json['success'] is True
activity_list = response.json['result']
return activity_list
return self.post('dashboard_activity_list', apikey=user['apikey'])

def dashboard_new_activities(self, user):
'''Return the activities from the user's dashboard activity stream
Expand All @@ -75,12 +80,17 @@ def dashboard_new_activities(self, user):
return [activity for activity in activity_list if activity['is_new']]

def dashboard_mark_all_new_activities_as_old(self, user):
params = json.dumps({})
response = self.app.post(
'/api/action/dashboard_mark_all_new_activities_as_old',
params=params,
extra_environ={'Authorization': str(user['apikey'])})
assert response.json['success'] is True
self.post('dashboard_mark_all_new_activities_as_old',
apikey=user['apikey'])

def test_00_dashboard_activity_list_not_logged_in(self):
self.post('dashboard_activity_list', status=403)

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)

def test_01_new_activities_count_for_new_user(self):
'''Test that a newly registered user's new activities count is 0.'''
Expand Down Expand Up @@ -196,10 +206,11 @@ def test_06_mark_new_activities_as_read(self):
def test_07_maximum_number_of_new_activities(self):
'''Test that the new activities count does not go higher than 15, even
if there are more than 15 new activities from the user's followers.'''
for n in range(0,20):
for n in range(0, 20):
notes = "Updated {n} times".format(n=n)
params = json.dumps({'name': 'warandpeace', 'notes': notes})
response = self.app.post('/api/action/package_update', params=params,
response = self.app.post('/api/action/package_update',
params=params,
extra_environ={'Authorization': str(self.joeadmin['apikey'])})
assert response.json['success'] is True
assert self.dashboard_new_activities_count(self.new_user) == 15
7 changes: 7 additions & 0 deletions doc/install-from-source.rst
Expand Up @@ -66,6 +66,13 @@ c. Install the Python modules that CKAN requires into your virtualenv::

pip install -r ~/pyenv/src/ckan/pip-requirements.txt

d. Deactivate and reactivate your virtualenv, to make sure you're using the
virtualenv's copies of commands like ``paster`` rather than any system-wide
installed copies::

deactivate
. ~/pyenv/bin/activate

3. Setup a PostgreSQL database
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Expand Down

0 comments on commit a138945

Please sign in to comment.