Merge pull request #13 from conwetlab/develop

Show or Hide Acquire URL
This commit is contained in:
Aitor Magán García 2014-10-13 10:06:36 +02:00
commit e4986cfc62
7 changed files with 64 additions and 6 deletions

View File

@ -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`)
* 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.
* 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`)
* That's All!

View File

@ -21,6 +21,8 @@ import ckan.model as model
import ckan.plugins.toolkit as tk
import db
from pylons import config
def is_dataset_acquired(pkg_dict):
@ -52,3 +54,17 @@ def can_read(pkg_dict):
return tk.check_access('package_show', context, pkg_dict)
except tk.NotAuthorized:
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')

View File

@ -245,4 +245,7 @@ class PrivateDatasets(p.SingletonPlugin, tk.DefaultDatasetForm):
return {'is_dataset_acquired': helpers.is_dataset_acquired,
'get_allowed_users_str': helpers.get_allowed_users_str,
'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
}

View File

@ -14,6 +14,7 @@
{% set organizations_available = h.organizations_available('create_dataset') %}
{% set user_is_sysadmin = h.check_access('sysadmin') %}
{% 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 %}
<div>
@ -77,7 +78,6 @@
{% endblock %}
{% if show_organizations_selector and show_visibility_selector %}
</div>
{% endif %}
@ -85,7 +85,12 @@
{% 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('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']) }}
{% 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']) }}
{% 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' %}
<div class="control-group">

View File

@ -37,10 +37,14 @@ class HelpersTest(unittest.TestCase):
self._db = helpers.db
helpers.db = MagicMock()
self._config = helpers.config
helpers.config = {}
def tearDown(self):
helpers.model = self._model
helpers.tk = self._tk
helpers.db = self._db
helpers.config = self._config
@parameterized.expand([
(False, 'user', False),
@ -119,3 +123,27 @@ class HelpersTest(unittest.TestCase):
# Assert called with
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)
@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())

View File

@ -169,7 +169,6 @@ class TestSelenium(unittest.TestCase):
except Exception:
pass
# THIRD PAGE: Metadata
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-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').send_keys(resource_format)
driver.find_element_by_xpath('(//button[@name=\'save\'])[4]').click()
# THIRD PAGE: Metadata
driver.find_element_by_xpath('(//button[@name=\'save\'])[4]').click()
def check_ds_values(self, url, private, searchable, allowed_users, acquire_url):

View File

@ -8,4 +8,6 @@ use = config:./ckan/test-core.ini
ckan.legacy_templates = No
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