2013-01-09 18:26:48 +01:00
|
|
|
from ckan.plugins import toolkit as pt
|
2013-01-28 17:31:11 +01:00
|
|
|
|
2013-01-09 18:26:48 +01:00
|
|
|
from ckanext.harvest.logic.auth import get_job_object
|
2012-03-01 13:02:16 +01:00
|
|
|
|
|
|
|
|
2014-01-20 14:47:37 +01:00
|
|
|
|
|
|
|
def auth_allow_anonymous_access(auth_function):
|
|
|
|
'''
|
|
|
|
Local version of the auth_allow_anonymous_access decorator that only
|
|
|
|
calls the actual toolkit decorator if the CKAN version supports it
|
|
|
|
'''
|
|
|
|
if pt.check_ckan_version(min_version='2.2'):
|
|
|
|
auth_function = pt.auth_allow_anonymous_access(auth_function)
|
|
|
|
|
|
|
|
return auth_function
|
|
|
|
|
|
|
|
|
|
|
|
@auth_allow_anonymous_access
|
2013-01-09 18:26:48 +01:00
|
|
|
def harvest_source_show(context, data_dict):
|
|
|
|
'''
|
|
|
|
Authorization check for getting the details of a harvest source
|
2012-03-01 13:02:16 +01:00
|
|
|
|
2013-01-09 18:26:48 +01:00
|
|
|
It forwards the checks to package_show, which will check for
|
|
|
|
organization membership, whether if sysadmin, etc according to the
|
|
|
|
instance configuration.
|
|
|
|
'''
|
|
|
|
model = context.get('model')
|
2012-03-01 13:02:16 +01:00
|
|
|
user = context.get('user')
|
2013-01-09 18:26:48 +01:00
|
|
|
source_id = data_dict['id']
|
|
|
|
|
|
|
|
pkg = model.Package.get(source_id)
|
|
|
|
if not pkg:
|
|
|
|
raise pt.ObjectNotFound(pt._('Harvest source not found'))
|
2012-03-01 13:02:16 +01:00
|
|
|
|
2013-01-09 18:26:48 +01:00
|
|
|
context['package'] = pkg
|
|
|
|
|
|
|
|
try:
|
|
|
|
pt.check_access('package_show', context, data_dict)
|
2012-03-01 13:02:16 +01:00
|
|
|
return {'success': True}
|
2013-01-16 13:56:58 +01:00
|
|
|
except pt.NotAuthorized:
|
2013-01-09 18:26:48 +01:00
|
|
|
return {'success': False,
|
2013-01-28 17:31:11 +01:00
|
|
|
'msg': pt._('User {0} not authorized to read harvest source {1}')
|
|
|
|
.format(user, source_id)}
|
2012-03-01 13:02:16 +01:00
|
|
|
|
2014-01-20 14:47:37 +01:00
|
|
|
@auth_allow_anonymous_access
|
2013-03-18 17:48:27 +01:00
|
|
|
def harvest_source_show_status(context, data_dict):
|
|
|
|
'''
|
|
|
|
Authorization check for getting the status of a harvest source
|
|
|
|
|
|
|
|
It forwards the checks to harvest_source_show.
|
|
|
|
'''
|
|
|
|
return harvest_source_show(context, data_dict)
|
2012-03-01 13:02:16 +01:00
|
|
|
|
2014-01-20 14:47:37 +01:00
|
|
|
@auth_allow_anonymous_access
|
2013-01-09 18:26:48 +01:00
|
|
|
def harvest_source_list(context, data_dict):
|
|
|
|
'''
|
|
|
|
Authorization check for getting a list of harveste sources
|
2012-03-01 13:02:16 +01:00
|
|
|
|
2013-01-09 18:26:48 +01:00
|
|
|
Everybody can do it
|
|
|
|
'''
|
|
|
|
return {'success': True}
|
2012-03-01 13:02:16 +01:00
|
|
|
|
|
|
|
|
2013-01-09 18:26:48 +01:00
|
|
|
def harvest_job_show(context, data_dict):
|
|
|
|
'''
|
|
|
|
Authorization check for getting the details of a harvest job
|
2012-03-01 13:02:16 +01:00
|
|
|
|
2013-01-28 17:31:11 +01:00
|
|
|
It forwards the checks to harvest_source_update, ie if the user can
|
|
|
|
update the parent source (eg create new jobs), she can get the details
|
|
|
|
for the job, including the reports
|
2013-01-09 18:26:48 +01:00
|
|
|
'''
|
2013-01-28 17:31:11 +01:00
|
|
|
user = context.get('user')
|
2013-01-09 18:26:48 +01:00
|
|
|
job = get_job_object(context, data_dict)
|
|
|
|
|
2013-01-28 17:31:11 +01:00
|
|
|
try:
|
|
|
|
pt.check_access('harvest_source_update',
|
|
|
|
context,
|
|
|
|
{'id': job.source.id})
|
|
|
|
return {'success': True}
|
|
|
|
except pt.NotAuthorized:
|
|
|
|
return {'success': False,
|
|
|
|
'msg': pt._('User {0} not authorized to see jobs from source {1}')
|
|
|
|
.format(user, job.source.id)}
|
2012-03-01 13:02:16 +01:00
|
|
|
|
2013-01-09 18:26:48 +01:00
|
|
|
|
|
|
|
def harvest_job_list(context, data_dict):
|
|
|
|
'''
|
|
|
|
Authorization check for getting a list of jobs for a source
|
|
|
|
|
2013-02-05 17:41:29 +01:00
|
|
|
It forwards the checks to harvest_source_update, ie if the user can
|
|
|
|
update the parent source (eg create new jobs), she can get the list of
|
|
|
|
jobs
|
2013-01-09 18:26:48 +01:00
|
|
|
'''
|
2013-02-05 17:41:29 +01:00
|
|
|
user = context.get('user')
|
2013-01-09 18:26:48 +01:00
|
|
|
source_id = data_dict['source_id']
|
2013-02-05 17:41:29 +01:00
|
|
|
|
|
|
|
try:
|
|
|
|
pt.check_access('harvest_source_update',
|
|
|
|
context,
|
|
|
|
{'id': source_id})
|
|
|
|
return {'success': True}
|
|
|
|
except pt.NotAuthorized:
|
|
|
|
return {'success': False,
|
|
|
|
'msg': pt._('User {0} not authorized to list jobs for source {1}')
|
|
|
|
.format(user, source_id)}
|
|
|
|
|
2013-01-09 18:26:48 +01:00
|
|
|
|
|
|
|
|
2014-01-20 14:47:37 +01:00
|
|
|
@auth_allow_anonymous_access
|
2013-01-09 18:26:48 +01:00
|
|
|
def harvest_object_show(context, data_dict):
|
|
|
|
'''
|
|
|
|
Authorization check for getting the contents of a harvest object
|
|
|
|
|
|
|
|
Everybody can do it
|
|
|
|
'''
|
2012-08-09 14:37:28 +02:00
|
|
|
return {'success': True}
|
2012-03-01 13:02:16 +01:00
|
|
|
|
|
|
|
|
2013-01-09 18:26:48 +01:00
|
|
|
def harvest_object_list(context, data_dict):
|
|
|
|
'''
|
|
|
|
TODO: remove
|
|
|
|
'''
|
|
|
|
return {'success': True}
|
2012-03-01 13:02:16 +01:00
|
|
|
|
|
|
|
|
2014-01-20 14:47:37 +01:00
|
|
|
@auth_allow_anonymous_access
|
2013-01-09 18:26:48 +01:00
|
|
|
def harvesters_info_show(context, data_dict):
|
|
|
|
'''
|
|
|
|
Authorization check for getting information about the available
|
|
|
|
harvesters
|
2012-03-01 13:02:16 +01:00
|
|
|
|
2013-01-09 18:26:48 +01:00
|
|
|
Everybody can do it
|
|
|
|
'''
|
|
|
|
return {'success': True}
|