diff options
author | Michael DeHaan <mdehaan@redhat.com> | 2008-03-31 17:09:26 -0400 |
---|---|---|
committer | Michael DeHaan <mdehaan@redhat.com> | 2008-03-31 17:09:26 -0400 |
commit | c3437479cc300683ac3ffd270114eed3dcaf4f39 (patch) | |
tree | af93eb22f4f04f05de3650d6d597f064e34f82c5 | |
parent | eee7bfa18052bb1e3d0c84421f2b425073043888 (diff) | |
download | third_party-cobbler-c3437479cc300683ac3ffd270114eed3dcaf4f39.tar.gz third_party-cobbler-c3437479cc300683ac3ffd270114eed3dcaf4f39.tar.xz third_party-cobbler-c3437479cc300683ac3ffd270114eed3dcaf4f39.zip |
Distro now instrumented with a warning panel that indicates when you probably
won't be able to edit an object.
-rw-r--r-- | cobbler/remote.py | 44 | ||||
-rw-r--r-- | cobbler/webui/CobblerWeb.py | 7 | ||||
-rw-r--r-- | webui_templates/distro_edit.tmpl | 9 |
3 files changed, 55 insertions, 5 deletions
diff --git a/cobbler/remote.py b/cobbler/remote.py index fa74e17..5e3fb83 100644 --- a/cobbler/remote.py +++ b/cobbler/remote.py @@ -593,6 +593,42 @@ class CobblerReadWriteXMLRPCInterface(CobblerXMLRPCInterface): self.log("invalid token",token=token) raise CX(_("invalid token: %s" % token)) + def __name_to_object(self,resource,name): + if resource.find("distro") != -1: + return self.api.find_distro(name) + if resource.find("profile") != -1: + return self.api.find_profile(name) + if resource.find("system") != -1: + return self.api.find_system(name) + if resource.find("repo") != -1: + return self.api.find_repo(name) + return None + + def check_access_no_fail(self,token,resource,arg1=None,arg2=None): + """ + This is called by the WUI to decide whether an element + is editable or not. It differs form check_access in that + it is supposed to /not/ log the access checks (TBA) and does + not raise exceptions. + """ + + need_remap = False + for x in [ "distro", "profile", "system", "repo" ]: + if arg1 is not None and resource.find(x) != -1: + need_remap = True + break + + if need_remap: + # we're called with an object name, but need an object + arg1 = self.__name_to_object(resource,arg1) + + try: + self.check_access(token,resource,arg1,arg2) + return True + except: + utils.log_exc(self.logger) + return False + def check_access(self,token,resource,arg1=None,arg2=None): validated = self.__validate_token(token) user = self.get_user_from_token(token) @@ -881,8 +917,8 @@ class CobblerReadWriteXMLRPCInterface(CobblerXMLRPCInterface): Allows modification of certain attributes on newly created or existing distro object handle. """ - self.check_access(token, "modify_distro", attribute, arg) obj = self.__get_object(object_id) + self.check_access(token, "modify_distro", obj, attribute) return self.__call_method(obj, attribute, arg) def modify_profile(self,object_id,attribute,arg,token): @@ -890,8 +926,8 @@ class CobblerReadWriteXMLRPCInterface(CobblerXMLRPCInterface): Allows modification of certain attributes on newly created or existing profile object handle. """ - self.check_access(token, "modify_profile", attribute, arg) obj = self.__get_object(object_id) + self.check_access(token, "modify_profile", obj, attribute) return self.__call_method(obj, attribute, arg) def modify_system(self,object_id,attribute,arg,token): @@ -899,8 +935,8 @@ class CobblerReadWriteXMLRPCInterface(CobblerXMLRPCInterface): Allows modification of certain attributes on newly created or existing system object handle. """ - self.check_access(token, "modify_system", attribute, arg) obj = self.__get_object(object_id) + self.check_access(token, "modify_system", obj, attribute) return self.__call_method(obj, attribute, arg) def modify_repo(self,object_id,attribute,arg,token): @@ -908,8 +944,8 @@ class CobblerReadWriteXMLRPCInterface(CobblerXMLRPCInterface): Allows modification of certain attributes on newly created or existing repo object handle. """ - self.check_access(token, "modify_repo", attribute, arg) obj = self.__get_object(object_id) + self.check_access(token, "modify_repo", obj, attribute) return self.__call_method(obj, attribute, arg) def remove_distro(self,name,token,recursive=1): diff --git a/cobbler/webui/CobblerWeb.py b/cobbler/webui/CobblerWeb.py index f53ba4d..b2de916 100644 --- a/cobbler/webui/CobblerWeb.py +++ b/cobbler/webui/CobblerWeb.py @@ -162,9 +162,14 @@ class CobblerWeb(object): input_distro = None if name is not None: input_distro = self.remote.get_distro(name, True) - + can_edit = self.remote.check_access_no_fail(self.token,"modify_distro",name) + else: + can_edit = self.remote.check_access_no_fail(self.token,"new_distro",None) + + return self.__render( 'distro_edit.tmpl', { 'edit' : True, + 'editable' : can_edit, 'distro': input_distro, } ) diff --git a/webui_templates/distro_edit.tmpl b/webui_templates/distro_edit.tmpl index 8b7d2cb..ccbb72f 100644 --- a/webui_templates/distro_edit.tmpl +++ b/webui_templates/distro_edit.tmpl @@ -15,6 +15,15 @@ function disablename(value) </script> #end if +#if $editable != True +<blockquote> +$editable + +WARNING: It looks like you do not have permission to make changes. +To recieve access, contact your Cobbler server administrator. +</blockquote> +#end if + <form method="POST" action="$base_url"> <fieldset id="cform"> |