[ckan harvester] Support for defining a custom user to do the harvesting
This commit is contained in:
parent
2018d9e513
commit
c939d90dbb
|
@ -117,7 +117,7 @@ The CKAN harvesters support a number of configuration options to control their
|
|||
behaviour. Those need to defined as a JSON object in the configuration form
|
||||
field. The currently supported configuration options are:
|
||||
|
||||
* api_version: You can force the harvester to use eithoer version '1' or
|
||||
* api_version: You can force the harvester to use either version '1' or
|
||||
'2' of the CKAN API. Default is '2'.
|
||||
|
||||
* default_tags: A list of tags that will be added to all harvested datasets.
|
||||
|
@ -128,13 +128,18 @@ field. The currently supported configuration options are:
|
|||
define the groups according to the API version you defined (names for
|
||||
version '1', ids for version '2')
|
||||
|
||||
* user: User who will run the harvesting process. Please note that this user
|
||||
needs to have permission for creating packages, and if default groups were
|
||||
defined, the user must have permission to assign packages to these groups.
|
||||
|
||||
Here is an example of a configuration object (the one that must be entered in
|
||||
the configuration field)::
|
||||
|
||||
{
|
||||
"api_version":"1",
|
||||
"default_tags":["new-tag-1","new-tag-2"],
|
||||
"default_groups":["my-own-group"]
|
||||
"default_groups":["my-own-group"],
|
||||
"user":"harverster-user"
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -109,13 +109,16 @@ class HarvesterBase(SingletonPlugin):
|
|||
# Check API version
|
||||
if self.config:
|
||||
api_version = self.config.get('api_version','2')
|
||||
#TODO: use site user when available
|
||||
user_name = self.config.get('user',u'harvest')
|
||||
else:
|
||||
api_verion = '2'
|
||||
user_name = u'harvest'
|
||||
|
||||
context = {
|
||||
'model': model,
|
||||
'session': Session,
|
||||
'user': u'harvest',
|
||||
'user': user_name,
|
||||
'api_version': api_version,
|
||||
'schema': schema,
|
||||
}
|
||||
|
|
|
@ -77,6 +77,14 @@ class CKANHarvester(HarvesterBase):
|
|||
except NotFound,e:
|
||||
raise ValueError('Default group not found')
|
||||
|
||||
if 'user' in config_obj:
|
||||
# Check if user exists
|
||||
context = {'model':model,'user':c.user}
|
||||
try:
|
||||
user = get_action('user_show')(context,{'id':config_obj.get('user')})
|
||||
except NotFound,e:
|
||||
raise ValueError('User not found')
|
||||
|
||||
except ValueError,e:
|
||||
raise e
|
||||
|
||||
|
|
Loading…
Reference in New Issue