Skip to content

Commit

Permalink
Merge branch '1641-resource-create-requires-url'
Browse files Browse the repository at this point in the history
  • Loading branch information
Sean Hammond committed Apr 28, 2014
2 parents 84536aa + 0b1bb78 commit bf3b4d7
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 28 deletions.
5 changes: 0 additions & 5 deletions ckan/logic/__init__.py
Expand Up @@ -259,7 +259,6 @@ def check_access(action, context, data_dict=None):
authorized to call the named action
'''
action = new_authz.clean_action_name(action)

# Auth Auditing. We remove this call from the __auth_audit stack to show
# we have called the auth function
Expand Down Expand Up @@ -341,8 +340,6 @@ def get_action(action):
:rtype: callable
'''
# clean the action names
action = new_authz.clean_action_name(action)

if _actions:
if not action in _actions:
Expand All @@ -365,7 +362,6 @@ def get_action(action):
if (hasattr(v, '__call__')
and (v.__module__ == module_path
or hasattr(v, '__replaced'))):
k = new_authz.clean_action_name(k)
_actions[k] = v

# Whitelist all actions defined in logic/action/get.py as
Expand All @@ -380,7 +376,6 @@ def get_action(action):
fetched_actions = {}
for plugin in p.PluginImplementations(p.IActions):
for name, auth_function in plugin.get_actions().items():
name = new_authz.clean_action_name(name)
if name in resolved_action_plugins:
raise Exception(
'The action %r is already implemented in %r' % (
Expand Down
6 changes: 3 additions & 3 deletions ckan/logic/action/create.py
Expand Up @@ -214,13 +214,12 @@ def package_create(context, data_dict):
def resource_create(context, data_dict):
'''Appends a new resource to a datasets list of resources.
:param package_id: id of package that the resource needs
should be added to.
:param package_id: id of package that the resource should be added to.
:type package_id: string
:param url: url of resource
:type url: string
:param revision_id: (optional)
:type revisiion_id: string
:type revision_id: string
:param description: (optional)
:type description: string
:param format: (optional)
Expand Down Expand Up @@ -261,6 +260,7 @@ def resource_create(context, data_dict):

package_id = _get_or_bust(data_dict, 'package_id')
data_dict.pop('package_id')
_get_or_bust(data_dict, 'url')

pkg_dict = _get_action('package_show')(context, {'id': package_id})

Expand Down
10 changes: 0 additions & 10 deletions ckan/new_authz.py
Expand Up @@ -57,7 +57,6 @@ def _build(self):

for key, v in module.__dict__.items():
if not key.startswith('_'):
key = clean_action_name(key)
# Whitelist all auth functions defined in
# logic/auth/get.py as not requiring an authorized user,
# as well as ensuring that the rest do. In both cases, do
Expand All @@ -75,7 +74,6 @@ def _build(self):
fetched_auth_functions = {}
for plugin in p.PluginImplementations(p.IAuthFunctions):
for name, auth_function in plugin.get_auth_functions().items():
name = clean_action_name(name)
if name in resolved_auth_function_plugins:
raise Exception(
'The auth function %r is already implemented in %r' % (
Expand Down Expand Up @@ -106,13 +104,6 @@ def auth_functions_list():
return _AuthFunctions.keys()


def clean_action_name(action_name):
''' Used to convert old style action names into new style ones '''
new_action_name = re.sub('package', 'dataset', action_name)
# CS: bad_spelling ignore
return re.sub('licence', 'license', new_action_name)


def is_sysadmin(username):
''' Returns True is username is a sysadmin '''
user = _get_user(username)
Expand Down Expand Up @@ -157,7 +148,6 @@ def is_authorized(action, context, data_dict=None):
if context.get('ignore_auth'):
return {'success': True}

action = clean_action_name(action)
auth_function = _AuthFunctions.get(action)
if auth_function:
username = context.get('user')
Expand Down
33 changes: 27 additions & 6 deletions ckan/new_tests/logic/action/test_create.py
Expand Up @@ -7,8 +7,8 @@

import ckan.new_tests.helpers as helpers
import ckan.new_tests.factories as factories
import ckan.model
import ckan.logic
import ckan.model as model
import ckan.logic as logic


class TestUserInvite(object):
Expand Down Expand Up @@ -56,17 +56,17 @@ def test_user_invite_works_even_if_username_already_exists(self, rand, _):
assert invited_user is not None, invited_user

@mock.patch('ckan.lib.mailer.send_invite')
@nose.tools.raises(ckan.logic.ValidationError)
@nose.tools.raises(logic.ValidationError)
def test_user_invite_requires_email(self, _):
self._invite_user_to_group(email=None)

@mock.patch('ckan.lib.mailer.send_invite')
@nose.tools.raises(ckan.logic.ValidationError)
@nose.tools.raises(logic.ValidationError)
def test_user_invite_requires_role(self, _):
self._invite_user_to_group(role=None)

@mock.patch('ckan.lib.mailer.send_invite')
@nose.tools.raises(ckan.logic.ValidationError)
@nose.tools.raises(logic.ValidationError)
def test_user_invite_requires_group_id(self, _):
self._invite_user_to_group(group={'id': None})

Expand All @@ -86,4 +86,25 @@ def _invite_user_to_group(self, email='user@email.com',

result = helpers.call_action('user_invite', context, **params)

return ckan.model.User.get(result['id'])
return model.User.get(result['id'])


class TestResourceCreate(object):

@classmethod
def setup_class(cls):
helpers.reset_db()

def setup(self):
model.repo.rebuild_db()

def test_it_requires_url(self):
user = factories.User()
dataset = factories.Dataset(user=user)
data_dict = {
'package_id': dataset['id']
}

nose.tools.assert_raises(logic.ValidationError,
helpers.call_action,
'resource_create', **data_dict)
1 change: 1 addition & 0 deletions ckan/public/base/less/layout.less
Expand Up @@ -109,6 +109,7 @@
margin: 0 0 5px 0;
font-size: 18px;
line-height: 1.3;
.break-word();
}
.info {
margin-top: 15px;
Expand Down
1 change: 1 addition & 0 deletions ckan/public/base/less/media.less
Expand Up @@ -90,6 +90,7 @@
font-size: 18px;
line-height: 1.3;
margin: 5px 0;
.break-word();
}

// Overlay
Expand Down
13 changes: 13 additions & 0 deletions ckan/public/base/less/mixins.less
@@ -1,3 +1,16 @@
.break-word {
-ms-word-break: break-all;
word-break: break-all;

/* Non standard for webkit */
word-break: break-word;

-webkit-hyphens: auto;
-moz-hyphens: auto;
-ms-hyphens: auto;
hyphens: auto;
}

.transform (@func) {
-webkit-transform: @arguments;
-moz-transform: @arguments;
Expand Down
2 changes: 1 addition & 1 deletion doc/contributing/pull-requests.rst
Expand Up @@ -64,7 +64,7 @@ This section will walk you through the steps for making a pull request.

- Your branch should contain new or changed tests for any new or changed
code, and all the CKAN tests should pass on your branch, see
`Testing CKAN <http://docs.ckan.org/en/latest/test.html>`_.
:doc:`test`.

- Your branch should contain new or updated documentation for any new or
updated code, see :doc:`documentation`.
Expand Down
4 changes: 1 addition & 3 deletions doc/contributing/test.rst
Expand Up @@ -71,8 +71,6 @@ option::

nosetests --ckan --reset-db --with-pylons=test-core.ini ckan

If you are have the ``ckan-migration`` option on the tests will reset the
reset the database before the test run.


.. _migrationtesting:
Expand All @@ -84,7 +82,7 @@ Migration testing
If you're a CKAN developer or extension developer and your new code requires a
change to CKAN's model, you'll need to write a migration script. To ensure that
the migration script itself gets tested, you should run the tests with
they ``--ckan-migration`` option, for example::
the ``--ckan-migration`` option, for example::

nosetests --ckan --ckan-migration --with-pylons=test-core.ini ckan ckanext

Expand Down

0 comments on commit bf3b4d7

Please sign in to comment.