From 323c5bcd26dbb1da1a8ff66f096bde764bb1cb49 Mon Sep 17 00:00:00 2001 From: Ross Jones Date: Fri, 7 Aug 2015 15:07:22 +0100 Subject: [PATCH] Allows the disabling of datastore_search_sql Although the datastore is useful, it may be that some users may will to disable the specific datastore_search_sql. This commit allows them to do that. --- ckanext/datastore/plugin.py | 9 ++++++++- ckanext/datastore/tests/test_disable.py | 27 +++++++++++++++++++++++++ doc/maintaining/configuration.rst | 14 +++++++++++++ 3 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 ckanext/datastore/tests/test_disable.py diff --git a/ckanext/datastore/plugin.py b/ckanext/datastore/plugin.py index a7db61dbd52..b581fb1aeac 100644 --- a/ckanext/datastore/plugin.py +++ b/ckanext/datastore/plugin.py @@ -81,6 +81,10 @@ def configure(self, config): # datastore runs on PG prior to 9.0 (for example 8.4). self.legacy_mode = _is_legacy_mode(self.config) + # Check whether users have disabled datastore_search_sql + self.enable_sql_search = p.toolkit.asbool( + self.config.get('ckan.datastore.sqlsearch.enabled', True)) + datapusher_formats = config.get('datapusher.formats', '').split() self.datapusher_formats = datapusher_formats or DEFAULT_FORMATS @@ -246,8 +250,11 @@ def get_actions(self): 'datastore_info': action.datastore_info, } if not self.legacy_mode: + if self.enable_sql_search: + # Only enable search_sql if the config does not disable it + actions.update({'datastore_search_sql': + action.datastore_search_sql}) actions.update({ - 'datastore_search_sql': action.datastore_search_sql, 'datastore_make_private': action.datastore_make_private, 'datastore_make_public': action.datastore_make_public}) return actions diff --git a/ckanext/datastore/tests/test_disable.py b/ckanext/datastore/tests/test_disable.py new file mode 100644 index 00000000000..bc3a6f223b5 --- /dev/null +++ b/ckanext/datastore/tests/test_disable.py @@ -0,0 +1,27 @@ + +import pylons.config as config +import ckan.plugins as p +import nose.tools as t + + +class TestDisable(object): + + @classmethod + def setup_class(cls): + with p.use_plugin('datastore') as the_plugin: + legacy = the_plugin.legacy_mode + + if legacy: + raise nose.SkipTest("SQL tests are not supported in legacy mode") + + @t.raises(KeyError) + def test_disable_sql_search(self): + config['ckan.datastore.sqlsearch.enabled'] = False + with p.use_plugin('datastore') as the_plugin: + print p.toolkit.get_action('datastore_search_sql') + config['ckan.datastore.sqlsearch.enabled'] = True + + def test_enabled_sql_search(self): + config['ckan.datastore.sqlsearch.enabled'] = True + with p.use_plugin('datastore') as the_plugin: + p.toolkit.get_action('datastore_search_sql') diff --git a/doc/maintaining/configuration.rst b/doc/maintaining/configuration.rst index 57830ff41c8..62c14ed9125 100644 --- a/doc/maintaining/configuration.rst +++ b/doc/maintaining/configuration.rst @@ -256,6 +256,20 @@ The default method used when creating full-text search indexes. Currently it can be "gin" or "gist". Refer to PostgreSQL's documentation to understand the characteristics of each one and pick the best for your instance. +.. _ckan.datastore.sqlsearch.enabled: + +ckan.datastore.sqlsearch.enabled +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +Example:: + + ckan.datastore.sqlsearch.enabled = False + +Default value: ``True`` + +This option allows you to disable the datastore_search_sql action function, and +corresponding API endpoint if you do not wish it to be activated. + Site Settings -------------