commit
e4986cfc62
|
@ -11,7 +11,10 @@ Install this extension in your CKAN is instance is as easy as intall any other C
|
||||||
* Activate your virtual environment (generally by running `. /usr/lib/ckan/default/bin/activate`)
|
* Activate your virtual environment (generally by running `. /usr/lib/ckan/default/bin/activate`)
|
||||||
* Install the extension by running `python setup.py develop`
|
* Install the extension by running `python setup.py develop`
|
||||||
* Modify your configuration file (generally in `/etc/ckan/default/production.ini`) and add `privatedatasets` in the `ckan.plugins` setting.
|
* Modify your configuration file (generally in `/etc/ckan/default/production.ini`) and add `privatedatasets` in the `ckan.plugins` setting.
|
||||||
* In the same config file, specify the location of your parser by adding the `ckan.privatedatasets.parser` setting. For example, to set the [FiWareNotificationParser](https://github.com/conwetlab/ckanext-privatedatasets/blob/master/ckanext/privatedatasets/parsers/fiware.py) as notification parser, add the following line: `ckan.privatedatasets.parser = ckanext.privatedatasets.parsers.fiware:FiWareNotificationParser`
|
* In the same config file, specify the location of your parser by adding the `ckan.privatedatasets.parser` setting. For example, to set the [FiWareNotificationParser](https://github.com/conwetlab/ckanext-privatedatasets/blob/master/ckanext/privatedatasets/parsers/fiware.py) as notification parser, add the following line: `ckan.privatedatasets.parser = ckanext.privatedatasets.parsers.fiware:FiWareNotificationParser`.
|
||||||
|
* If you want you can also add some preferences to set if the Acquire URL should be shown when the user is creating and/or editing a dataset:
|
||||||
|
* To show the Acquire URL when the user is **creating** a dataset, you should set the following preference: `ckan.privatedatasets.show_acquire_url_on_create = True`. By default, the value of this preference is set to `False`.
|
||||||
|
* To show the Acquire URL when the user is **editing** a dataset, you should set the following preference: `ckan.privatedatasets.show_acquire_url_on_edit = True`. By default, the value of this preference is set to `False`.
|
||||||
* Restart your apache2 reserver (`sudo service apache2 restart`)
|
* Restart your apache2 reserver (`sudo service apache2 restart`)
|
||||||
* That's All!
|
* That's All!
|
||||||
|
|
||||||
|
|
|
@ -21,6 +21,8 @@ import ckan.model as model
|
||||||
import ckan.plugins.toolkit as tk
|
import ckan.plugins.toolkit as tk
|
||||||
import db
|
import db
|
||||||
|
|
||||||
|
from pylons import config
|
||||||
|
|
||||||
|
|
||||||
def is_dataset_acquired(pkg_dict):
|
def is_dataset_acquired(pkg_dict):
|
||||||
|
|
||||||
|
@ -52,3 +54,17 @@ def can_read(pkg_dict):
|
||||||
return tk.check_access('package_show', context, pkg_dict)
|
return tk.check_access('package_show', context, pkg_dict)
|
||||||
except tk.NotAuthorized:
|
except tk.NotAuthorized:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
def get_config_bool_value(config_name, default_value=False):
|
||||||
|
value = config.get(config_name, default_value)
|
||||||
|
value = value if type(value) == bool else value != 'False'
|
||||||
|
return value
|
||||||
|
|
||||||
|
|
||||||
|
def show_acquire_url_on_create():
|
||||||
|
return get_config_bool_value('ckan.privatedatasets.show_acquire_url_on_create')
|
||||||
|
|
||||||
|
|
||||||
|
def show_acquire_url_on_edit():
|
||||||
|
return get_config_bool_value('ckan.privatedatasets.show_acquire_url_on_edit')
|
||||||
|
|
|
@ -245,4 +245,7 @@ class PrivateDatasets(p.SingletonPlugin, tk.DefaultDatasetForm):
|
||||||
return {'is_dataset_acquired': helpers.is_dataset_acquired,
|
return {'is_dataset_acquired': helpers.is_dataset_acquired,
|
||||||
'get_allowed_users_str': helpers.get_allowed_users_str,
|
'get_allowed_users_str': helpers.get_allowed_users_str,
|
||||||
'is_owner': helpers.is_owner,
|
'is_owner': helpers.is_owner,
|
||||||
'can_read': helpers.can_read}
|
'can_read': helpers.can_read,
|
||||||
|
'show_acquire_url_on_create': helpers.show_acquire_url_on_create,
|
||||||
|
'show_acquire_url_on_edit': helpers.show_acquire_url_on_edit
|
||||||
|
}
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
{% set organizations_available = h.organizations_available('create_dataset') %}
|
{% set organizations_available = h.organizations_available('create_dataset') %}
|
||||||
{% set user_is_sysadmin = h.check_access('sysadmin') %}
|
{% set user_is_sysadmin = h.check_access('sysadmin') %}
|
||||||
{% set show_organizations_selector = organizations_available and (user_is_sysadmin or dataset_is_draft) %}
|
{% set show_organizations_selector = organizations_available and (user_is_sysadmin or dataset_is_draft) %}
|
||||||
|
{% set editing = 'id' in data %}
|
||||||
|
|
||||||
{% if show_organizations_selector and show_visibility_selector %}
|
{% if show_organizations_selector and show_visibility_selector %}
|
||||||
<div>
|
<div>
|
||||||
|
@ -77,7 +78,6 @@
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
{% if show_organizations_selector and show_visibility_selector %}
|
{% if show_organizations_selector and show_visibility_selector %}
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
@ -85,7 +85,12 @@
|
||||||
{% set users_attrs = {'data-module': 'autocomplete', 'data-module-tags': '', 'data-module-source': '/api/2/util/user/autocomplete?q=?'} %}
|
{% set users_attrs = {'data-module': 'autocomplete', 'data-module-tags': '', 'data-module-source': '/api/2/util/user/autocomplete?q=?'} %}
|
||||||
{{ form.input('allowed_users_str', label=_('Allowed Users'), id='field-allowed_users_str', placeholder=_('Allowed Users'), value=h.get_allowed_users_str(data.allowed_users), error=errors.custom_text, classes=['control-full'], attrs=users_attrs) }}
|
{{ form.input('allowed_users_str', label=_('Allowed Users'), id='field-allowed_users_str', placeholder=_('Allowed Users'), value=h.get_allowed_users_str(data.allowed_users), error=errors.custom_text, classes=['control-full'], attrs=users_attrs) }}
|
||||||
|
|
||||||
|
|
||||||
|
{% if editing and h.show_acquire_url_on_edit() or not editing and h.show_acquire_url_on_create() %}
|
||||||
{{ form.input('acquire_url', label=_('Acquire URL'), id='field-acquire_url', placeholder=_('http://example.com/acquire/'), value=data.acquire_url, error=errors.custom_text, classes=['control-medium']) }}
|
{{ form.input('acquire_url', label=_('Acquire URL'), id='field-acquire_url', placeholder=_('http://example.com/acquire/'), value=data.acquire_url, error=errors.custom_text, classes=['control-medium']) }}
|
||||||
|
{% else %}
|
||||||
|
<input type="hidden" name="acquire_url" id="acquire_url" value="{{ data.acquire_url }}" />
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
{% if data.id and h.check_access('package_delete', {'id': data.id}) and data.state != 'active' %}
|
{% if data.id and h.check_access('package_delete', {'id': data.id}) and data.state != 'active' %}
|
||||||
<div class="control-group">
|
<div class="control-group">
|
||||||
|
|
|
@ -37,10 +37,14 @@ class HelpersTest(unittest.TestCase):
|
||||||
self._db = helpers.db
|
self._db = helpers.db
|
||||||
helpers.db = MagicMock()
|
helpers.db = MagicMock()
|
||||||
|
|
||||||
|
self._config = helpers.config
|
||||||
|
helpers.config = {}
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
helpers.model = self._model
|
helpers.model = self._model
|
||||||
helpers.tk = self._tk
|
helpers.tk = self._tk
|
||||||
helpers.db = self._db
|
helpers.db = self._db
|
||||||
|
helpers.config = self._config
|
||||||
|
|
||||||
@parameterized.expand([
|
@parameterized.expand([
|
||||||
(False, 'user', False),
|
(False, 'user', False),
|
||||||
|
@ -119,3 +123,27 @@ class HelpersTest(unittest.TestCase):
|
||||||
# Assert called with
|
# Assert called with
|
||||||
context = {'user': helpers.tk.c.user, 'userobj': helpers.tk.c.userobj, 'model': helpers.model}
|
context = {'user': helpers.tk.c.user, 'userobj': helpers.tk.c.userobj, 'model': helpers.model}
|
||||||
helpers.tk.check_access.assert_called_once_with('package_show', context, package)
|
helpers.tk.check_access.assert_called_once_with('package_show', context, package)
|
||||||
|
|
||||||
|
@parameterized.expand([
|
||||||
|
(None, False),
|
||||||
|
('True', True),
|
||||||
|
('False', False)
|
||||||
|
])
|
||||||
|
def test_show_acquire_url_on_create(self, config_value, expected_value):
|
||||||
|
if config_value is not None:
|
||||||
|
helpers.config['ckan.privatedatasets.show_acquire_url_on_create'] = config_value
|
||||||
|
|
||||||
|
# Call the function
|
||||||
|
self.assertEquals(expected_value, helpers.show_acquire_url_on_create())
|
||||||
|
|
||||||
|
@parameterized.expand([
|
||||||
|
(None, False),
|
||||||
|
('True', True),
|
||||||
|
('False', False)
|
||||||
|
])
|
||||||
|
def test_show_acquire_url_on_edit(self, config_value, expected_value):
|
||||||
|
if config_value is not None:
|
||||||
|
helpers.config['ckan.privatedatasets.show_acquire_url_on_edit'] = config_value
|
||||||
|
|
||||||
|
# Call the function
|
||||||
|
self.assertEquals(expected_value, helpers.show_acquire_url_on_edit())
|
||||||
|
|
|
@ -169,7 +169,6 @@ class TestSelenium(unittest.TestCase):
|
||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
# THIRD PAGE: Metadata
|
|
||||||
driver.find_element_by_id('field-image-url').clear()
|
driver.find_element_by_id('field-image-url').clear()
|
||||||
driver.find_element_by_id('field-image-url').send_keys(resource_url)
|
driver.find_element_by_id('field-image-url').send_keys(resource_url)
|
||||||
driver.find_element_by_id('field-name').clear()
|
driver.find_element_by_id('field-name').clear()
|
||||||
|
@ -179,6 +178,8 @@ class TestSelenium(unittest.TestCase):
|
||||||
driver.find_element_by_id('s2id_autogen1').clear()
|
driver.find_element_by_id('s2id_autogen1').clear()
|
||||||
driver.find_element_by_id('s2id_autogen1').send_keys(resource_format)
|
driver.find_element_by_id('s2id_autogen1').send_keys(resource_format)
|
||||||
driver.find_element_by_xpath('(//button[@name=\'save\'])[4]').click()
|
driver.find_element_by_xpath('(//button[@name=\'save\'])[4]').click()
|
||||||
|
|
||||||
|
# THIRD PAGE: Metadata
|
||||||
driver.find_element_by_xpath('(//button[@name=\'save\'])[4]').click()
|
driver.find_element_by_xpath('(//button[@name=\'save\'])[4]').click()
|
||||||
|
|
||||||
def check_ds_values(self, url, private, searchable, allowed_users, acquire_url):
|
def check_ds_values(self, url, private, searchable, allowed_users, acquire_url):
|
||||||
|
|
2
test.ini
2
test.ini
|
@ -9,3 +9,5 @@ use = config:./ckan/test-core.ini
|
||||||
ckan.legacy_templates = No
|
ckan.legacy_templates = No
|
||||||
ckan.plugins = privatedatasets
|
ckan.plugins = privatedatasets
|
||||||
ckan.privatedatasets.parser = ckanext.privatedatasets.parsers.fiware:FiWareNotificationParser
|
ckan.privatedatasets.parser = ckanext.privatedatasets.parsers.fiware:FiWareNotificationParser
|
||||||
|
ckan.privatedatasets.show_acquire_url_on_create = True
|
||||||
|
ckan.privatedatasets.show_acquire_url_on_edit = True
|
Loading…
Reference in New Issue