Changeset 1534
- Timestamp:
- 11/10/06 22:30:32 (2 years ago)
- Files:
-
- accountmanagerplugin/trunk/acct_mgr/admin.py (modified) (1 diff)
- accountmanagerplugin/trunk/acct_mgr/api.py (modified) (1 diff)
- accountmanagerplugin/trunk/acct_mgr/http.py (added)
- accountmanagerplugin/trunk/acct_mgr/templates/account.html (modified) (1 diff)
- accountmanagerplugin/trunk/acct_mgr/templates/admin_users.html (modified) (3 diffs)
- accountmanagerplugin/trunk/acct_mgr/web_ui.py (modified) (7 diffs)
- accountmanagerplugin/trunk/setup.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
accountmanagerplugin/trunk/acct_mgr/admin.py
r1524 r1534 79 79 def _do_users(self, req): 80 80 perm = PermissionSystem(self.env) 81 data = {} 81 listing_enabled = self.account_manager.supports('get_users') 82 create_enabled = self.account_manager.supports('set_password') 83 delete_enabled = self.account_manager.supports('delete_user') 84 85 data = { 86 'listing_enabled': listing_enabled, 87 'create_enabled': create_enabled, 88 'delete_enabled': delete_enabled, 89 } 90 82 91 if req.method == 'POST': 83 92 if req.args.get('add'): 84 try: 85 _create_user(req, self.env, check_permissions=False) 86 except TracError, e: 87 data['registration_error'] = e.message 93 if create_enabled: 94 try: 95 _create_user(req, self.env, check_permissions=False) 96 except TracError, e: 97 data['registration_error'] = e.message 98 else: 99 data['registration_error'] = 'The password store does ' \ 100 'not support creating users' 88 101 elif req.args.get('remove'): 89 sel = req.args.get('sel') 90 sel = isinstance(sel, list) and sel or [sel] 91 for account in sel: 92 self.account_manager.delete_user(account) 102 if delete_enabled: 103 sel = req.args.get('sel') 104 sel = isinstance(sel, list) and sel or [sel] 105 for account in sel: 106 self.account_manager.delete_user(account) 107 else: 108 data['deletion_error'] = 'The password store does not ' \ 109 'support deleting users' 93 110 94 accounts = {} 95 for username in self.account_manager.get_users(): 96 accounts[username] = {'username': username} 111 if listing_enabled: 112 accounts = {} 113 for username in self.account_manager.get_users(): 114 accounts[username] = {'username': username} 97 115 98 for username, name, email in self.env.get_known_users():99 account = accounts.get(username)100 if account:101 account['name'] = name102 account['email'] = email116 for username, name, email in self.env.get_known_users(): 117 account = accounts.get(username) 118 if account: 119 account['name'] = name 120 account['email'] = email 103 121 104 db = self.env.get_db_cnx() 105 cursor = db.cursor() 106 cursor.execute("SELECT sid,last_visit FROM session WHERE authenticated=1") 107 for username, last_visit in cursor: 108 account = accounts.get(username) 109 if account and last_visit: 110 account['last_visit'] = format_datetime(last_visit) 122 db = self.env.get_db_cnx() 123 cursor = db.cursor() 124 cursor.execute("SELECT sid,last_visit FROM session WHERE " 125 "authenticated=1") 126 for username, last_visit in cursor: 127 account = accounts.get(username) 128 if account and last_visit: 129 account['last_visit'] = format_datetime(last_visit) 111 130 112 data['accounts'] = sorted(accounts.itervalues(),113 key=lambda acct: acct['username'])131 data['accounts'] = sorted(accounts.itervalues(), 132 key=lambda acct: acct['username']) 114 133 115 134 return 'admin_users.html', data accountmanagerplugin/trunk/acct_mgr/api.py
r1068 r1534 108 108 self._notify('deleted', user) 109 109 110 def supports(self, operation): 111 return hasattr(self.password_store, operation) 112 110 113 def password_store(self): 111 114 try: accountmanagerplugin/trunk/acct_mgr/templates/account.html
r1508 r1534 38 38 </form> 39 39 40 <form method="post" action="" 40 <form method="post" action="" py:if="account.delete_enabled" 41 41 onsubmit="return confirm('Are you sure you want to delete your account?');"> 42 42 <input type="hidden" name="action" value="delete" /> accountmanagerplugin/trunk/acct_mgr/templates/admin_users.html
r1524 r1534 13 13 <h2>Manage User Accounts</h2> 14 14 15 <form id="addaccount" class="addnew" method="post" >15 <form id="addaccount" class="addnew" method="post" py:if="create_enabled"> 16 16 <fieldset> 17 17 <div class="system-message" … … 41 41 </form> 42 42 43 <form method="post"> 43 <py:choose> 44 <div class="system-message" 45 py:when="not listing_enabled"> 46 <p>This password store does not support listing users</p> 47 </div> 48 <form method="post" py:otherwise="" py:strip="not delete_enabled"> 49 <div class="system-message" 50 py:if="deletion_error"><p>${deletion_error}</p></div> 44 51 <table class="listing" id="accountlist"> 45 52 <thead> 46 <tr><th class="sel"> </th><th>Account</th><th>Name</th><th>Email</th><th>Last Login</th></tr> 53 <tr> 54 <th class="sel" py:if="delete_enabled"> </th> 55 <th>Account</th><th>Name</th><th>Email</th><th>Last Login</th> 56 </tr> 47 57 </thead> 48 58 <tbody> 49 59 <tr py:for="account in accounts"> 50 <td><input type="checkbox" name="sel" value="${account.username}" /></td> 60 <td py:if="delete_enabled"> 61 <input type="checkbox" name="sel" value="${account.username}" /> 62 </td> 51 63 <td>${account.username}</td> 52 64 <td>${account.name}</td> … … 56 68 </tbody> 57 69 </table> 58 <div class="buttons" >70 <div class="buttons" py:if="delete_enabled"> 59 71 <input type="submit" name="remove" value="Remove selected accounts" /> 60 72 </div> 61 73 </form> 74 </py:choose> 62 75 </body> 63 76 </html> accountmanagerplugin/trunk/acct_mgr/web_ui.py
r1508 r1534 129 129 'account.') 130 130 131 def __init__(self): 132 self._write_check(log=True) 133 134 def _write_check(self, log=False): 135 writable = AccountManager(self.env).supports('set_password') 136 if not writable and log: 137 self.log.warn('AccountModule is disabled because the password ' 138 'store does not support writing.') 139 return writable 140 131 141 #INavigationContributor methods 132 142 def get_active_navigation_item(self, req): … … 134 144 135 145 def get_navigation_items(self, req): 146 if not self._write_check(): 147 return 136 148 if req.authname != 'anonymous': 137 149 yield 'metanav', 'account', Markup('<a href="%s">My Account</a>', … … 140 152 # IRequestHandler methods 141 153 def match_request(self, req): 142 return req.path_info in ('/account', '/reset_password') 154 return (req.path_info in ('/account', '/reset_password') 155 and self._write_check(log=True)) 143 156 144 157 def process_request(self, req): … … 154 167 req.redirect(self.env.href.wiki()) 155 168 action = req.args.get('action') 169 delete_enabled = AccountManager(self.env).supports('delete_user') 170 data = {'delete_enabled': delete_enabled} 156 171 if req.method == 'POST': 157 172 if action == 'change_password': 158 return self._do_change_password(req)173 data.update(self._do_change_password(req)) 159 174 elif action == 'delete': 160 return self._do_delete(req)161 return {}175 data.update(self._do_delete(req)) 176 return data 162 177 163 178 def _do_reset_password(self, req): … … 228 243 implements(INavigationContributor, IRequestHandler, ITemplateProvider) 229 244 245 def __init__(self): 246 self._write_check(log=True) 247 248 def _write_check(self, log=False): 249 writable = AccountManager(self.env).supports('set_password') 250 if not writable and log: 251 self.log.warn('RegistrationModule is disabled because the password ' 252 'store does not support writing.') 253 return writable 254 230 255 #INavigationContributor methods 231 256 … … 234 259 235 260 def get_navigation_items(self, req): 261 if not self._write_check(): 262 return 236 263 if req.authname == 'anonymous': 237 264 yield 'metanav', 'register', Markup('<a href="%s">Register</a>', … … 241 268 242 269 def match_request(self, req): 243 return req.path_info == '/register' 270 return req.path_info == '/register' and self._write_check(log=True) 244 271 245 272 def process_request(self, req): accountmanagerplugin/trunk/setup.py
r1503 r1534 29 29 'acct_mgr.web_ui = acct_mgr.web_ui', 30 30 'acct_mgr.htfile = acct_mgr.htfile', 31 'acct_mgr.http = acct_mgr.http', 31 32 'acct_mgr.api = acct_mgr.api', 32 33 'acct_mgr.admin = acct_mgr.admin',
