2013-01-09 18:26:48 +01:00
|
|
|
from ckan.plugins import toolkit as pt
|
|
|
|
from ckanext.harvest.logic.auth import user_is_sysadmin
|
2012-03-01 13:02:16 +01:00
|
|
|
|
2013-01-09 18:26:48 +01:00
|
|
|
|
|
|
|
def harvest_source_update(context, data_dict):
|
|
|
|
'''
|
|
|
|
Authorization check for harvest source update
|
|
|
|
|
|
|
|
It forwards the checks to package_update, 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']
|
2012-03-01 13:02:16 +01:00
|
|
|
|
2013-01-09 18:26:48 +01:00
|
|
|
pkg = model.Package.get(source_id)
|
|
|
|
if not pkg:
|
|
|
|
raise pt.ObjectNotFound(pt._('Harvest source not found'))
|
|
|
|
|
|
|
|
context['package'] = pkg
|
|
|
|
|
|
|
|
try:
|
|
|
|
pt.check_access('package_update', 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,
|
|
|
|
'msg': pt._('User {0} not authorized to update harvest source {1}').format(user, source_id)}
|
2012-03-01 13:02:16 +01:00
|
|
|
|
2013-03-25 12:39:00 +01:00
|
|
|
def harvest_source_clear(context, data_dict):
|
2013-05-16 18:57:59 +02:00
|
|
|
'''
|
|
|
|
Authorization check for clearing a harvest source
|
|
|
|
|
|
|
|
It forwards to harvest_source_update
|
|
|
|
'''
|
|
|
|
return harvest_source_update(context, data_dict)
|
2012-03-01 13:02:16 +01:00
|
|
|
|
2013-01-09 18:26:48 +01:00
|
|
|
def harvest_objects_import(context, data_dict):
|
|
|
|
'''
|
|
|
|
Authorization check reimporting all harvest objects
|
|
|
|
|
|
|
|
Only sysadmins can do it
|
|
|
|
'''
|
|
|
|
if not user_is_sysadmin(context):
|
|
|
|
return {'success': False, 'msg': pt._('Only sysadmins can reimport all harvest objects')}
|
2012-03-01 13:02:16 +01:00
|
|
|
else:
|
|
|
|
return {'success': True}
|
|
|
|
|
|
|
|
|
2013-01-09 18:26:48 +01:00
|
|
|
def harvest_jobs_run(context, data_dict):
|
|
|
|
'''
|
|
|
|
Authorization check for running the pending harvest jobs
|
|
|
|
|
|
|
|
Only sysadmins can do it
|
|
|
|
'''
|
|
|
|
if not user_is_sysadmin(context):
|
|
|
|
return {'success': False, 'msg': pt._('Only sysadmins can run the pending harvest jobs')}
|
2012-03-01 13:02:16 +01:00
|
|
|
else:
|
|
|
|
return {'success': True}
|
2013-01-22 17:43:25 +01:00
|
|
|
|
|
|
|
def harvest_sources_reindex(context, data_dict):
|
|
|
|
'''
|
|
|
|
Authorization check for reindexing all harvest sources
|
|
|
|
|
|
|
|
Only sysadmins can do it
|
|
|
|
'''
|
|
|
|
if not user_is_sysadmin(context):
|
|
|
|
return {'success': False, 'msg': pt._('Only sysadmins can reindex all harvest sources')}
|
|
|
|
else:
|
|
|
|
return {'success': True}
|