Anonymous committed ac54e07

[svn r5056] check for plugin enablability and display HTML accordingly; closes #4104

Comments (0)

Files changed (5)


         data['enabled'] = system.is_enabled(hookname)
+        data['can_enable'] = system.can_enable(hookname)
         activated = [ i.__class__.__name__ for i in system.subscribers(hookname) ]
         data['snippet'] = system.render(hookname, req)


         if self.is_enabled(hookname):
             return # nothing to do
-        if not iswritable(hookname):
+        if not self.can_enable(hookname):
             return # XXX err more gracefully
         def print_hook(f):
                 if project in projects: 
                     return True
         return False
+    def can_enable(self, hookname):
+        return iswritable(self.filename(hookname))


         contingent upon enable marking the hook in such a way that it can be identified as enabled
+    def can_enable(hookname):
+        """
+        whether the hook can be set up
+        """
 class IRepositoryHookAdminContributer(Interface):
     contributes to the webadmin panel for the RepositoryHookSystem


         filename = self.filename(hookname)
             contents = file(filename).read() # check for CRLF here too?
-            return tag.textarea(contents, rows='25', cols='80', name='hook-file-contents')
+            return tag.textarea(contents, rows='25', cols='80', name='hook-file-contents', disabled=not self.can_enable(hookname) or None)
         except IOError:
-            if iswritable(filename):
+            if self.can_enable(filename):
                 text = "No %s hook file yet exists;  enable this hook to create one" % hookname
-                text = "The file, %s, is unwritable;  enabling this hook will have no effect"
+                text = "The file, %s, is unwritable;  enabling this hook will have no effect" % filename
             return text
     def process_post(self, hookname, req):


 	<div class="field">
 	    <input type="checkbox" name="enable" value="enable" 
-		   py:attrs="{'checked': enabled or None}"/>
+		   py:attrs="{'checked': enabled or None, 'disabled': not can_enable or None}"/>