Skip to content

Commit

Permalink
Merged master
Browse files Browse the repository at this point in the history
  • Loading branch information
johnmartin committed Jun 25, 2013
2 parents 1354683 + 3dedaa5 commit 53f1860
Show file tree
Hide file tree
Showing 147 changed files with 16,479 additions and 6,605 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.rst
Expand Up @@ -423,7 +423,7 @@ v1.5 2011-11-07
Major:
* New visual theme (#1108)
* Package & Resource edit overhaul (#1294/#1348/#1351/#1368/#1296)
* JS and CSS reorganisation (#1282, #1349, #1380)
* JS and CSS reorganization (#1282, #1349, #1380)
* Apache Solr used for search in core instead of Postgres (#1275, #1361, #1365)
* Authorization system now embedded in the logic layer (#1253)
* Captcha added for user registration (#1307, #1431)
Expand Down
1 change: 1 addition & 0 deletions bin/ckan_edit_local.py
Expand Up @@ -84,6 +84,7 @@ def canada_extras():
'Level of Government':'level_of_government',
}
license_mapping = {
# CS: bad_spelling ignore
'http://geogratis.ca/geogratis/en/licence.jsp':'geogratis',
'Crown Copyright':'canada-crown',
}
Expand Down
14 changes: 9 additions & 5 deletions ckan/controllers/api.py
Expand Up @@ -158,7 +158,7 @@ def action(self, logic_function, ver=None):
except KeyError:
log.error('Can\'t find logic function: %s' % logic_function)
return self._finish_bad_request(
_('Action name not known: %s') % str(logic_function))
_('Action name not known: %s') % logic_function)

context = {'model': model, 'session': model.Session, 'user': c.user,
'api_version': ver}
Expand All @@ -169,9 +169,9 @@ def action(self, logic_function, ver=None):
request_data = self._get_request_data(try_url_params=
side_effect_free)
except ValueError, inst:
log.error('Bad request data: %s' % str(inst))
log.error('Bad request data: %s' % inst)
return self._finish_bad_request(
_('JSON Error: %s') % str(inst))
_('JSON Error: %s') % inst)
if not isinstance(request_data, dict):
# this occurs if request_data is blank
log.error('Bad request data - not dict: %r' % request_data)
Expand Down Expand Up @@ -210,6 +210,7 @@ def action(self, logic_function, ver=None):
error_dict['__type'] = 'Validation Error'
return_dict['error'] = error_dict
return_dict['success'] = False
# CS nasty_string ignore
log.error('Validation error: %r' % str(e.error_dict))
return self._finish(409, return_dict, content_type='json')
except search.SearchQueryError, e:
Expand Down Expand Up @@ -334,7 +335,7 @@ def create(self, ver=None, register=None, subregister=None,
data_dict.update(request_data)
except ValueError, inst:
return self._finish_bad_request(
_('JSON Error: %s') % str(inst))
_('JSON Error: %s') % inst)

action = self._get_action_from_map(action_map, register, subregister)
if not action:
Expand All @@ -357,6 +358,7 @@ def create(self, ver=None, register=None, subregister=None,
extra_msg = e.extra_msg
return self._finish_not_found(extra_msg)
except ValidationError, e:
# CS: nasty_string ignore
log.error('Validation error: %r' % str(e.error_dict))
return self._finish(409, e.error_dict, content_type='json')
except DataError, e:
Expand Down Expand Up @@ -396,7 +398,7 @@ def update(self, ver=None, register=None, subregister=None,
data_dict.update(request_data)
except ValueError, inst:
return self._finish_bad_request(
_('JSON Error: %s') % str(inst))
_('JSON Error: %s') % inst)

action = self._get_action_from_map(action_map, register, subregister)
if not action:
Expand All @@ -412,6 +414,7 @@ def update(self, ver=None, register=None, subregister=None,
extra_msg = e.extra_msg
return self._finish_not_found(extra_msg)
except ValidationError, e:
# CS: nasty_string ignore
log.error('Validation error: %r' % str(e.error_dict))
return self._finish(409, e.error_dict, content_type='json')
except DataError, e:
Expand Down Expand Up @@ -459,6 +462,7 @@ def delete(self, ver=None, register=None, subregister=None,
extra_msg = e.extra_msg
return self._finish_not_found(extra_msg)
except ValidationError, e:
# CS: nasty_string ignore
log.error('Validation error: %r' % str(e.error_dict))
return self._finish(409, e.error_dict, content_type='json')

Expand Down
2 changes: 1 addition & 1 deletion ckan/controllers/group.py
Expand Up @@ -524,7 +524,7 @@ def _save_edit(self, id, context):
if id != group['name']:
self._force_reindex(group)

h.redirect_to('%s_read' % str(group['type']), id=group['name'])
h.redirect_to('%s_read' % group['type'], id=group['name'])
except NotAuthorized:
abort(401, _('Unauthorized to read group %s') % id)
except NotFound, e:
Expand Down
2 changes: 1 addition & 1 deletion ckan/lib/activity_streams.py
Expand Up @@ -256,7 +256,7 @@ def activity_list_to_html(context, activity_stream, extra_vars):

if not activity_type in activity_stream_string_functions:
raise NotImplementedError("No activity renderer for activity "
"type '%s'" % str(activity_type))
"type '%s'" % activity_type)

if activity_type in activity_stream_string_icons:
activity_icon = activity_stream_string_icons[activity_type]
Expand Down
6 changes: 6 additions & 0 deletions ckan/lib/base.py
Expand Up @@ -263,6 +263,12 @@ def _identify_user(self):
if not c.user:
self._identify_user_default()

# If we have a user but not the userobj let's get the userobj. This
# means that IAuthenticator extensions do not need to access the user
# model directly.
if c.user and not c.userobj:
c.userobj = model.User.by_name(c.user)

# general settings
if c.user:
c.author = c.user
Expand Down
7 changes: 6 additions & 1 deletion ckan/lib/helpers.py
Expand Up @@ -1464,7 +1464,12 @@ def format_resource_items(items):
continue
# size is treated specially as we want to show in MiB etc
if key == 'size':
value = formatters.localised_filesize(int(value))
try:
value = formatters.localised_filesize(int(value))
except ValueError:
# Sometimes values that can't be converted to ints can sneak
# into the db. In this case, just leave them as they are.
pass
elif isinstance(value, basestring):
# check if strings are actually datetime/number etc
if re.search(reg_ex_datetime, value):
Expand Down
5 changes: 4 additions & 1 deletion ckan/lib/i18n.py
Expand Up @@ -34,7 +34,10 @@ def _get_locales():
locale_order = config.get('ckan.locale_order', '').split()

locales = ['en']
i18n_path = os.path.dirname(ckan.i18n.__file__)
if config.get('ckan.i18n_directory'):
i18n_path = os.path.join(config.get('ckan.i18n_directory'), 'i18n')
else:
i18n_path = os.path.dirname(ckan.i18n.__file__)
locales += [l for l in os.listdir(i18n_path) if localedata.exists(l)]

assert locale_default in locales, \
Expand Down
1 change: 1 addition & 0 deletions ckan/lib/plugins.py
Expand Up @@ -192,6 +192,7 @@ def setup_template_variables(self, context, data_dict):
c.groups_available = authz_fn(context, data_dict)

c.licenses = [('', '')] + base.model.Package.get_license_options()
# CS: bad_spelling ignore 2 lines
c.licences = c.licenses
deprecate_context_item('licences', 'Use `c.licenses` instead')
c.is_sysadmin = ckan.new_authz.is_sysadmin(c.user)
Expand Down
8 changes: 4 additions & 4 deletions ckan/logic/action/create.py
Expand Up @@ -181,7 +181,7 @@ def package_create(context, data_dict):
context["package"] = pkg
## this is added so that the rest controller can make a new location
context["id"] = pkg.id
log.debug('Created object %s' % str(pkg.name))
log.debug('Created object %s' % pkg.name)

# Make sure that a user provided schema is not used on package_show
context.pop('schema', None)
Expand Down Expand Up @@ -575,7 +575,7 @@ def _group_or_org_create(context, data_dict, is_org=False):
}
logic.get_action('member_create')(member_create_context, member_dict)

log.debug('Created object %s' % str(group.name))
log.debug('Created object %s' % group.name)
return model_dictize.group_dictize(group, context)


Expand Down Expand Up @@ -822,7 +822,7 @@ def user_create(context, data_dict):

context['user_obj'] = user
context['id'] = user.id
log.debug('Created user %s' % str(user.name))
log.debug('Created user %s' % user.name)
return user_dict

## Modifications for rest api
Expand Down Expand Up @@ -888,7 +888,7 @@ def vocabulary_create(context, data_dict):
if not context.get('defer_commit'):
model.repo.commit()

log.debug('Created Vocabulary %s' % str(vocabulary.name))
log.debug('Created Vocabulary %s' % vocabulary.name)

return model_dictize.vocabulary_dictize(vocabulary, context)

Expand Down
5 changes: 4 additions & 1 deletion ckan/logic/action/get.py
Expand Up @@ -639,7 +639,7 @@ def user_list(context, data_dict):
)

if q:
query = model.User.search(q, query)
query = model.User.search(q, query, user_name=context.get('user'))

if order_by == 'edits':
query = query.order_by(_desc(
Expand Down Expand Up @@ -982,6 +982,9 @@ def user_show(context, data_dict):

user_dict = model_dictize.user_dictize(user_obj,context)

if context.get('return_minimal'):
return user_dict

revisions_q = model.Session.query(model.Revision
).filter_by(author=user_obj.name)

Expand Down
9 changes: 4 additions & 5 deletions ckan/logic/action/update.py
Expand Up @@ -321,7 +321,7 @@ def package_update(context, data_dict):
if not context.get('defer_commit'):
model.repo.commit()

log.debug('Updated object %s' % str(pkg.name))
log.debug('Updated object %s' % pkg.name)

return_id_only = context.get('return_id_only', False)

Expand Down Expand Up @@ -764,11 +764,10 @@ def term_translation_update_many(context, data_dict):
'''
model = context['model']


if not data_dict.get('data') and isinstance(data_dict, list):
if not (data_dict.get('data') and isinstance(data_dict.get('data'), list)):
raise ValidationError(
{'error':
'term_translation_update_many needs to have a list of dicts in field data'}
{'error': 'term_translation_update_many needs to have a '
'list of dicts in field data'}
)

context['defer_commit'] = True
Expand Down
2 changes: 1 addition & 1 deletion ckan/logic/auth/create.py
Expand Up @@ -18,7 +18,7 @@ def package_create(context, data_dict=None):

check2 = _check_group_auth(context,data_dict)
if not check2:
return {'success': False, 'msg': _('User %s not authorized to edit these groups') % str(user)}
return {'success': False, 'msg': _('User %s not authorized to edit these groups') % user}

return {'success': True}

Expand Down
6 changes: 3 additions & 3 deletions ckan/logic/auth/delete.py
Expand Up @@ -10,7 +10,7 @@ def package_delete(context, data_dict):

authorized = new_authz.has_user_permission_for_group_or_org(package.owner_org, user, 'delete_dataset')
if not authorized:
return {'success': False, 'msg': _('User %s not authorized to delete package %s') % (str(user),package.id)}
return {'success': False, 'msg': _('User %s not authorized to delete package %s') % (user, package.id)}
else:
return {'success': True}

Expand All @@ -32,7 +32,7 @@ def resource_delete(context, data_dict):
authorized = package_delete(context, pkg_dict).get('success')

if not authorized:
return {'success': False, 'msg': _('User %s not authorized to delete resource %s') % (str(user), resource.id)}
return {'success': False, 'msg': _('User %s not authorized to delete resource %s') % (user, resource.id)}
else:
return {'success': True}

Expand Down Expand Up @@ -122,7 +122,7 @@ def _group_or_org_member_delete(context, data_dict):
authorized = new_authz.has_user_permission_for_group_or_org(
group.id, user, 'delete_member')
if not authorized:
return {'success': False, 'msg': _('User %s not authorized to delete organization %s members') % (str(user),group.id)}
return {'success': False, 'msg': _('User %s not authorized to delete organization %s members') % (user, group.id)}
else:
return {'success': True}
return {'success': True}
Expand Down
2 changes: 1 addition & 1 deletion ckan/logic/auth/get.py
Expand Up @@ -133,7 +133,7 @@ def resource_show(context, data_dict):
authorized = package_show(context, pkg_dict).get('success')

if not authorized:
return {'success': False, 'msg': _('User %s not authorized to read resource %s') % (str(user), resource.id)}
return {'success': False, 'msg': _('User %s not authorized to read resource %s') % (user, resource.id)}
else:
return {'success': True}

Expand Down
2 changes: 2 additions & 0 deletions ckan/logic/schema.py
Expand Up @@ -21,6 +21,7 @@
duplicate_extras_key,
ignore_not_package_admin,
ignore_not_group_admin,
ignore_not_sysadmin,
no_http,
tag_not_uppercase,
user_name_validator,
Expand Down Expand Up @@ -384,6 +385,7 @@ def default_user_schema():
'about': [ignore_missing, user_about_validator, unicode],
'created': [ignore],
'openid': [ignore_missing],
'sysadmin': [ignore_missing, ignore_not_sysadmin],
'apikey': [ignore],
'reset_key': [ignore],
'activity_streams_email_notifications': [ignore_missing],
Expand Down
17 changes: 15 additions & 2 deletions ckan/logic/validators.py
Expand Up @@ -110,7 +110,7 @@ def package_name_exists(value, context):
result = session.query(model.Package).filter_by(name=value).first()

if not result:
raise Invalid(_('Not found') + ': %r' % str(value))
raise Invalid(_('Not found') + ': %s' % value)
return value

def package_id_or_name_exists(package_id_or_name, context):
Expand Down Expand Up @@ -267,7 +267,7 @@ def object_id_validator(key, activity_dict, errors, context):
return object_id_validators[activity_type](object_id, context)
else:
raise Invalid('There is no object_id validator for '
'activity type "%s"' % str(activity_type))
'activity type "%s"' % activity_type)

def extras_unicode_convert(extras, context):
for extra in extras:
Expand Down Expand Up @@ -437,6 +437,19 @@ def ignore_not_package_admin(key, data, errors, context):
return
data.pop(key)


def ignore_not_sysadmin(key, data, errors, context):
'''Ignore the field if user not sysadmin or ignore_auth in context.'''

user = context.get('user')
ignore_auth = context.get('ignore_auth')

if ignore_auth or (user and new_authz.is_sysadmin(user)):
return

data.pop(key)


def ignore_not_group_admin(key, data, errors, context):
'''Ignore if the user is not allowed to administer for the group specified.'''

Expand Down
4 changes: 3 additions & 1 deletion ckan/model/license.py
Expand Up @@ -184,7 +184,7 @@ class LicenseOpenDataCommonsPDDL(DefaultLicense):

@property
def title(self):
return _("Open Data Commons Public Domain Dedication and Licence (PDDL)")
return _("Open Data Commons Public Domain Dedication and License (PDDL)")

class LicenseOpenDataCommonsOpenDatabase(DefaultLicense):
domain_data = True
Expand Down Expand Up @@ -279,10 +279,12 @@ class LicenseOpenGovernment(DefaultLicense):
domain_content = True
id = "uk-ogl"
is_okd_compliant = True
# CS: bad_spelling ignore
url = "http://reference.data.gov.uk/id/open-government-licence"

@property
def title(self):
# CS: bad_spelling ignore
return _("UK Open Government Licence (OGL)")

class LicenseCreativeCommonsNonCommercial(DefaultLicense):
Expand Down
16 changes: 11 additions & 5 deletions ckan/model/user.py
Expand Up @@ -199,18 +199,24 @@ def get_groups(self, group_type=None, capacity=None):
return groups

@classmethod
def search(cls, querystr, sqlalchemy_query=None):
def search(cls, querystr, sqlalchemy_query=None, user_name=None):
'''Search name, fullname, email and openid. '''
if sqlalchemy_query is None:
query = meta.Session.query(cls)
else:
query = sqlalchemy_query
qstr = '%' + querystr + '%'
query = query.filter(or_(
filters = [
cls.name.ilike(qstr),
cls.fullname.ilike(qstr), cls.openid.ilike(qstr),
cls.email.ilike(qstr)
))
cls.fullname.ilike(qstr),
cls.openid.ilike(qstr),
]
# sysadmins can search on user emails
import ckan.new_authz as new_authz
if user_name and new_authz.is_sysadmin(user_name):
filters.append(cls.email.ilike(qstr))

query = query.filter(or_(*filters))
return query

meta.mapper(User, user_table,
Expand Down
1 change: 1 addition & 0 deletions ckan/new_authz.py
Expand Up @@ -23,6 +23,7 @@ def clear_auth_functions_cache():
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)


Expand Down

0 comments on commit 53f1860

Please sign in to comment.