Module: check_mk
Branch: master
Commit: 8eb8fa95d094e41372a440cec7c4c5fd6a590375
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=8eb8fa95d094e4…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Wed Feb 18 08:15:39 2015 +0100
#1983 FIX Fixed special case in language configuration via user profile
When a user explicitly configured "english" as language in it's user
profile, this setting was not saved correctly. Instead the former
configured language or the default configured language was selected
again after saving.
---
.werks/1983 | 13 +++++++++++++
ChangeLog | 1 +
web/htdocs/forms.py | 4 ++--
web/htdocs/wato.py | 35 ++++++++++++++++-------------------
web/plugins/userdb/hook_auth.py | 11 ++++++++---
5 files changed, 40 insertions(+), 24 deletions(-)
diff --git a/.werks/1983 b/.werks/1983
new file mode 100644
index 0000000..9737070
--- /dev/null
+++ b/.werks/1983
@@ -0,0 +1,13 @@
+Title: Fixed special case in language configuration via user profile
+Level: 1
+Component: multisite
+Class: fix
+Compatible: compat
+State: unknown
+Version: 1.2.7i1
+Date: 1424243612
+
+When a user explicitly configured "english" as language in it's user
+profile, this setting was not saved correctly. Instead the former
+configured language or the default configured language was selected
+again after saving.
diff --git a/ChangeLog b/ChangeLog
index 56da789..9ed39f0 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -199,6 +199,7 @@
* 1978 FIX: Fixed linking to other views using "joined columns"...
* 1980 FIX: logwatch: Fixed exception when acknowledging errors of a single logfile
on a single host
* 1981 FIX: Not trying to render view in view editor when the view is not valid
+ * 1983 FIX: Fixed special case in language configuration via user profile...
WATO:
* 1760 Added search form to manual checks page
diff --git a/web/htdocs/forms.py b/web/htdocs/forms.py
index 7a7c392..28119c6 100644
--- a/web/htdocs/forms.py
+++ b/web/htdocs/forms.py
@@ -220,8 +220,8 @@ def section(title = None, checkbox = None, id = "",
simple=False, hide = False,
if type(checkbox) == str:
html.write(checkbox)
else:
- name, inactive, attrname = checkbox
- html.checkbox(name, inactive, onclick = 'wato_toggle_attribute(this,
\'%s\')' % attrname)
+ name, active, attrname = checkbox
+ html.checkbox(name, active, onclick = 'wato_toggle_attribute(this,
\'%s\')' % attrname)
html.write('</div>')
html.write('</td>')
html.write('<td class="content%s">' % (simple and "
simple" or ""))
diff --git a/web/htdocs/wato.py b/web/htdocs/wato.py
index 1350a49..e750609 100644
--- a/web/htdocs/wato.py
+++ b/web/htdocs/wato.py
@@ -11991,9 +11991,9 @@ def mode_edit_user(phase):
roles.keys())
# Language configuration
- set_lang = html.var('_set_lang')
+ set_lang = html.get_checkbox('_set_lang')
language = html.var('language')
- if set_lang and language != config.default_language:
+ if set_lang:
if language == '':
language = None
new_user['language'] = language
@@ -12272,7 +12272,7 @@ def mode_edit_user(phase):
custom_user_attributes('notify')
forms.header(_("Personal Settings"), isopen = False)
- select_language(user.get('language', ''))
+ select_language(user)
custom_user_attributes('personal')
# TODO: Later we could add custom macros here, which
@@ -15676,20 +15676,16 @@ def verify_password_policy(password):
'set a password which uses at least %d of them.') % num_groups)
-def select_language(user_language):
+def select_language(user):
languages = [ l for l in get_languages() if not config.hide_language(l[0]) ]
- inactive = not not user_language
-
if languages:
- forms.section(_("Language"),
- checkbox = ('_set_lang', inactive, 'language'))
- # html.checkbox('_set_lang', inactive, onclick =
'wato_toggle_attribute(this, \'language\')')
- # html.write(" ")
+ active = 'language' in user
+ forms.section(_("Language"), checkbox = ('_set_lang', active,
'language'))
default_label = _('Default: %s') %
(get_language_alias(config.default_language) or _('English'))
html.write('<div class="inherited"
id="attr_default_language" style="%s">%s</div>' %
- (inactive and "display: none" or
"", default_label))
- html.write('<div id="attr_entry_language"
style="%s">' % ((not inactive) and "display: none" or
""))
- html.select("language", languages, user_language)
+ ((active) and "display: none" or
"", default_label))
+ html.write('<div id="attr_entry_language"
style="%s">' % ((not active) and "display: none" or
""))
+ html.select("language", languages, user.get('language') or
'')
html.write("</div>")
html.help(_('Configure the default language '
'to be used by the user in the user interface here. If you do not
check '
@@ -15774,16 +15770,16 @@ def page_user_profile(change_pw=False):
success = None
if html.has_var('_save') and html.check_transaction():
- try:
- users = userdb.load_users(lock = True)
+ users = userdb.load_users(lock = True)
+ try:
# Profile edit (user options like language etc.)
if config.may('general.edit_profile'):
if not change_pw:
- set_lang = html.var('_set_lang')
+ set_lang = html.get_checkbox('_set_lang')
language = html.var('language')
# Set the users language if requested
- if set_lang and language != config.get_language():
+ if set_lang:
if language == '':
language = None
# Set custom language
@@ -15863,6 +15859,8 @@ def page_user_profile(change_pw=False):
success = True
except MKUserError, e:
html.add_user_error(e.varname, e.message)
+ else:
+ users = userdb.load_users()
# When in distributed setup, display the replication dialog instead of the normal
# profile edit dialog after changing the password.
@@ -15905,7 +15903,6 @@ def page_user_profile(change_pw=False):
if html.has_user_errors():
html.show_user_errors()
- users = userdb.load_users()
user = users.get(config.user_id)
if user == None:
html.show_warning(_("Sorry, your user account does not exist."))
@@ -15937,7 +15934,7 @@ def page_user_profile(change_pw=False):
html.password_input('password2', autocomplete = "off")
if not change_pw and config.may('general.edit_profile'):
- select_language(config.get_language(''))
+ select_language(user)
# Let the user configure how he wants to be notified
if not rulebased_notifications \
diff --git a/web/plugins/userdb/hook_auth.py b/web/plugins/userdb/hook_auth.py
index fc34447..d57d1c7 100644
--- a/web/plugins/userdb/hook_auth.py
+++ b/web/plugins/userdb/hook_auth.py
@@ -89,9 +89,12 @@ def format_php(data, lvl = 1):
def create_php_file(callee, users, role_permissions, groups, folder_permissions):
+ # Do not change WATO internal objects
+ nagvis_users = copy.deepcopy(users)
+
# Set a language for all users
- for username in users:
- users[username].setdefault('language', config.default_language)
+ for user in nagvis_users.values():
+ user.setdefault('language', config.default_language)
# need an extra lock file, since we move the auth.php.tmp file later
# to auth.php. This move is needed for not having loaded incomplete
@@ -224,7 +227,9 @@ function permitted_maps($username) {
}
?>
-''' % (callee, format_php(users), format_php(role_permissions),
format_php(groups), format_php(folder_permissions)))
+''' % (callee, format_php(nagvis_users), format_php(role_permissions),
+ format_php(groups), format_php(folder_permissions)))
+
# Now really replace the file
os.rename(tempfile, g_auth_base_dir + '/auth.php')