Show
Ignore:
Timestamp:
05/07/08 06:30:14 (8 months ago)
Author:
robert_martin
Message:

Includes a basic check of the file prior to saving. Group information
not displayed on the web page, as it is automatically included in the
file.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • finegrainedpageauthzeditorplugin/0.11/page_authz_policy_editor/pape_admin.py

    r3625 r3629  
    2020import pkg_resources 
    2121from configobj import ConfigObj 
    22 #import ConfigParser 
    2322from StringIO import StringIO 
    2423 
     
    4241 
    4342 
    44  
    4543class PageAuthzPolicyEditor(Component): 
    4644 
     
    6260        if 'TRAC_ADMIN' in req.perm: 
    6361            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 groups 
    8162 
    8263    def _get_users(self): 
     
    126107        if req.method == 'POST': 
    127108             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.')) 
    129117                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
    131119                authz_policy_file.close() 
    132120 
    133         authz_policy_file = ConfigObj(authz_policy_file_name) 
     121        authz_policy_dict = ConfigObj(authz_policy_file_name) 
    134122 
    135123        # If there isn't a group file, don't destroy the existing entries 
    136124        if (group_details): 
    137             authz_policy_file['groups'] = group_details 
     125            authz_policy_dict['groups'] = group_details 
    138126 
    139127        # This is purely to fill in the text area with the contents. 
    140128        contents = StringIO() 
    141         authz_policy_file.write(contents) 
     129        authz_policy_dict.write(contents) 
    142130 
    143131 
     
    146134            'file_name' : authz_policy_file_name, 
    147135            'contents': contents.getvalue(), 
    148             'users' : self._get_users(), 
    149             'groups' : self._get_groups() 
     136            'users' : self._get_users() 
    150137        } 
    151138        return 'page_authz_policy_editor.html', {'pages_authz': data} 
  • finegrainedpageauthzeditorplugin/0.11/page_authz_policy_editor/templates/page_authz_policy_editor.html

    r3608 r3629  
    3232        <div class="field">${pages_authz.users}</div> 
    3333      </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> 
    3837      <div class="buttons"> 
    3938        <input type="submit" value="Apply changes"/>