Anonymous avatar Anonymous committed ac54e07

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

Comments (0)

Files changed (5)

0.11/repository_hook_system/admin.py

             
 
         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)
 

0.11/repository_hook_system/filesystemhooks.py

         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))

0.11/repository_hook_system/interface.py

         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

0.11/repository_hook_system/svnhooksystem.py

         filename = self.filename(hookname)
         try:
             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
             else:
-                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):

0.11/repository_hook_system/templates/repositoryhooks.html

 	<div class="field">
 	  <b>Enabled:</b>
 	    <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}"/>
 	</div>
 	<div>
 	  ${snippet}
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.