From aea845aaa03f605268970c776797befe26fde229 Mon Sep 17 00:00:00 2001 From: tobes Date: Fri, 31 May 2013 12:10:53 +0100 Subject: [PATCH 1/4] [#954] Add dataset button on org page fix --- ckan/logic/auth/create.py | 12 ++++++++---- ckan/templates/organization/read_base.html | 4 +++- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/ckan/logic/auth/create.py b/ckan/logic/auth/create.py index 1baf9b61077..ec1725d6858 100644 --- a/ckan/logic/auth/create.py +++ b/ckan/logic/auth/create.py @@ -14,12 +14,16 @@ def package_create(context, data_dict=None): if not check1: return {'success': False, 'msg': _('User %s not authorized to create packages') % user} - else: - check2 = _check_group_auth(context,data_dict) - if not check2: - return {'success': False, 'msg': _('User %s not authorized to edit these groups') % str(user)} + check2 = _check_group_auth(context,data_dict) + if not check2: + return {'success': False, 'msg': _('User %s not authorized to edit these groups') % user} + # If an organization is given are we able to add a dataset to it? + org_id = data_dict.get('organization_id') + if org_id and not new_authz.has_user_permission_for_group_or_org( + org_id, user, 'create_dataset'): + return {'success': False, 'msg': _('User %s not authorized to add dataset to this organization') % user} return {'success': True} def file_upload(context, data_dict=None): diff --git a/ckan/templates/organization/read_base.html b/ckan/templates/organization/read_base.html index 959d078d7e2..ae90169d12b 100644 --- a/ckan/templates/organization/read_base.html +++ b/ckan/templates/organization/read_base.html @@ -8,8 +8,10 @@ {% endblock %} {% block actions_content %} - {% if h.check_access('organization_update', {'id': c.group_dict.id}) %} + {% if h.check_access('package_create', {'organization_id': c.group_dict.id}) %}
  • {% link_for _('Add Dataset'), controller='package', action='new', group=c.group_dict.id, class_='btn', icon='plus-sign-alt' %}
  • + {% endif %} + {% if h.check_access('organization_update', {'id': c.group_dict.id}) %}
  • {% link_for _('Admin'), controller='organization', action='edit', id=c.group_dict.name, class_='btn btn-primary', icon='wrench' %}
  • {% endif %}
  • {{ h.follow_button('group', c.group_dict.id) }}
  • From a829e16484ee111a81637c092cdd5879f0722d5d Mon Sep 17 00:00:00 2001 From: tobes Date: Fri, 31 May 2013 12:36:09 +0100 Subject: [PATCH 2/4] [#954] Allow data_dict=None --- ckan/logic/auth/create.py | 1 + 1 file changed, 1 insertion(+) diff --git a/ckan/logic/auth/create.py b/ckan/logic/auth/create.py index ec1725d6858..92f5ecd2826 100644 --- a/ckan/logic/auth/create.py +++ b/ckan/logic/auth/create.py @@ -20,6 +20,7 @@ def package_create(context, data_dict=None): return {'success': False, 'msg': _('User %s not authorized to edit these groups') % user} # If an organization is given are we able to add a dataset to it? + data_dict = data_dict or {} org_id = data_dict.get('organization_id') if org_id and not new_authz.has_user_permission_for_group_or_org( org_id, user, 'create_dataset'): From 6f43c65fa9b318c7aebe3583076fd28cdb5a1a6a Mon Sep 17 00:00:00 2001 From: tobes Date: Fri, 31 May 2013 12:36:35 +0100 Subject: [PATCH 3/4] [#954] Coding standards remove file from blacklist --- ckan/tests/test_coding_standards.py | 1 - 1 file changed, 1 deletion(-) diff --git a/ckan/tests/test_coding_standards.py b/ckan/tests/test_coding_standards.py index 34bd996f9dd..2cce807998c 100644 --- a/ckan/tests/test_coding_standards.py +++ b/ckan/tests/test_coding_standards.py @@ -80,7 +80,6 @@ class TestNastyString(object): 'ckan/lib/activity_streams.py', 'ckan/logic/action/create.py', 'ckan/logic/action/update.py', - 'ckan/logic/auth/create.py', 'ckan/logic/auth/delete.py', 'ckan/logic/auth/get.py', 'ckan/logic/validators.py', From e414929022e4cdcedbc029b2f17a043f2074a580 Mon Sep 17 00:00:00 2001 From: tobes Date: Wed, 26 Jun 2013 10:58:42 +0100 Subject: [PATCH 4/4] Fix add dataset logic --- ckan/templates/organization/read.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ckan/templates/organization/read.html b/ckan/templates/organization/read.html index 25f7fcc94bd..33b035ce82b 100644 --- a/ckan/templates/organization/read.html +++ b/ckan/templates/organization/read.html @@ -1,7 +1,7 @@ {% extends "organization/read_base.html" %} {% block page_primary_action %} - {% if h.check_access('organization_update', {'id': c.group_dict.id}) %} + {% if h.check_access('package_create', {'organization_id': c.group_dict.id}) %} {% link_for _('Add Dataset'), controller='package', action='new', group=c.group_dict.id, class_='btn btn-primary', icon='plus-sign-alt' %} {% endif %} {% endblock %}