fix redirects and auths
This commit is contained in:
parent
568119bee5
commit
1ac5b93326
|
@ -3,45 +3,35 @@ import ckan.model as model
|
||||||
import ckan.logic as logic
|
import ckan.logic as logic
|
||||||
from ckan.lib.base import h
|
from ckan.lib.base import h
|
||||||
from ckan.controllers.package import PackageController
|
from ckan.controllers.package import PackageController
|
||||||
from ckan.common import request
|
from ckan.common import request, _
|
||||||
|
import ckan.lib.base as base
|
||||||
|
|
||||||
c = p.toolkit.c
|
c = p.toolkit.c
|
||||||
flatten_to_string_key = logic.flatten_to_string_key
|
flatten_to_string_key = logic.flatten_to_string_key
|
||||||
|
NotAuthorized = logic.NotAuthorized
|
||||||
|
abort = base.abort
|
||||||
|
|
||||||
class RatingController(p.toolkit.BaseController):
|
class RatingController(p.toolkit.BaseController):
|
||||||
|
|
||||||
def submit_package_rating(self, package, rating):
|
def submit_package_rating(self, package, rating):
|
||||||
context = {'model': model, 'user': c.user or c.author}
|
context = {'model': model, 'user': c.user or c.author}
|
||||||
data_dict = {'package': package, 'rating': rating}
|
data_dict = {'package': package, 'rating': rating}
|
||||||
if p.toolkit.check_access('check_access_user', context, data_dict):
|
try:
|
||||||
|
p.toolkit.check_access('check_access_user', context, data_dict)
|
||||||
p.toolkit.get_action('rating_package_create')(context, data_dict)
|
p.toolkit.get_action('rating_package_create')(context, data_dict)
|
||||||
h.redirect_to(str('/dataset/' + package))
|
h.redirect_to(controller='package', action='read', id=package)
|
||||||
return p.toolkit.render('package/read.html')
|
except NotAuthorized:
|
||||||
|
abort(403, _('Unauthenticated user not allowed to submit ratings.'))
|
||||||
|
|
||||||
def submit_showcase_rating(self, package, rating):
|
def submit_showcase_rating(self, package, rating):
|
||||||
context = {'model': model, 'user': c.user or c.author}
|
context = {'model': model, 'user': c.user or c.author}
|
||||||
data_dict = {'package': package, 'rating': rating}
|
data_dict = {'package': package, 'rating': rating}
|
||||||
if p.toolkit.check_access('check_access_user', context, data_dict):
|
|
||||||
p.toolkit.get_action('rating_package_create')(context, data_dict)
|
|
||||||
h.redirect_to(str('/showcase/' + package))
|
|
||||||
return p.toolkit.render('showcase/showcase_info.html')
|
|
||||||
|
|
||||||
def submit_ajax_package_rating(self, package, rating):
|
|
||||||
context = {'model': model, 'user': c.user or c.author}
|
|
||||||
data_dict = {'package': package, 'rating': rating}
|
|
||||||
if p.toolkit.check_access('check_access_user', context, data_dict):
|
|
||||||
try:
|
try:
|
||||||
p.toolkit.get_action('rating_package_create')(
|
p.toolkit.check_access('check_access_user', context, data_dict)
|
||||||
context, data_dict)
|
p.toolkit.get_action('rating_package_create')(context, data_dict)
|
||||||
except Exception, ex:
|
h.redirect_to(controller='ckanext.sixodp_showcase.controller:Sixodp_ShowcaseController', action='read', id=package)
|
||||||
errors = ex
|
except NotAuthorized:
|
||||||
else:
|
abort(403, _('Unauthenticated user not allowed to submit ratings.'))
|
||||||
data['success'] = True
|
|
||||||
|
|
||||||
data = flatten_to_string_key({'data': data, 'errors': errors}),
|
|
||||||
response.headers['Content-Type'] = 'application/json;charset=utf-8'
|
|
||||||
return h.json.dumps(data)
|
|
||||||
|
|
||||||
|
|
||||||
class RatingPackageController(PackageController):
|
class RatingPackageController(PackageController):
|
||||||
|
|
|
@ -16,5 +16,5 @@ def check_access_user(context, data_dict):
|
||||||
return {'success': True}
|
return {'success': True}
|
||||||
else:
|
else:
|
||||||
allow_rating = toolkit.asbool(
|
allow_rating = toolkit.asbool(
|
||||||
config.get('rating.enabled_for_unauthenticated_users', True))
|
config.get('ckanext.rating.enabled_for_unauthenticated_users', True))
|
||||||
return {'success': allow_rating}
|
return {'success': allow_rating}
|
||||||
|
|
Loading…
Reference in New Issue