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_create(context, data_dict):
|
|
|
|
'''
|
|
|
|
Authorization check for harvest source creation
|
|
|
|
|
|
|
|
It forwards the checks to package_create, which will check for
|
|
|
|
organization membership, whether if sysadmin, etc according to the
|
|
|
|
instance configuration.
|
|
|
|
'''
|
2012-03-01 13:02:16 +01:00
|
|
|
user = context.get('user')
|
2013-01-09 18:26:48 +01:00
|
|
|
try:
|
|
|
|
pt.check_access('package_create', context, data_dict)
|
2012-03-01 13:02:16 +01:00
|
|
|
return {'success': True}
|
2013-01-09 18:26:48 +01:00
|
|
|
except pt.Not_Authorized:
|
|
|
|
return {'success': False,
|
|
|
|
'msg': pt._('User {0} not authorized to create harvest sources').format(user)}
|
2012-03-01 13:02:16 +01:00
|
|
|
|
2012-12-20 17:09:26 +01:00
|
|
|
|
2013-01-09 18:26:48 +01:00
|
|
|
def harvest_job_create(context, data_dict):
|
|
|
|
'''
|
|
|
|
Authorization check for harvest job creation
|
|
|
|
|
|
|
|
It forwards the checks to package_update, ie the user can only create
|
|
|
|
new jobs if she is allowed to edit the harvest source dataset.
|
|
|
|
'''
|
2012-03-01 13:02:16 +01:00
|
|
|
model = context['model']
|
2013-01-09 18:26:48 +01:00
|
|
|
source_id = data_dict['source_id']
|
|
|
|
|
|
|
|
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-09 18:26:48 +01:00
|
|
|
except pt.Not_Authorized:
|
|
|
|
return {'success': False,
|
|
|
|
'msg': pt._('User not authorized to create a job for source {0}').format(source_id)}
|
2012-03-01 13:02:16 +01:00
|
|
|
|
2012-12-20 17:09:26 +01:00
|
|
|
|
2013-01-09 18:26:48 +01:00
|
|
|
def harvest_job_create_all(context, data_dict):
|
|
|
|
'''
|
|
|
|
Authorization check for creating new jobs for all sources
|
|
|
|
|
|
|
|
Only sysadmins can do it
|
|
|
|
'''
|
|
|
|
if not user_is_sysadmin(context):
|
|
|
|
return {'success': False, 'msg': pt._('Only sysadmins can create harvest jobs for all sources')}
|
2012-03-01 13:02:16 +01:00
|
|
|
else:
|
|
|
|
return {'success': True}
|