def action(self) -> ActionResult: if request.var("_action") != "discard": return None if not transactions.check_transaction(): return None if not self._may_discard_changes(): return None if not self.has_changes(): return None # Now remove all currently pending changes by simply restoring the last automatically # taken snapshot. Then activate the configuration. This should revert all pending changes. file_to_restore = self._get_last_wato_snapshot_file() if not file_to_restore: raise MKUserError(None, _("There is no WATO snapshot to be restored.")) msg = _("Discarded pending changes (Restored %s)") % file_to_restore # All sites and domains can be affected by a restore: Better restart everything. _changes.add_change( "changes-discarded", msg, domains=ABCConfigDomain.enabled_domains(), need_restart=True, ) self._extract_snapshot(file_to_restore) activate_changes.execute_activate_changes([ d.get_domain_request([]) for d in ABCConfigDomain.enabled_domains() ]) for site_id in activation_sites(): self.confirm_site_changes(site_id) build_index_background() make_header( html, self.title(), breadcrumb=self.breadcrumb(), show_body_start=display_options.enabled(display_options.H), show_top_heading=display_options.enabled(display_options.T), ) html.open_div(class_="wato") html.show_message(_("Successfully discarded all pending changes.")) html.javascript("hide_changes_buttons();") html.footer() return FinalizeRequest(code=200)
def save_global_settings(vars_, site_specific=False, custom_site_path=None): per_domain: Dict[str, Dict[Any, Any]] = {} # TODO: Uee _get_global_config_var_names() from domain class? for config_variable_class in config_variable_registry.values(): config_variable = config_variable_class() domain = config_variable.domain() varname = config_variable.ident() if varname not in vars_: continue per_domain.setdefault(domain().ident(), {})[varname] = vars_[varname] # Some settings are handed over from the central site but are not registered in the # configuration domains since the user must not change it directly. for varname in [ "wato_enabled", "userdb_automatic_sync", "user_login", ]: if varname in vars_: per_domain.setdefault(ConfigDomainGUI.ident(), {})[varname] = vars_[varname] for domain in ABCConfigDomain.enabled_domains(): domain_config = per_domain.get(domain().ident(), {}) if site_specific: domain().save_site_globals(domain_config, custom_site_path=custom_site_path) else: domain().save(domain_config, custom_site_path=custom_site_path)
def save_global_settings(vars_, site_specific=False, custom_site_path=None): per_domain = {} # type: Dict[str, Dict[Any, Any]] # TODO: Uee _get_global_config_var_names() from domain class? for config_variable_class in config_variable_registry.values(): config_variable = config_variable_class() domain = config_variable.domain() varname = config_variable.ident() if varname not in vars_: continue per_domain.setdefault(domain.ident, {})[varname] = vars_[varname] # The global setting wato_enabled is not registered in the configuration domains # since the user must not change it directly. It is set by D-WATO on slave sites. if "wato_enabled" in vars_: per_domain.setdefault(ConfigDomainGUI.ident, {})["wato_enabled"] = vars_["wato_enabled"] if "userdb_automatic_sync" in vars_: per_domain.setdefault( ConfigDomainGUI.ident, {})["userdb_automatic_sync"] = vars_["userdb_automatic_sync"] for domain in ABCConfigDomain.enabled_domains(): domain_config = per_domain.get(domain.ident, {}) if site_specific: domain().save_site_globals(domain_config, custom_site_path=custom_site_path) else: domain().save(domain_config, custom_site_path=custom_site_path)
def load_configuration_settings(site_specific=False): settings = {} for domain in ABCConfigDomain.enabled_domains(): if site_specific: settings.update(domain().load_site_globals()) else: settings.update(domain().load()) return settings
def load_configuration_settings(site_specific=False, custom_site_path=None, full_config=False): settings = {} for domain in ABCConfigDomain.enabled_domains(): if full_config: settings.update(domain().load_full_config()) elif site_specific: settings.update(domain().load_site_globals(custom_site_path=custom_site_path)) else: settings.update(domain().load()) return settings