summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimo Sorce <simo@redhat.com>2014-11-03 17:28:58 -0500
committerPatrick Uiterwijk <puiterwijk@redhat.com>2014-11-12 23:47:39 +0100
commitb07ee59ded4f926a38cd1b30d7f8de7b568840a8 (patch)
tree521c70a5c8f12a72bcb487f2f71a4659ff3161eb
parentb15a773ee9257f0102f24b6f634cf55a5948a443 (diff)
downloadipsilon-b07ee59ded4f926a38cd1b30d7f8de7b568840a8.tar.gz
ipsilon-b07ee59ded4f926a38cd1b30d7f8de7b568840a8.tar.xz
ipsilon-b07ee59ded4f926a38cd1b30d7f8de7b568840a8.zip
Return proper errors if config is read-only
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>
-rwxr-xr-xipsilon/admin/common.py50
-rwxr-xr-xipsilon/util/plugin.py8
2 files changed, 49 insertions, 9 deletions
diff --git a/ipsilon/admin/common.py b/ipsilon/admin/common.py
index 9c82142..0177402 100755
--- a/ipsilon/admin/common.py
+++ b/ipsilon/admin/common.py
@@ -23,6 +23,15 @@ from ipsilon.util.page import admin_protect
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):
@@ -61,6 +70,11 @@ class AdminPluginConfig(AdminPage):
@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()
@@ -131,6 +145,12 @@ class AdminPluginsOrder(AdminPage):
@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()
@@ -219,14 +239,27 @@ class AdminPlugins(AdminPage):
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]
+ if plugins.is_readonly:
+ msg = "Configuration is marked Read-Only"
+ raise AdminError(msg)
if plugin not in plugins.available:
msg = "Unknown plugin %s" % plugin
- return self.root_with_msg(msg, "error")
+ raise AdminError(msg)
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()
@@ -237,11 +270,10 @@ class AdminPlugins(AdminPage):
@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()
diff --git a/ipsilon/util/plugin.py b/ipsilon/util/plugin.py
index 063767c..ae98b4c 100755
--- a/ipsilon/util/plugin.py
+++ b/ipsilon/util/plugin.py
@@ -89,6 +89,10 @@ class PluginLoader(Log):
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)
@@ -129,6 +133,10 @@ class PluginObject(Log):
self._plugins = plugins
self.is_enabled = False
+ @property
+ def is_readonly(self):
+ return self._data.is_readonly
+
def on_enable(self):
return