def _action(self) -> None: assert user.id is not None users = userdb.load_users(lock=True) user_spec = users[user.id] language = request.get_ascii_input_mandatory("language", "") # Set the users language if requested to set it explicitly if language != "_default_": user_spec["language"] = language user.language = language set_language_cookie(request, response, language) else: if "language" in user_spec: del user_spec["language"] user.reset_language() # load the new language localize(user.language) if user.may("general.edit_notifications") and user_spec.get( "notifications_enabled"): value = forms.get_input(get_vs_flexible_notifications(), "notification_method") user_spec["notification_method"] = value # Custom attributes if user.may("general.edit_user_attributes"): for name, attr in userdb.get_user_attributes(): if not attr.user_editable(): continue perm_name = attr.permission() if perm_name and not user.may(perm_name): continue vs = attr.valuespec() value = vs.from_html_vars("ua_" + name) vs.validate_value(value, "ua_" + name) # TODO: Dynamically fiddling around with a TypedDict is a bit questionable user_spec[name] = value # type: ignore[literal-required] userdb.save_users(users) flash(_("Successfully updated user profile.")) # In distributed setups with remote sites where the user can login, start the # user profile replication now which will redirect the user to the destination # page after completion. Otherwise directly open up the destination page. if user.authorized_login_sites(): back_url = "user_profile_replicate.py?back=user_profile.py" else: back_url = "user_profile.py" # Ensure theme changes are applied without additional user interaction html.reload_whole_page(back_url) html.footer() raise FinalizeRequest(code=200)
def _action(self) -> None: assert config.user.id is not None users = userdb.load_users(lock=True) user = users[config.user.id] language = request.get_ascii_input_mandatory('language', "") # Set the users language if requested to set it explicitly if language != "_default_": user['language'] = language config.user.language = language set_language_cookie(request, response, language) else: if 'language' in user: del user['language'] config.user.reset_language() # load the new language cmk.gui.i18n.localize(config.user.language) if config.user.may('general.edit_notifications') and user.get( "notifications_enabled"): value = forms.get_input(watolib.get_vs_flexible_notifications(), "notification_method") user["notification_method"] = value # Custom attributes if config.user.may('general.edit_user_attributes'): for name, attr in userdb.get_user_attributes(): if not attr.user_editable(): continue if attr.permission() and not config.user.may( attr.permission()): continue vs = attr.valuespec() value = vs.from_html_vars('ua_' + name) vs.validate_value(value, "ua_" + name) user[name] = value userdb.save_users(users) flash(_("Successfully updated user profile.")) # In distributed setups with remote sites where the user can login, start the # user profile replication now which will redirect the user to the destination # page after completion. Otherwise directly open up the destination page. if config.user.authorized_login_sites(): back_url = "user_profile_replicate.py?back=user_profile.py" else: back_url = "user_profile.py" # Ensure theme changes are applied without additional user interaction html.reload_whole_page(back_url) html.footer() raise FinalizeRequest(code=200)
def _localize_request() -> None: previous_language = cmk.gui.i18n.get_current_language() user_language = request.get_ascii_input("lang", user.language) set_language_cookie(request, response, user_language) cmk.gui.i18n.localize(user_language) # All plugins might have to be reloaded due to a language change. Only trigger # a second plugin loading when the user is really using a custom localized GUI. # Otherwise the load_all_plugins() at the beginning of the request is sufficient. if cmk.gui.i18n.get_current_language() != previous_language: load_all_plugins()
def _localize_request() -> None: user_language = request.get_ascii_input("lang", user.language) set_language_cookie(request, response, user_language) cmk.gui.i18n.localize(user_language)