Changeset 988

Show
Ignore:
Timestamp:
07/02/06 13:22:07 (2 years ago)
Author:
coderanger
Message:

AccountManagerPlugin:

More file changes.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • accountmanagerplugin/sandbox/modular/acct_mgr/api.py

    r706 r988  
    1111 
    1212from trac.core import * 
     13from trac.config import * 
    1314 
    14 class IPasswordStore(Interface): 
    15     """An interface for Components that provide a storage method for users and 
    16     passwords. 
    17     """ 
     15class AccountError(TracError): 
     16    """ A generic account error. """ 
    1817 
    19     def config_key(self): 
    20         """Returns a string used to identify this implementation in the config. 
    21         This password storage implementation will be used if the value of 
    22         the config property "account-manager.password_format" matches. 
    23         """ 
     18class UnknownUserError(AccountError): 
     19    """ Raise this on an action against an unknown user name. """ 
     20 
     21class IAccountStore(Interface): 
     22    """An interface for Components that provide a storage method for accounts.""" 
    2423 
    2524    def get_users(self): 
     
    3029        """Returns whether the user account exists. 
    3130        """ 
     31         
     32    def add_user(self, user): 
     33        """Create a new user. 
     34        """ 
     35 
     36    def delete_user(self, user): 
     37        """Deletes the user account.""" 
     38 
     39class IPasswordStore(Interface): 
     40    """An interface for Components that provide a storage method for passwords.""" 
    3241 
    3342    def set_password(self, user, password): 
    34         """Sets the password for the user.  This should create the user account 
    35         if it doesn't already exist. 
    36         Returns True if a new account was created, False if an existing account 
    37         was updated. 
     43        """Sets the password for the user. If you do not define this  
     44        method, it is assumed you cannot change passwords in this store. 
    3845        """ 
    3946 
     
    4249        """ 
    4350 
    44     def delete_user(self, user): 
    45         """Deletes the user account. 
    46         Returns True if the account existed and was deleted, False otherwise. 
    47         """ 
    48  
    4951class IAccountChangeListener(Interface): 
    5052    """An interface for receiving account change events. 
    5153    """ 
    5254 
    53     def user_created(self, user, password): 
     55    def user_created(self, user): 
    5456        """New user 
    5557        """ 
    5658 
    57     def user_password_changed(self, user, password): 
     59    def user_password_changed(self, user): 
    5860        """Password changed 
    5961        """ 
     
    6365        """ 
    6466 
     67class IAccountActionController(Interface): 
     68    """An interface for providing and manipluation account actions. 
     69    """ 
     70     
     71    def get_account_actions(req, account): 
     72        """ Return an interable of (action, label). 
     73        """ 
     74         
     75    def apply_account_action(req, account, action): 
     76        """ Perform the given action on an account. 
     77        """ 
     78         
     79    def intercept_account_action(req, account, action): 
     80        """ Intercept, and possibly alter, an account action. 
     81        """ 
     82 
    6583class AccountManager(Component): 
    6684    """The AccountManager component handles all user account management methods 
    67     provided by the IPasswordStore interface
     85    provided by the IAccountStore and IPasswordStore interfaces
    6886 
    6987    The methods will be handled by the underlying password storage 
     
    7492    implements(IAccountChangeListener) 
    7593 
    76     stores = ExtensionPoint(IPasswordStore) 
     94    account_store  = OrderedExtensionsOption('account-manager','account_store',IAccountStore, 
     95                                             include_missing=False, 
     96                                             doc="Which account storage backends to use.") 
     97                                              
     98    password_store = OrderedExtensionsOption('account-manager','password_store',IPasswordStore, 
     99                                             include_missing=False, 
     100                                             doc="Which password storage backends to use.") 
     101     
    77102    change_listeners = ExtensionPoint(IAccountChangeListener) 
     103    action_controllers = ExtensionPoint(IAccountActionController) 
     104     
     105    store_key = Option('account-manager','password_format', 
     106                       doc='Short-code for the desired password store') 
    78107 
    79108    # Public API 
     109     
     110    def account_actions(self, req, user): 
     111        """Return a dictionary of the form {action:(label, controller)}.""" 
     112        actions = {} 
     113        for controller in self.action_controllers: 
     114            for action, label in controller.get_account_actions(req, user) 
     115                assert action not in actions, "Action %s already registered by %s" % \ 
     116                                       (action, actions[action][1].__class__.__name__) 
     117                actions[action] = (label, controller) 
     118        return actions 
    80119 
    81120    def get_users(self): 
    82         return self.password_store.get_users() 
     121        for store in self.account_stores: 
     122            for user in store.get_users(): 
     123                yield user 
    83124 
    84125    def has_user(self, user): 
    85         return self.password_store.has_user(user) 
    86  
    87     def set_password(self, user, password): 
    88         if self.password_store.set_password(user, password): 
    89             self._notify('created', user, password) 
    90         else: 
    91             self._notify('password_changed', user, password) 
    92  
    93     def check_password(self, user, password): 
    94         return self.password_store.check_password(user, password) 
    95  
    96     def delete_user(self, user): 
    97         if self.password_store.delete_user(user): 
    98             self._notify('deleted', user) 
    99  
    100     def password_store(self): 
    101         fmt = self.config.get('account-manager', 'password_format') 
    102         for store in self.stores: 
    103             if store.config_key() == fmt: 
    104                 return store 
    105         raise TracError('No password store found.  Please configure ' 
    106                         '"account-manager.password_format" in trac.ini.') 
    107     password_store = property(password_store) 
    108  
    109     def _notify(self, func, *args): 
    110         func = 'user_' + func 
    111         for l in self.change_listeners: 
    112             getattr(l, func)(*args) 
    113  
     126        for store in self.account_stores: 
     127            if store.has_user(user): 
     128                return True 
     129        return False 
     130         
    114131    # IAccountChangeListener methods 
    115132 
     
    117134        self.log.info('Created new user: %s' % user) 
    118135 
    119     def user_password_changed(self, user, password): 
     136    def user_password_changed(self, user): 
    120137        self.log.info('Updated password for user: %s' % user) 
    121138 
  • accountmanagerplugin/sandbox/modular/acct_mgr/__init__.py

    r76 r988  
    1 from acct_mgr.api import * 
    2 from acct_mgr.htfile import * 
    3 from acct_mgr.web_ui import *