Skip to content

Commit

Permalink
Merge branch 'master' of github.com:okfn/ckan into feature-1515-activ…
Browse files Browse the repository at this point in the history
…ity-streams

Conflicts:
	ckan/controllers/user.py
	ckan/logic/action/get.py
	ckan/templates/user/read.html
  • Loading branch information
Sean Hammond committed Feb 5, 2012
2 parents 7f0c3d9 + f93a103 commit 622a220
Show file tree
Hide file tree
Showing 27 changed files with 764 additions and 300 deletions.
11 changes: 10 additions & 1 deletion ckan/controllers/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from ckan.lib.navl.dictization_functions import DataError
from ckan.lib.munge import munge_name, munge_title_to_name, munge_tag
from ckan.logic import get_action, check_access
from ckan.logic import NotFound, NotAuthorized, ValidationError
from ckan.logic import NotFound, NotAuthorized, ValidationError, ParameterError
from ckan.lib.jsonp import jsonpify
from ckan.forms.common import package_exists, group_exists

Expand Down Expand Up @@ -173,6 +173,8 @@ def action(self, logic_function):
except NotFound:
return_dict['error'] = {'__type': 'Not Found Error',
'message': _('Not found')}
if e.extra_msg:
return_dict['error']['message'] += ': %s' % e.extra_msg
return_dict['success'] = False
return self._finish(404, return_dict, content_type='json')
except ValidationError, e:
Expand All @@ -182,6 +184,13 @@ def action(self, logic_function):
return_dict['success'] = False
log.error('Validation error: %r' % str(e.error_dict))
return self._finish(409, return_dict, content_type='json')
except ParameterError, e:
return_dict['error'] = {'__type': 'Parameter Error',
'message': '%s: %s' % \
(_('Parameter Error'), e.extra_msg)}
return_dict['success'] = False
log.error('Parameter error: %r' % e.extra_msg)
return self._finish(409, return_dict, content_type='json')
except SearchQueryError, e:
return_dict['error'] = {'__type': 'Search Query Error',
'message': 'Search Query is invalid: %r' % e.args }
Expand Down
16 changes: 2 additions & 14 deletions ckan/controllers/authorization_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,23 +157,11 @@ def authz(self, id):
if not c.authz_editable:
abort(401, gettext('User %r not authorized to edit %s authorizations') % (c.user, id))

current_uors = self._get_userobjectroles(id)
self._handle_update_of_authz(current_uors, authorization_group)

# get the roles again as may have changed
user_object_roles = self._get_userobjectroles(id)
self._prepare_authz_info_for_render(user_object_roles)
roles = self._handle_update_of_authz(authorization_group)
self._prepare_authz_info_for_render(roles)
return render('authorization_group/authz.html')


def _get_userobjectroles(self, authzgroup_name_or_id):
authorization_group = model.AuthorizationGroup.by_name(authzgroup_name_or_id) or\
model.Session.query(model.AuthorizationGroup).get(authzgroup_name_or_id)
uors = model.Session.query(model.AuthorizationGroupRole).join('authorization_group').\
filter_by(id=authorization_group.id).all()
return uors


def _render_edit_form(self, fs):
# errors arrive in c.error and fs.errors
c.fieldset = fs
Expand Down
14 changes: 2 additions & 12 deletions ckan/controllers/group.py
Original file line number Diff line number Diff line change
Expand Up @@ -467,21 +467,11 @@ def authz(self, id):
if not c.authz_editable:
abort(401, gettext('User %r not authorized to edit %s authorizations') % (c.user, id))

current_uors = self._get_userobjectroles(id)
self._handle_update_of_authz(current_uors, group)

# get the roles again as may have changed
user_object_roles = self._get_userobjectroles(id)
self._prepare_authz_info_for_render(user_object_roles)
roles = self._handle_update_of_authz(group)
self._prepare_authz_info_for_render(roles)
return render('group/authz.html')


def _get_userobjectroles(self, group_id):
group = model.Group.get(group_id)
uors = model.Session.query(model.GroupRole).join('group').filter_by(name=group.name).all()
return uors


def history(self, id):
if 'diff' in request.params or 'selected1' in request.params:
try:
Expand Down
16 changes: 2 additions & 14 deletions ckan/controllers/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ def _lookup_plugin(package_type):
If the package type is None or cannot be found in the mapping, then the
fallback behaviour is used.
"""
#from pdb import set_trace; set_trace()
if package_type is None:
return _default_controller_behaviour
return _controller_behaviour_for.get(package_type,
Expand Down Expand Up @@ -706,21 +705,10 @@ def authz(self, id):
if not c.authz_editable:
abort(401, gettext('User %r not authorized to edit %s authorizations') % (c.user, id))

current_uors = self._get_userobjectroles(id)
self._handle_update_of_authz(current_uors, pkg)

# get the roles again as may have changed
user_object_roles = self._get_userobjectroles(id)
self._prepare_authz_info_for_render(user_object_roles)
roles = self._handle_update_of_authz(pkg)
self._prepare_authz_info_for_render(roles)
return render('package/authz.html')


def _get_userobjectroles(self, pkg_id):
pkg = model.Package.get(pkg_id)
uors = model.Session.query(model.PackageRole).join('package').filter_by(name=pkg.name).all()
return uors


def autocomplete(self):
# DEPRECATED in favour of /api/2/util/dataset/autocomplete
q = unicode(request.params.get('q', ''))
Expand Down
6 changes: 2 additions & 4 deletions ckan/controllers/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,10 @@ def index(self):
return render('user/list.html')

def read(self, id=None):

context = {'model': model,
'user': c.user or c.author}

data_dict = {'id':id,
'user_obj':c.userobj}

try:
check_access('user_show',context, data_dict)
except NotAuthorized:
Expand All @@ -107,8 +104,9 @@ def read(self, id=None):
c.user_activity_stream = user_activity_list_html(context,
{'id':c.user_dict['id']})

c.created_formatted = h.date_str_to_datetime(user_dict['created']).strftime('%b %d, %Y')
return render('user/read.html')

def me(self):
if not c.user:
h.redirect_to(controller='user', action='login', id=None)
Expand Down

0 comments on commit 622a220

Please sign in to comment.