Changeset 3625
- Timestamp:
- 05/06/08 12:06:02 (4 months ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
finegrainedpageauthzeditorplugin/0.11/page_authz_policy_editor/pape_admin.py
r3608 r3625 19 19 import os 20 20 import pkg_resources 21 from configobj import ConfigObj 22 #import ConfigParser 23 from StringIO import StringIO 21 24 22 25 from genshi import HTML … … 84 87 try: 85 88 for user_line in password_file: 86 group = user_line.strip()87 89 # Ignore blank lines and lines starting with # 88 90 if user_line and not user_line.startswith('#'): 89 91 user_name = user_line.split(':', 1)[0] 90 users_list.append(user_name )92 users_list.append(user_name.strip()) 91 93 finally: 92 94 password_file.close() … … 94 96 return users 95 97 98 # Get the groups and their members so they can easily be included in the 99 # groups section of the authz file. Need it as a dictionary of arrays so it be easily 100 # iterated. 101 def _get_groups_and_members(self): 102 group_file_name = self.config.get('account-manager', 'group_file') 103 if os.path.exists(group_file_name): 104 group_file = file(group_file_name) 105 try: 106 groups_dict = dict() 107 for group_line in group_file: 108 group = group_line.strip() 109 # Ignore blank lines and lines starting with # 110 if group_line and not group_line.startswith('#'): 111 group_name = group_line.split(':', 1)[0] 112 group_members = group_line.split(':', 2)[1].split(' ') 113 groups_dict[group_name] = [ x for x in [member.strip() for member in group_members] if x ] 114 finally: 115 group_file.close() 116 if len(groups_dict): 117 return groups_dict 118 else: 119 return None 120 96 121 def render_admin_panel(self, req, cat, page, path_info): 97 122 req.perm.require('TRAC_ADMIN') 98 123 authz_policy_file_name = self.config.get('authz_policy', 'authz_file') 124 group_details = self._get_groups_and_members() 99 125 # Handle the return data 100 126 if req.method == 'POST': … … 105 131 authz_policy_file.close() 106 132 107 contents = open(authz_policy_file_name).readlines() 133 authz_policy_file = ConfigObj(authz_policy_file_name) 134 135 # If there isn't a group file, don't destroy the existing entries 136 if (group_details): 137 authz_policy_file['groups'] = group_details 138 139 # This is purely to fill in the text area with the contents. 140 contents = StringIO() 141 authz_policy_file.write(contents) 142 143 144 #contents = open(authz_policy_file_name).readlines() 108 145 data = { 109 146 'file_name' : authz_policy_file_name, 110 'contents': contents ,147 'contents': contents.getvalue(), 111 148 'users' : self._get_users(), 112 149 'groups' : self._get_groups()
