Changeset 1524

Show
Ignore:
Timestamp:
11/10/06 18:54:52 (2 years ago)
Author:
mgood
Message:

AccountManagerPlugin:

add a configuration panel for selecting the password storage format and setting its options (fixes #542)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • accountmanagerplugin/trunk/acct_mgr/admin.py

    r1503 r1524  
    1010# Author: Matthew Good <trac@matt-good.net> 
    1111 
     12import inspect 
     13 
    1214from trac.core import * 
     15from trac.config import Option 
    1316from trac.perm import PermissionSystem 
    1417from trac.util import sorted 
     
    1821from acct_mgr.api import AccountManager 
    1922from acct_mgr.web_ui import _create_user 
     23 
     24def _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)] 
    2029 
    2130class AccountManagerAdminPage(Component): 
     
    2938    def get_admin_panels(self, req): 
    3039        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') 
    3242 
    3343    def render_admin_panel(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        return 'admin_accountsconfig.html', {'sections': sections} 
     78 
     79    def _do_users(self, req): 
    3480        perm = PermissionSystem(self.env) 
    3581        data = {} 
     
    67113                                  key=lambda acct: acct['username']) 
    68114 
    69         return 'admin_accounts.html', data 
    70  
     115        return 'admin_users.html', data