Do not throw 501 errors, instead return warnings that the configuration
changes cannot be applied.
Signed-off-by: Simo Sorce <simo@redhat.com>
Reviewed-by: Patrick Uiterwijk <puiterwijk@redhat.com>
from ipsilon.util import config as pconfig
from ipsilon.util import config as pconfig
+class AdminError(Exception):
+ def __init__(self, message):
+ super(AdminError, self).__init__(message)
+ self.message = message
+
+ def __str__(self):
+ return str(self.message)
+
+
class AdminPage(Page):
def __init__(self, *args, **kwargs):
class AdminPage(Page):
def __init__(self, *args, **kwargs):
@admin_protect
def POST(self, *args, **kwargs):
@admin_protect
def POST(self, *args, **kwargs):
+ if self._po.is_readonly:
+ return self.root_with_msg(
+ message="Configuration is marked Read-Only",
+ message_type="warning")
+
message = "Nothing was modified."
message_type = "info"
new_db_values = dict()
message = "Nothing was modified."
message_type = "info"
new_db_values = dict()
@admin_protect
def POST(self, *args, **kwargs):
@admin_protect
def POST(self, *args, **kwargs):
+
+ if self._site[self.facility].is_readonly:
+ return self.parent.root_with_msg(
+ message="Configuration is marked Read-Only",
+ message_type="warning")
+
message = "Nothing was modified."
message_type = "info"
cur_enabled = self._get_enabled_list()
message = "Nothing was modified."
message_type = "info"
cur_enabled = self._get_enabled_list()
def root(self, *args, **kwargs):
return self.root_with_msg()
def root(self, *args, **kwargs):
return self.root_with_msg()
- @admin_protect
- def enable(self, plugin):
- msg = None
+ def _get_plugin_obj(self, plugin):
plugins = self._site[self.facility]
plugins = self._site[self.facility]
+ if plugins.is_readonly:
+ msg = "Configuration is marked Read-Only"
+ raise AdminError(msg)
if plugin not in plugins.available:
msg = "Unknown plugin %s" % plugin
if plugin not in plugins.available:
msg = "Unknown plugin %s" % plugin
- return self.root_with_msg(msg, "error")
obj = plugins.available[plugin]
obj = plugins.available[plugin]
+ if obj.is_readonly:
+ msg = "Plugin Configuration is marked Read-Only"
+ raise AdminError(msg)
+ return obj
+
+ @admin_protect
+ def enable(self, plugin):
+ msg = None
+ try:
+ obj = self._get_plugin_obj(plugin)
+ except AdminError, e:
+ return self.root_with_msg(str(e), "warning")
if not obj.is_enabled:
obj.enable()
obj.save_enabled_state()
if not obj.is_enabled:
obj.enable()
obj.save_enabled_state()
@admin_protect
def disable(self, plugin):
msg = None
@admin_protect
def disable(self, plugin):
msg = None
- plugins = self._site[self.facility]
- if plugin not in plugins.available:
- msg = "Unknown plugin %s" % plugin
- return self.root_with_msg(msg, "error")
- obj = plugins.available[plugin]
+ try:
+ obj = self._get_plugin_obj(plugin)
+ except AdminError, e:
+ return self.root_with_msg(str(e), "warning")
if obj.is_enabled:
obj.disable()
obj.save_enabled_state()
if obj.is_enabled:
obj.disable()
obj.save_enabled_state()
self.__data = AdminStore()
return self.__data
self.__data = AdminStore()
return self.__data
+ @property
+ def is_readonly(self):
+ return self._data.is_readonly
+
def get_plugins(self):
p = Plugins()
return p.get_plugins(self._pathname, self._plugin_type, self)
def get_plugins(self):
p = Plugins()
return p.get_plugins(self._pathname, self._plugin_type, self)
self._plugins = plugins
self.is_enabled = False
self._plugins = plugins
self.is_enabled = False
+ @property
+ def is_readonly(self):
+ return self._data.is_readonly
+
def on_enable(self):
return
def on_enable(self):
return