Changeset 990
- Timestamp:
- 07/02/06 16:22:11 (2 years ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
accountmanagerplugin/sandbox/modular/acct_mgr/api.py
r988 r990 15 15 class AccountError(TracError): 16 16 """ A generic account error. """ 17 18 class AccountActionError(AccountError): 19 """ An account action error. Generally raised on an invalid or unknown action. """ 17 20 18 21 class UnknownUserError(AccountError): … … 31 34 32 35 def add_user(self, user): 33 """Create a new user. 34 """ 36 """Create a new user. Optional function.""" 35 37 36 38 def delete_user(self, user): 37 """Deletes the user account. """39 """Deletes the user account. Optional function""" 38 40 39 41 class IPasswordStore(Interface): … … 119 121 120 122 def get_users(self): 123 """Enumerate all users in all account stores.""" 121 124 for store in self.account_stores: 122 125 for user in store.get_users(): … … 124 127 125 128 def has_user(self, user): 126 for store in self.account_stores: 127 if store.has_user(user): 128 return True 129 return False 129 """Check if the username is found in any store.""" 130 return any(self.account_stores, lambda s: s.has_user(user)) 131 132 # Account store functions 133 def can_change_password(self): 134 """Check if any password stores are writable.""" 135 return any(self.password_stores, lambda s: hasattr(s, 'set_password')) 136 137 def can_change_account(self): 138 """Check if any account stores are writable.""" 139 return any(self.account_stores, lambda s: hasattr(s, 'add_account')) 140 141 def get_mutable_stores(self): 142 """Find mutable stores. 143 Returns a tuple of (account_store, password_store), where None means no mutable stores found""" 144 acct = find(self.account_stores , lambda s: hasattr(s, 'add_account')) 145 passwd = find(self.password_stores, lambda s: hasattr(s, 'set_password')) 146 return (acct,passwd) 147 mutable_stores = property(get_mutable_stores) 130 148 131 149 # IAccountChangeListener methods accountmanagerplugin/sandbox/modular/acct_mgr/model.py
r988 r990 28 28 else: 29 29 raise AccountError, "Non-new account that doesn't exist in any store" 30 else: 31 assert not AccountSystem(self.env).has_user(self.username) 32 self.store, _ = AccountSystem(self.env).mutable_stores 30 33 31 34 def save(self, db = None): … … 37 40 old_status = cursor.fetchone() 38 41 if not old_status: 39 cursor.execute('INSERT INTO account_status (user, status) VALUES (%s, %s)', (self.username, self.status))42 cursor.execute('INSERT INTO account_status (user, status) VALUES (%s, %s)', (self.username, self.status)) 40 43 elif old_status == self.status: 41 44 return 42 45 else: 43 cursor.execute(' 46 cursor.execute('UPDATE account_status SET status=%s WHERE user=%s', (self.status, self.username)) 47 48 if handle_commit: 49 db.commit() 50 51 def create(self, password=None): 52 """Create this account.""" 53 assert self.status == 'new', 'Cannot create an existing account' 54 if self.store: 55 self.store.add_account(self.username) 56 else: 57 raise AccountActionError, 'No mutable stores available' 58 59 self.status = 'created' 60 self.save() 61 62 if password: 63 self.set_password(password) 44 64 45 65 def _get_db(db)
