Changeset 1548
- Timestamp:
- 11/12/06 22:43:36 (2 years ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
accountmanagerplugin/0.10/acct_mgr/admin.py
r1502 r1548 10 10 # Author: Matthew Good <trac@matt-good.net> 11 11 12 import inspect 13 12 14 from trac.core import * 15 from trac.config import Option 13 16 from trac.perm import PermissionSystem 14 17 from trac.util import sorted … … 18 21 from acct_mgr.api import AccountManager 19 22 from acct_mgr.web_ui import _create_user 23 24 def _getoptions(cls): 25 if isinstance(cls, Component): 26 cls = cls.__class__ 27 return [(name, value) for name, value in inspect.getmembers(cls) 28 if isinstance(value, Option)] 20 29 21 30 class AccountManagerAdminPage(Component): … … 29 38 def get_admin_pages(self, req): 30 39 if req.perm.has_permission('TRAC_ADMIN'): 31 yield ('general', 'General', 'accounts', 'Accounts') 40 yield ('accounts', 'Accounts', 'config', 'Configuration') 41 yield ('accounts', 'Accounts', 'users', 'Users') 32 42 33 43 def process_admin_request(self, req, cat, page, path_info): 44 if page == 'config': 45 return self._do_config(req) 46 elif page == 'users': 47 return self._do_users(req) 48 49 def _do_config(self, req): 50 if req.method == 'POST': 51 selected_class = req.args.get('selected') 52 self.config.set('account-manager', 'password_store', selected_class) 53 selected = self.account_manager.password_store 54 for attr, option in _getoptions(selected): 55 newvalue = req.args.get('%s.%s' % (selected_class, attr)) 56 if newvalue is not None: 57 self.config.set(option.section, option.name, newvalue) 58 self.config.save() 59 try: 60 selected = self.account_manager.password_store 61 except AttributeError: 62 selected = None 63 sections = [ 64 {'name': store.__class__.__name__, 65 'classname': store.__class__.__name__, 66 'selected': store is selected, 67 'options': [ 68 {'label': attr, 69 'name': '%s.%s' % (store.__class__.__name__, attr), 70 'value': option.__get__(store, store), 71 } 72 for attr, option in _getoptions(store) 73 ], 74 } for store in self.account_manager.stores 75 ] 76 sections = sorted(sections, key=lambda i: i['name']) 77 req.hdf['sections'] = sections 78 return 'admin_accountsconfig.cs', None 79 80 def _do_users(self, req): 34 81 perm = PermissionSystem(self.env) 35 82 if req.method == 'POST': … … 66 113 key=lambda acct: acct['username']) 67 114 68 return 'admin_ accounts.cs', None115 return 'admin_users.cs', None 69 116
