Commit
Sysadmins can call this action with a key (eg. 'ckan.site_title') to retrieve a config value. The value is returned either from the system_info table of the database, or secondly, from the config object as defined in the ini file. Only config options in the schema whitelisted as editable will be returned. Non-editable options, or non existing options, will return a ValidationError.
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3361,3 +3361,43 @@ def help_show(context, data_dict): | |
raise NotFound('Action function not found') | ||
|
||
return function.__doc__ | ||
|
||
|
||
def config_option_show(context, data_dict): | ||
'''Show the current value of a particular configuration option. | ||
Only return config options that can be updated with the | ||
`config_option_update` action. | ||
:param id: The configuration option key | ||
:type id: string | ||
:returns: The value of the config option from either the system_info table | ||
or ini file. | ||
:rtype: string | ||
:raises: :class:`ckan.logic.ValidationError`: if config option is not in | ||
the schema (whitelisted as editable). | ||
''' | ||
|
||
model = context['model'] | ||
|
||
_check_access('config_option_show', context, data_dict) | ||
|
||
key = _get_or_bust(data_dict, 'key') | ||
|
||
schema = ckan.logic.schema.default_show_configuration_schema() | ||
This comment has been minimized.
Sorry, something went wrong. |
||
|
||
# Only return whitelisted keys | ||
if key not in schema: | ||
raise ValidationError( | ||
'Configuration option \'{0}\' can not be shown'.format(key)) | ||
|
||
# return the value from system_info or config | ||
default_value = config.get(key, None) | ||
if key in schema.keys(): | ||
This comment has been minimized.
Sorry, something went wrong.
amercader
Member
|
||
value = model.get_system_info(key, default=default_value) | ||
else: | ||
value = default_value | ||
|
||
return value |
@brew We want to check which config options can be edited to decide which ones to show, so I wouldn't create a dedicated show schema, as it will be confusing. Also we should now use
ckan.logic.schema.update_config_schema
, which will incorporate changes from extensions.