Commits

ejucovy committed a6a85b6

wire up the view to collect the form; use JSON for the form elements instead of hoping the pipe character is unused by the content; add a PSM

  • Participants
  • Parent commits 736874f

Comments (0)

Files changed (2)

File trac_gitolite/conf_writer.py

+import json
 import pkg_resources
 
 from trac.admin import IAdminPanelProvider
 from trac.config import Option, BoolOption
 from trac.util.translation import _
 from trac.web.chrome import ITemplateProvider
+from trac.web.chrome import add_notice
 
 from trac_gitolite import utils
 
     def render_admin_panel(self, req, category, page, path_info):
         req.perm.require('VERSIONCONTROL_ADMIN')
 
+        if req.method == 'POST':
+            perms = {}
+            for setting in req.args:
+                try:
+                    setting = json.loads(setting)
+                except ValueError:
+                    continue
+                if not isinstance(setting, dict) or 'perm' not in setting or 'user' not in setting or 'repo' not in setting:
+                    continue
+                repo = setting['repo']; perm = setting['perm']; user = setting['user']
+                if repo not in perms:
+                    perms[repo] = {}
+                if perm not in perms[repo]:
+                    perms[repo][perm] = []
+                if user not in perms[repo][perm]:
+                    perms[repo][perm].append(user)
+
+            ## do the actual saving of the file here
+
+            add_notice(req, _('The permissions have been updated.'))
+            req.redirect(req.href.admin(category, page))
+
         perms = self.read_config()
-
-        if req.method == 'POST':
-            req.redirect(req.href.admin(category, page))
         
         flattened_perms = set()
         for p in perms.values():

File trac_gitolite/templates/admin_repository_permissions.html

 
   <body>
     <h2>Manage Repository Permissions</h2>
+    <form method="post" action="">
 
     <table class="listing">
       <thead>
 	  <td>$repo</td>
 	  <td py:for="user in users">
 	    <label py:for="perm in sort_perms(repo_perms.keys())"
-		   for="$repo|$user|$perm"
+		   for='{"repo": "$repo", "user": "$user", "perm": "$perm"}'
 		   style="border: 1px solid lightgray; border-radius: 5px; padding: 2px; margin-right: 2px">
 	      $perm
-	      <input type="checkbox" name="$repo|$user|$perm" id="$repo|$user|$perm" 
+	      <input type="checkbox" 
+		     name='{"repo": "$repo", "user": "$user", "perm": "$perm"}'
+		     id='{"repo": "$repo", "user": "$user", "perm": "$perm"}'
 		     checked="checked" py:if="user in repo_perms[perm]" />
-	      <input type="checkbox" name="$repo|$user|$perm" id="$repo|$user|$perm" 
+	      <input type="checkbox" 
+		     name='{"repo": "$repo", "user": "$user", "perm": "$perm"}'
+		     id='{"repo": "$repo", "user": "$user", "perm": "$perm"}'
 		     py:if="user not in repo_perms[perm]" />
 	    </label>
 	  </td>
     <div class="buttons">
       <input type="submit" value="${_('Update repository permissions')}" />
     </div>
+
+    </form>
   </body>
 
 </html>