Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an endpoint to get default settings. #207

Merged
merged 1 commit into from
Jul 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions histomicsui/rest/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
from girder.constants import AccessType, TokenScope
from girder.models.folder import Folder
from girder.models.item import Item
from girder.models.setting import Setting
from girder.utility.model_importer import ModelImporter
from girder_jobs.models.job import Job

Expand All @@ -39,6 +40,7 @@ def addSystemEndpoints(apiRoot):
apiRoot.folder.route('GET', ('query',), getFoldersByQuery)
# Added to the system route
apiRoot.system.route('PUT', ('restart',), restartServer)
apiRoot.system.route('GET', ('setting', 'default'), getSettingDefault)
# Added to the job route
apiRoot.job.route('GET', ('old',), getOldJobs)
apiRoot.job.route('DELETE', ('old',), deleteOldJobs)
Expand Down Expand Up @@ -320,3 +322,31 @@ def putResourceMetadata(self, resources, metadata, allowNull):
# restrictive than we want.
modified += model.update({'_id': resource['_id']}, metaUpdate).modified_count
return modified


@access.admin(scope=TokenScope.SETTINGS_READ)
@autoDescribeRoute(
Description('Get the value of a system setting, or a list of them.')
.notes('Must be a system administrator to call this.')
.param('key', 'The key identifying this setting.', required=False)
.jsonParam('list', 'A JSON list of keys representing a set of settings to return.',
required=False, requireArray=True)
.param('default', 'If "none", return a null value if a setting is '
'currently the default value. If "default", return the default '
'value of the setting(s).', required=False)
.errorResponse('You are not a system administrator.', 403)
)
@boundHandler
def getSettingDefault(self, key, list, default=None):
getFunc = Setting().get
if default == 'none':
getFunc = (lambda k: (Setting()._get(k) or {}).get('value'))
elif default == 'default':
getFunc = Setting().getDefault
elif default:
raise RestException("Default was not 'none', 'default', or blank.")
if list is not None:
return {k: getFunc(k) for k in list}
else:
self.requireParams({'key': key})
return getFunc(key)
4 changes: 2 additions & 2 deletions histomicsui/web_client/views/body/ConfigView.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ var ConfigView = View.extend({
$.when(
restRequest({
method: 'GET',
url: 'system/setting',
url: 'system/setting/default',
data: {
list: JSON.stringify(this.settingsKeys),
default: 'none'
Expand All @@ -78,7 +78,7 @@ var ConfigView = View.extend({
}),
restRequest({
method: 'GET',
url: 'system/setting',
url: 'system/setting/default',
data: {
list: JSON.stringify(this.settingsKeys),
default: 'default'
Expand Down