Skip to content

Commit

Permalink
Adding edit and save extra user preferences if present to manage info…
Browse files Browse the repository at this point in the history
… screen in User Preferences and merging base.css file in the static folder
  • Loading branch information
anuprulez committed Nov 10, 2016
1 parent f3ecafd commit 5327042
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 53 deletions.
61 changes: 59 additions & 2 deletions lib/galaxy/webapps/galaxy/api/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import logging
import datetime
import re

import json
from sqlalchemy import false, true, and_, or_

from galaxy import exceptions, util, web
Expand All @@ -27,7 +27,7 @@
from galaxy.tools.toolbox.filters import FilterFactory
from galaxy.util import docstring_trim, listify
from galaxy.util.odict import odict

from yaml import load

log = logging.getLogger( __name__ )

Expand Down Expand Up @@ -251,6 +251,46 @@ def anon_user_api_value( self, trans ):
'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.xml to display
admin defined user informations
"""
path = trans.app.config.user_preferences_extra_config_file
try:
with open(path, 'r') as stream:
config = 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["extra_user_preferences"])
extra_pref_inputs = list()
# Build sections for different categories of inputs
for item in preferences:
section = preferences[item]
for input in section['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_item[field]
extra_pref_inputs.append({'type': 'section', 'title': section['description'], 'name': item, 'expanded': True, 'inputs': section['inputs']})
return extra_pref_inputs

@expose_api
def get_information(self, trans, id, **kwd):
'''
Expand Down Expand Up @@ -299,6 +339,12 @@ def get_information(self, trans, id, **kwd):
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)

# Build 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)

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]})
Expand Down Expand Up @@ -369,6 +415,17 @@ def set_information(self, trans, id, payload={}, **kwd):
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 = list()
get_extra_pref_keys = self._get_extra_user_preferences(trans)
for key in get_extra_pref_keys:
key_prefix = key + '|'
for item in payload:
if item.startswith(key_prefix):
extra_user_pref_data.append({ item : payload[item] })
user.preferences["extra_user_preferences"] = json.dumps(extra_user_pref_data)

# Update user addresses
address_dicts = {}
address_count = 0
Expand Down
29 changes: 7 additions & 22 deletions static/scripts/bundled/analysis.bundled.js

Large diffs are not rendered by default.

6 changes: 1 addition & 5 deletions static/scripts/bundled/analysis.bundled.js.map

Large diffs are not rendered by default.

5 changes: 0 additions & 5 deletions static/scripts/bundled/libs.bundled.js

Large diffs are not rendered by default.

6 changes: 1 addition & 5 deletions static/scripts/bundled/libs.bundled.js.map

Large diffs are not rendered by default.

4 changes: 0 additions & 4 deletions static/scripts/bundled/login.bundled.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 5327042

Please sign in to comment.