Changeset 3629 for finegrainedpageauthzeditorplugin
- Timestamp:
- 05/07/08 06:30:14 (8 months ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
finegrainedpageauthzeditorplugin/0.11/page_authz_policy_editor/pape_admin.py
r3625 r3629 20 20 import pkg_resources 21 21 from configobj import ConfigObj 22 #import ConfigParser23 22 from StringIO import StringIO 24 23 … … 42 41 43 42 44 45 43 class PageAuthzPolicyEditor(Component): 46 44 … … 62 60 if 'TRAC_ADMIN' in req.perm: 63 61 yield ('accounts', _('Accounts'), 'pages', _('Page Permissions')) 64 65 def _get_groups(self):66 group_file_name = self.config.get('account-manager', 'group_file')67 groups_list = list()68 if os.path.exists(group_file_name):69 group_file = file(group_file_name)70 try:71 for group_line in group_file:72 group = group_line.strip()73 # Ignore blank lines and lines starting with #74 if group_line and not group_line.startswith('#'):75 group_name = group_line.split(':', 1)[0]76 groups_list.append('@' + group_name)77 finally:78 group_file.close()79 groups = ', '.join(sorted(groups_list))80 return groups81 62 82 63 def _get_users(self): … … 126 107 if req.method == 'POST': 127 108 if req.args.get('authz_file_contents'): 128 edited_contents = req.args.get('authz_file_contents') 109 # The data needs to be validated, otherwise duplicate 110 # entries can break things. 111 edited_contents = str(req.args.get('authz_file_contents')) 112 edited_contents_stringio = StringIO(edited_contents) 113 try: 114 test_authz_policy_dict = ConfigObj(edited_contents_stringio) 115 except: 116 raise TracError(_('Error in edited file. Re-edit and check for duplicate entries.')) 129 117 authz_policy_file = open(authz_policy_file_name, 'w') 130 authz_policy_file.write(edited_contents)118 test_authz_policy_dict.write(authz_policy_file) 131 119 authz_policy_file.close() 132 120 133 authz_policy_ file= ConfigObj(authz_policy_file_name)121 authz_policy_dict = ConfigObj(authz_policy_file_name) 134 122 135 123 # If there isn't a group file, don't destroy the existing entries 136 124 if (group_details): 137 authz_policy_ file['groups'] = group_details125 authz_policy_dict['groups'] = group_details 138 126 139 127 # This is purely to fill in the text area with the contents. 140 128 contents = StringIO() 141 authz_policy_ file.write(contents)129 authz_policy_dict.write(contents) 142 130 143 131 … … 146 134 'file_name' : authz_policy_file_name, 147 135 'contents': contents.getvalue(), 148 'users' : self._get_users(), 149 'groups' : self._get_groups() 136 'users' : self._get_users() 150 137 } 151 138 return 'page_authz_policy_editor.html', {'pages_authz': data} finegrainedpageauthzeditorplugin/0.11/page_authz_policy_editor/templates/page_authz_policy_editor.html
r3608 r3629 32 32 <div class="field">${pages_authz.users}</div> 33 33 </fieldset> 34 <fieldset> 35 <legend>Current Project Groups - specified with a leading '@'</legend> 36 <div class="field">${pages_authz.groups}</div> 37 </fieldset> 34 <p> 35 Project Groups are specified with a leading '@' 36 </p> 38 37 <div class="buttons"> 39 38 <input type="submit" value="Apply changes"/>
