From 5ef1ac6117b7aea46e7502ecd5ab3bef82b216e9 Mon Sep 17 00:00:00 2001 From: amercader Date: Tue, 3 Dec 2013 18:27:46 +0000 Subject: [PATCH 1/7] [#1358] Fix auth error on datapusher_hook When logged in as a non-sysadmin user, you always got an error like: Process completed but unable to post to result_url This was caused by calling task_status_update, which is sysadmin only on datapusher_hook without ignore_auth in the context. We can safely add it at this point because access has been already checked. Added some tests. --- ckanext/datapusher/logic/action.py | 1 + ckanext/datapusher/tests/test.py | 12 ++++++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/ckanext/datapusher/logic/action.py b/ckanext/datapusher/logic/action.py index 1872a1ef265..359fcb3d21f 100644 --- a/ckanext/datapusher/logic/action.py +++ b/ckanext/datapusher/logic/action.py @@ -153,6 +153,7 @@ def datapusher_hook(context, data_dict): task['state'] = status task['last_updated'] = str(datetime.datetime.now()) + context['ignore_auth'] = True p.toolkit.get_action('task_status_update')(context, task) diff --git a/ckanext/datapusher/tests/test.py b/ckanext/datapusher/tests/test.py index 2ec2df42d21..af7488736f6 100644 --- a/ckanext/datapusher/tests/test.py +++ b/ckanext/datapusher/tests/test.py @@ -138,7 +138,7 @@ def test_send_datapusher_creates_task(self): assert task['state'] == 'pending', task - def test_datapusher_hook(self): + def _call_datapusher_hook(self, user): package = model.Package.get('annakarenina') resource = package.resources[0] @@ -163,7 +163,7 @@ def test_datapusher_hook(self): } } postparams = '%s=1' % json.dumps(data) - auth = {'Authorization': str(self.sysadmin_user.apikey)} + auth = {'Authorization': str(user.apikey)} res = self.app.post('/api/action/datapusher_hook', params=postparams, extra_environ=auth, status=200) print res.body @@ -182,3 +182,11 @@ def test_datapusher_hook(self): task_type='datapusher', key='datapusher') assert task['state'] == 'success', task + + def test_datapusher_hook_sysadmin(self): + + self._call_datapusher_hook(self.sysadmin_user) + + def test_datapusher_hook_normal_user(self): + + self._call_datapusher_hook(self.normal_user) From 7f7d3ddded575646bcf43985f45c4c52b9fed658 Mon Sep 17 00:00:00 2001 From: amercader Date: Tue, 3 Dec 2013 18:28:57 +0000 Subject: [PATCH 2/7] [#1358] Show actual timestamp, translate string --- ckan/templates/package/resource_data.html | 10 +++++++--- doc/_themes/sphinx-theme-okfn | 2 +- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/ckan/templates/package/resource_data.html b/ckan/templates/package/resource_data.html index 05bd66fdfee..7a7c336e12e 100644 --- a/ckan/templates/package/resource_data.html +++ b/ckan/templates/package/resource_data.html @@ -36,7 +36,11 @@ {{ _('Last updated') }} - {{ h.time_ago_from_timestamp(status.last_updated) if status.status else _('Never') }} + {% if status.status %} + {{ h.time_ago_from_timestamp(status.last_updated) }} + {% else %} + {{ _('Never') }} + {% endif %} @@ -51,9 +55,9 @@

{{ _('Upload Log') }}

{{ item.message | urlize }}
- + {{ h.time_ago_from_timestamp(item.timestamp) }} - more info + {{ _('Details') }}

diff --git a/doc/_themes/sphinx-theme-okfn b/doc/_themes/sphinx-theme-okfn index 4628f26abf4..e2722286d64 160000 --- a/doc/_themes/sphinx-theme-okfn +++ b/doc/_themes/sphinx-theme-okfn @@ -1 +1 @@ -Subproject commit 4628f26abf401fdb63ec099384bff44a27dcda4c +Subproject commit e2722286d647df9e79c723aa469198cace34e36d From e7bc7ad89212b696b9a4be78414fde50eb46f291 Mon Sep 17 00:00:00 2001 From: amercader Date: Tue, 3 Dec 2013 18:37:33 +0000 Subject: [PATCH 3/7] [#1358] Make DataPusher statuses translatable --- ckan/templates/package/resource_data.html | 2 +- ckanext/datapusher/helpers.py | 15 +++++++++++++++ ckanext/datapusher/plugin.py | 4 +++- 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/ckan/templates/package/resource_data.html b/ckan/templates/package/resource_data.html index 7a7c336e12e..ee01c97ef78 100644 --- a/ckan/templates/package/resource_data.html +++ b/ckan/templates/package/resource_data.html @@ -32,7 +32,7 @@ {{ _('Status') }} - {{ status.status.capitalize() if status.status else _('Not Uploaded Yet') }} + {{ h.datapusher_status_description(status) }} {{ _('Last updated') }} diff --git a/ckanext/datapusher/helpers.py b/ckanext/datapusher/helpers.py index d5291425b28..11519e2e3ef 100644 --- a/ckanext/datapusher/helpers.py +++ b/ckanext/datapusher/helpers.py @@ -9,3 +9,18 @@ def datapusher_status(resource_id): return { 'status': 'unknown' } + +def datapusher_status_description(status): + _ = toolkit._ + + if status.get('status'): + captions = { + 'complete': _('Complete'), + 'pending': _('Pending'), + 'submitting': _('Submitting'), + 'error': _('Error'), + } + + return captions.get(status['status'], status['status'].capitalize()) + else: + return _('Not Uploaded Yet') diff --git a/ckanext/datapusher/plugin.py b/ckanext/datapusher/plugin.py index c53dd14790d..08b9a355f3e 100644 --- a/ckanext/datapusher/plugin.py +++ b/ckanext/datapusher/plugin.py @@ -128,4 +128,6 @@ def get_auth_functions(self): def get_helpers(self): return { - 'datapusher_status': helpers.datapusher_status} + 'datapusher_status': helpers.datapusher_status, + 'datapusher_status_description': helpers.datapusher_status_description, + } From b3f6c1b63c01b32a36c8a2350c5b1d7efd671fc0 Mon Sep 17 00:00:00 2001 From: amercader Date: Thu, 5 Dec 2013 11:45:53 +0000 Subject: [PATCH 4/7] [#1358] Tweak captions to make them clearer for users --- ckan/templates/package/resource_data.html | 2 +- ckan/templates/package/resource_edit_base.html | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ckan/templates/package/resource_data.html b/ckan/templates/package/resource_data.html index ee01c97ef78..531d9575c44 100644 --- a/ckan/templates/package/resource_data.html +++ b/ckan/templates/package/resource_data.html @@ -9,7 +9,7 @@
diff --git a/ckan/templates/package/resource_edit_base.html b/ckan/templates/package/resource_edit_base.html index 0682cbbf014..b4478caff4e 100644 --- a/ckan/templates/package/resource_edit_base.html +++ b/ckan/templates/package/resource_edit_base.html @@ -21,7 +21,7 @@ {% block content_primary_nav %} {{ h.build_nav_icon('resource_edit', _('Edit resource'), id=pkg.name, resource_id=res.id) }} {% if 'datapusher' in g.plugins %} - {{ h.build_nav_icon('resource_data', _('Resource Data'), id=pkg.name, resource_id=res.id) }} + {{ h.build_nav_icon('resource_data', _('Resource DataStore'), id=pkg.name, resource_id=res.id) }} {% endif %} {% endblock %} From e973268cb7caa58b63cecade1c607c769a9b26e4 Mon Sep 17 00:00:00 2001 From: amercader Date: Thu, 5 Dec 2013 12:07:39 +0000 Subject: [PATCH 5/7] [#1358] Change tab name --- ckan/templates/package/resource_edit_base.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ckan/templates/package/resource_edit_base.html b/ckan/templates/package/resource_edit_base.html index b4478caff4e..4ace42b6dea 100644 --- a/ckan/templates/package/resource_edit_base.html +++ b/ckan/templates/package/resource_edit_base.html @@ -21,7 +21,7 @@ {% block content_primary_nav %} {{ h.build_nav_icon('resource_edit', _('Edit resource'), id=pkg.name, resource_id=res.id) }} {% if 'datapusher' in g.plugins %} - {{ h.build_nav_icon('resource_data', _('Resource DataStore'), id=pkg.name, resource_id=res.id) }} + {{ h.build_nav_icon('resource_data', _('DataStore'), id=pkg.name, resource_id=res.id) }} {% endif %} {% endblock %} From 97ecce24b9a2d170b9899d01a391f7ebb030f587 Mon Sep 17 00:00:00 2001 From: amercader Date: Thu, 5 Dec 2013 13:19:14 +0000 Subject: [PATCH 6/7] [#1358] The joys of PEP8 --- ckanext/datapusher/helpers.py | 1 + ckanext/datapusher/plugin.py | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/ckanext/datapusher/helpers.py b/ckanext/datapusher/helpers.py index 11519e2e3ef..535e6d57635 100644 --- a/ckanext/datapusher/helpers.py +++ b/ckanext/datapusher/helpers.py @@ -10,6 +10,7 @@ def datapusher_status(resource_id): 'status': 'unknown' } + def datapusher_status_description(status): _ = toolkit._ diff --git a/ckanext/datapusher/plugin.py b/ckanext/datapusher/plugin.py index 08b9a355f3e..50c9cd864f5 100644 --- a/ckanext/datapusher/plugin.py +++ b/ckanext/datapusher/plugin.py @@ -129,5 +129,6 @@ def get_auth_functions(self): def get_helpers(self): return { 'datapusher_status': helpers.datapusher_status, - 'datapusher_status_description': helpers.datapusher_status_description, + 'datapusher_status_description': + helpers.datapusher_status_description, } From a691bd308199209eced83428fb3f177108f7ee1e Mon Sep 17 00:00:00 2001 From: amercader Date: Tue, 10 Dec 2013 11:16:10 +0000 Subject: [PATCH 7/7] [#1358] Revert docs theme to the version on master --- doc/_themes/sphinx-theme-okfn | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/_themes/sphinx-theme-okfn b/doc/_themes/sphinx-theme-okfn index e2722286d64..4628f26abf4 160000 --- a/doc/_themes/sphinx-theme-okfn +++ b/doc/_themes/sphinx-theme-okfn @@ -1 +1 @@ -Subproject commit e2722286d647df9e79c723aa469198cace34e36d +Subproject commit 4628f26abf401fdb63ec099384bff44a27dcda4c