mirror of
https://github.com/galaxyproject/galaxy.git
synced 2026-09-24 16:30:27 +08:00
Merge pull request #3383 from bgruening/extra_user_preferences
Add extension point for user preferences
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
preferences:
|
||||
# the key you can refer to
|
||||
apollo_url_01:
|
||||
# description that is displayed to the user
|
||||
description: The URL to your personal Apollo instance
|
||||
inputs:
|
||||
# the content can be accessed by apollo_url_01.apollo_url
|
||||
- name: apollo_url
|
||||
label: Apollo URL
|
||||
# type of input field that will be displayed to the user
|
||||
# can be string or password
|
||||
type: text
|
||||
# by defaul all inputs are required
|
||||
required: True
|
||||
- name: apollo_text
|
||||
label: Apollo Text
|
||||
# type of input field that will be displayed to the user
|
||||
# can be string or password
|
||||
type: text
|
||||
# by defaul all inputs are required
|
||||
required: True
|
||||
|
||||
openstack_account:
|
||||
description: Your own Open Stack account
|
||||
inputs:
|
||||
- name: username
|
||||
label: Username
|
||||
type: text
|
||||
required: False
|
||||
- name: url
|
||||
label: Open Stack URL
|
||||
type: text
|
||||
required: True
|
||||
|
||||
webhook_overlay_search:
|
||||
description: Configuration option for your search results
|
||||
inputs:
|
||||
- name: max_search_results
|
||||
label: Maximum number of search results
|
||||
type: text
|
||||
required: False
|
||||
@@ -54,6 +54,7 @@ PATH_DEFAULTS = dict(
|
||||
workflow_schedulers_config_file=['config/workflow_schedulers_conf.xml', 'config/workflow_schedulers_conf.xml.sample'],
|
||||
modules_mapping_files=['config/environment_modules_mapping.yml', 'config/environment_modules_mapping.yml.sample'],
|
||||
local_conda_mapping_file=['config/local_conda_mapping.yml', 'config/local_conda_mapping.yml.sample'],
|
||||
user_preferences_extra_config_file=[ 'config/user_preferences_extra_conf.yml' ],
|
||||
containers_config_file=['config/containers_conf.yml'],
|
||||
)
|
||||
|
||||
|
||||
@@ -11,6 +11,8 @@ from datetime import datetime
|
||||
from markupsafe import escape
|
||||
from sqlalchemy import false, true, and_, or_
|
||||
|
||||
import yaml
|
||||
|
||||
from galaxy import exceptions, util, web
|
||||
from galaxy.exceptions import MessageException, ObjectInvalid
|
||||
from galaxy.managers import users
|
||||
@@ -250,6 +252,46 @@ class UserAPIController( BaseAPIController, UsesTagsMixin, CreatesUsersMixin, Cr
|
||||
'nice_total_disk_usage': util.nice_size( usage ),
|
||||
'quota_percent': percent}
|
||||
|
||||
def _get_extra_user_preferences(self, trans):
|
||||
"""
|
||||
Reads the file user_preferences_extra_conf.yml to display
|
||||
admin defined user informations
|
||||
"""
|
||||
path = trans.app.config.user_preferences_extra_config_file
|
||||
try:
|
||||
with open(path, 'r') as stream:
|
||||
config = yaml.load(stream)
|
||||
except:
|
||||
log.warn('Config file (%s) could not be found or is malformed.' % path)
|
||||
return {}
|
||||
|
||||
return config['preferences'] if config else {}
|
||||
|
||||
def _build_extra_user_pref_inputs(self, preferences, user):
|
||||
"""
|
||||
Build extra user preferences inputs list.
|
||||
Add values to the fields if present
|
||||
"""
|
||||
if not preferences:
|
||||
return []
|
||||
data = []
|
||||
# Get data if present
|
||||
data_key = "extra_user_preferences"
|
||||
if data_key in user.preferences:
|
||||
data = json.loads(user.preferences[data_key])
|
||||
extra_pref_inputs = list()
|
||||
# Build sections for different categories of inputs
|
||||
for item, value in preferences.items():
|
||||
if value is not None:
|
||||
for input in value["inputs"]:
|
||||
input['help'] = 'Required' if input['required'] else ''
|
||||
field = item + '|' + input['name']
|
||||
for data_item in data:
|
||||
if field in data_item:
|
||||
input['value'] = data[data_item]
|
||||
extra_pref_inputs.append({'type': 'section', 'title': value['description'], 'name': item, 'expanded': True, 'inputs': value['inputs']})
|
||||
return extra_pref_inputs
|
||||
|
||||
@expose_api
|
||||
def get_information(self, trans, id, **kwd):
|
||||
"""
|
||||
@@ -302,6 +344,7 @@ class UserAPIController( BaseAPIController, UsesTagsMixin, CreatesUsersMixin, Cr
|
||||
info_field['test_param']['data'].append({'label': info_form['name'], 'value': info_form['id']})
|
||||
info_field['cases'].append({'value': info_form['id'], 'inputs': info_form['inputs']})
|
||||
inputs.append(info_field)
|
||||
|
||||
address_inputs = [{'type': 'hidden', 'name': 'id', 'hidden': True}]
|
||||
for field in AddressField.fields():
|
||||
address_inputs.append({'type': 'text', 'name': field[0], 'label': field[1], 'help': field[2]})
|
||||
@@ -315,6 +358,11 @@ class UserAPIController( BaseAPIController, UsesTagsMixin, CreatesUsersMixin, Cr
|
||||
address_cache.append(input_copy)
|
||||
address_repeat['cache'].append(address_cache)
|
||||
inputs.append(address_repeat)
|
||||
|
||||
# Build input sections for extra user preferences
|
||||
extra_user_pref = self._build_extra_user_pref_inputs( self._get_extra_user_preferences( trans ), user )
|
||||
for item in extra_user_pref:
|
||||
inputs.append(item)
|
||||
else:
|
||||
if user.active_repositories:
|
||||
inputs.append(dict(id='name_input', name='username', label='Public name:', type='hidden', value=username, help='You cannot change your public name after you have created a repository in this tool shed.'))
|
||||
@@ -382,6 +430,26 @@ class UserAPIController( BaseAPIController, UsesTagsMixin, CreatesUsersMixin, Cr
|
||||
form_values = trans.model.FormValues(user_info_form, user_info_values)
|
||||
trans.sa_session.add(form_values)
|
||||
user.values = form_values
|
||||
|
||||
# Update values for extra user preference items
|
||||
extra_user_pref_data = dict()
|
||||
get_extra_pref_keys = self._get_extra_user_preferences( trans )
|
||||
if get_extra_pref_keys is not None:
|
||||
for key in get_extra_pref_keys:
|
||||
key_prefix = key + '|'
|
||||
for item in payload:
|
||||
if item.startswith( key_prefix ):
|
||||
# Show error message if the required field is empty
|
||||
if payload[item] == "":
|
||||
# Raise an exception when a required field is empty while saving the form
|
||||
keys = item.split("|")
|
||||
section = get_extra_pref_keys[keys[0]]
|
||||
for input in section['inputs']:
|
||||
if input['name'] == keys[1] and input['required']:
|
||||
raise MessageException("Please fill the required field")
|
||||
extra_user_pref_data[ item ] = payload[ item ]
|
||||
user.preferences[ "extra_user_preferences" ] = json.dumps( extra_user_pref_data )
|
||||
|
||||
# Update user addresses
|
||||
address_dicts = {}
|
||||
address_count = 0
|
||||
|
||||
Reference in New Issue
Block a user