Skip to content

Commit

Permalink
Allows the disabling of datastore_search_sql
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
rossjones committed Sep 11, 2015
1 parent 63e3bc9 commit 323c5bc
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 1 deletion.
9 changes: 8 additions & 1 deletion ckanext/datastore/plugin.py
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
27 changes: 27 additions & 0 deletions 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')
14 changes: 14 additions & 0 deletions doc/maintaining/configuration.rst
Expand Up @@ -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
-------------

Expand Down

0 comments on commit 323c5bc

Please sign in to comment.