Merge pull request #213 from ckan/212-module-import-error
[#212] Fixes #212 - auth for harvest_job_create was broken.
This commit is contained in:
commit
4ca4b3a2f2
|
@ -76,8 +76,8 @@ def harvest_job_create(context, data_dict):
|
||||||
Creates a Harvest Job for a Harvest Source and runs it (by putting it on
|
Creates a Harvest Job for a Harvest Source and runs it (by putting it on
|
||||||
the gather queue)
|
the gather queue)
|
||||||
|
|
||||||
:param source_id:
|
:param source_id: id of the harvest source to create a job for
|
||||||
:type param: string
|
:type source_id: string
|
||||||
:param run: whether to also run it or not (default: True)
|
:param run: whether to also run it or not (default: True)
|
||||||
:type run: bool
|
:type run: bool
|
||||||
'''
|
'''
|
||||||
|
|
|
@ -462,16 +462,16 @@ def harvest_send_job_to_gather_queue(context, data_dict):
|
||||||
:type id: string
|
:type id: string
|
||||||
'''
|
'''
|
||||||
log.info('Send job to gather queue: %r', data_dict)
|
log.info('Send job to gather queue: %r', data_dict)
|
||||||
check_access('harvest_send_job_to_gather_queue', context, data_dict)
|
|
||||||
|
|
||||||
job_id = logic.get_or_bust(data_dict, 'id')
|
job_id = logic.get_or_bust(data_dict, 'id')
|
||||||
|
job = toolkit.get_action('harvest_job_show')(
|
||||||
|
context, {'id': job_id})
|
||||||
|
|
||||||
|
check_access('harvest_send_job_to_gather_queue', context, job)
|
||||||
|
|
||||||
# gather queue
|
# gather queue
|
||||||
publisher = get_gather_publisher()
|
publisher = get_gather_publisher()
|
||||||
|
|
||||||
job = logic.get_action('harvest_job_show')(
|
|
||||||
context, {'id': job_id})
|
|
||||||
|
|
||||||
# Check the source is active
|
# Check the source is active
|
||||||
context['detailed'] = False
|
context['detailed'] = False
|
||||||
source = harvest_source_show(context, {'id': job['source_id']})
|
source = harvest_source_show(context, {'id': job['source_id']})
|
||||||
|
|
|
@ -66,7 +66,7 @@ def harvest_send_job_to_gather_queue(context, data_dict):
|
||||||
It forwards the checks to harvest_job_create, ie the user can only run
|
It forwards the checks to harvest_job_create, ie the user can only run
|
||||||
the job if she is allowed to create the job.
|
the job if she is allowed to create the job.
|
||||||
'''
|
'''
|
||||||
from ckanext.harvest.auth.create import harvest_job_create
|
from ckanext.harvest.logic.auth.create import harvest_job_create
|
||||||
return harvest_job_create(context, data_dict)
|
return harvest_job_create(context, data_dict)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
import json
|
import json
|
||||||
import uuid
|
|
||||||
import factories
|
import factories
|
||||||
import unittest
|
import unittest
|
||||||
from nose.tools import assert_equal, assert_raises
|
from nose.tools import assert_equal, assert_raises
|
||||||
|
@ -7,11 +6,12 @@ from nose.plugins.skip import SkipTest
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from ckan.tests import factories as ckan_factories
|
from ckan.tests import factories as ckan_factories
|
||||||
from ckan.tests.helpers import _get_test_app, reset_db, FunctionalTestBase
|
from ckan.tests.helpers import (_get_test_app, reset_db,
|
||||||
|
FunctionalTestBase, assert_in)
|
||||||
except ImportError:
|
except ImportError:
|
||||||
from ckan.new_tests import factories as ckan_factories
|
from ckan.new_tests import factories as ckan_factories
|
||||||
from ckan.new_tests.helpers import (_get_test_app, reset_db,
|
from ckan.new_tests.helpers import (_get_test_app, reset_db,
|
||||||
FunctionalTestBase)
|
FunctionalTestBase, assert_in)
|
||||||
from ckan import plugins as p
|
from ckan import plugins as p
|
||||||
from ckan.plugins import toolkit
|
from ckan.plugins import toolkit
|
||||||
from ckan import model
|
from ckan import model
|
||||||
|
@ -403,6 +403,44 @@ class TestActions(ActionBase):
|
||||||
toolkit.get_action('harvest_source_create')(
|
toolkit.get_action('harvest_source_create')(
|
||||||
{'user': site_user}, data_dict)
|
{'user': site_user}, data_dict)
|
||||||
|
|
||||||
|
def test_harvest_job_create_as_sysadmin(self):
|
||||||
|
source = factories.HarvestSource(**SOURCE_DICT)
|
||||||
|
|
||||||
|
site_user = toolkit.get_action('get_site_user')(
|
||||||
|
{'model': model, 'ignore_auth': True}, {})['name']
|
||||||
|
data_dict = {
|
||||||
|
'source_id': source['id'],
|
||||||
|
'run': True
|
||||||
|
}
|
||||||
|
job = toolkit.get_action('harvest_job_create')(
|
||||||
|
{'user': site_user}, data_dict)
|
||||||
|
|
||||||
|
assert_equal(job['source_id'], source['id'])
|
||||||
|
assert_equal(job['status'], 'Running')
|
||||||
|
assert_equal(job['gather_started'], None)
|
||||||
|
assert_in('stats', job.keys())
|
||||||
|
|
||||||
|
def test_harvest_job_create_as_admin(self):
|
||||||
|
# as if an admin user presses 'refresh'
|
||||||
|
user = ckan_factories.User()
|
||||||
|
user['capacity'] = 'admin'
|
||||||
|
org = ckan_factories.Organization(users=[user])
|
||||||
|
source_dict = dict(SOURCE_DICT.items() +
|
||||||
|
[('publisher_id', org['id'])])
|
||||||
|
source = factories.HarvestSource(**source_dict)
|
||||||
|
|
||||||
|
data_dict = {
|
||||||
|
'source_id': source['id'],
|
||||||
|
'run': True
|
||||||
|
}
|
||||||
|
job = toolkit.get_action('harvest_job_create')(
|
||||||
|
{'user': user['name']}, data_dict)
|
||||||
|
|
||||||
|
assert_equal(job['source_id'], source['id'])
|
||||||
|
assert_equal(job['status'], 'Running')
|
||||||
|
assert_equal(job['gather_started'], None)
|
||||||
|
assert_in('stats', job.keys())
|
||||||
|
|
||||||
|
|
||||||
class TestHarvestObject(unittest.TestCase):
|
class TestHarvestObject(unittest.TestCase):
|
||||||
@classmethod
|
@classmethod
|
||||||
|
|
Loading…
Reference in New Issue