Changeset 1549

Show
Ignore:
Timestamp:
11/12/06 23:48:39 (2 years ago)
Author:
coderanger
Message:

AccountManagerPlugin:

Backporting [1534] to the 0.10 version.

Files:

Legend:

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

    r1548 r1549  
    8080    def _do_users(self, req): 
    8181        perm = PermissionSystem(self.env) 
     82        listing_enabled = self.account_manager.supports('get_users') 
     83        create_enabled = self.account_manager.supports('set_password')  
     84        delete_enabled = self.account_manager.supports('delete_user') 
     85         
     86        req.hdf['listing_enabled'] = listing_enabled 
     87        req.hdf['create_enabled'] = create_enabled 
     88        req.hdf['delete_enabled'] = delete_enabled 
     89         
    8290        if req.method == 'POST': 
    8391            if req.args.get('add'): 
    84                 try: 
    85                     _create_user(req, self.env, check_permissions=False) 
    86                 except TracError, e: 
    87                     req.hdf['registration.error'] = e.message 
     92                if create_enabled: 
     93                    try: 
     94                        _create_user(req, self.env, check_permissions=False) 
     95                    except TracError, e: 
     96                        req.hdf['registration.error'] = e.message 
     97                else: 
     98                    req.hdf['registration_error'] = 'The password store does ' \ 
     99                                                    'not support creating users' 
    88100            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) 
     101                if delete_enabled: 
     102                    sel = req.args.get('sel') 
     103                    sel = isinstance(sel, list) and sel or [sel] 
     104                    for account in sel: 
     105                        self.account_manager.delete_user(account) 
     106                else: 
     107                    req.hdf['deletion_error'] = 'The password store does not ' \ 
     108                                                'support deleting users' 
     109        if listing_enabled: 
     110            accounts = {} 
     111            for username in self.account_manager.get_users(): 
     112                accounts[username] = {'username': username} 
    93113 
    94         accounts = {} 
    95         for username in self.account_manager.get_users(): 
    96             accounts[username] = {'username': username} 
     114            for username, name, email in self.env.get_known_users(): 
     115                account = accounts.get(username) 
     116                if account: 
     117                    account['name'] = name 
     118                    account['email'] = email 
    97119 
    98         for username, name, email in self.env.get_known_users(): 
    99             account = accounts.get(username) 
    100             if account: 
    101                 account['name'] = name 
    102                 account['email'] = email 
     120            db = self.env.get_db_cnx() 
     121            cursor = db.cursor() 
     122            cursor.execute("SELECT sid,last_visit FROM session WHERE authenticated=1") 
     123            for username, last_visit in cursor: 
     124                account = accounts.get(username) 
     125                if account and last_visit: 
     126                    account['last_visit'] = format_datetime(last_visit) 
    103127 
    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) 
    111  
    112         req.hdf['accounts'] = sorted(accounts.itervalues(), 
    113                                      key=lambda acct: acct['username']) 
     128            req.hdf['accounts'] = sorted(accounts.itervalues(), 
     129                                         key=lambda acct: acct['username']) 
    114130 
    115131        return 'admin_users.cs', None 
  • accountmanagerplugin/0.10/acct_mgr/api.py

    r1068 r1549  
    108108            self._notify('deleted', user) 
    109109 
     110    def supports(self, operation): 
     111        return hasattr(self.password_store, operation) 
     112 
    110113    def password_store(self): 
    111114        try: 
  • accountmanagerplugin/0.10/acct_mgr/templates/account.cs

    r76 r1549  
    3838 </form> 
    3939 
     40 <?cs if:delete_enabled ?> 
    4041 <form method="post" action="" 
    4142       onsubmit="return confirm('Are you sure you want to delete your account?');"> 
     
    4344  <input type="submit" value="Delete account" /> 
    4445 </form> 
     46 <?cs /if ?> 
    4547 
    4648</div> 
  • accountmanagerplugin/0.10/acct_mgr/templates/admin_users.cs

    r1548 r1549  
    11<h2>Manage User Accounts</h2> 
    22 
     3<?cs if:create_enabled ?> 
    34<form id="addaccount" class="addnew" method="post"> 
    45 <fieldset> 
     
    2930 </fieldset> 
    3031</form> 
     32<?cs /if ?> 
    3133 
     34<?cs if:!listing_enabled ?> 
     35<div class="system-message"> 
     36    <p>This password store does not support listing users</p> 
     37</div> 
     38<?cs else ?> 
    3239<form method="post"> 
     40 <?cs if:deletion_error ?><div class="system-message"><p><?cs var:deletion_error ?></p></div><?cs /if ?> 
    3341 <table class="listing" id="accountlist"> 
    3442  <thead> 
    35    <tr><th class="sel">&nbsp;</th><th>Account</th><th>Name</th><th>Email</th><th>Last Login</th></tr> 
     43   <tr> 
     44    <?cs if:delete_enabled ?><th class="sel">&nbsp;</th><?cs /if ?> 
     45    <th>Account</th><th>Name</th><th>Email</th><th>Last Login</th> 
     46   </tr> 
    3647  </thead><tbody><?cs 
    3748  each:account = accounts ?> 
    3849   <tr> 
    39     <td><input type="checkbox" name="sel" value="<?cs var:account.username ?>" /></td> 
     50    <?cs if:delete_enabled ?> 
     51     <td><input type="checkbox" name="sel" value="<?cs var:account.username ?>" /></td> 
     52    <?cs /if ?> 
    4053    <td><?cs var:account.username ?></td> 
    4154        <td><?cs var:account.name ?></td> 
     
    4558  /each ?></tbody> 
    4659 </table> 
     60 <?cs if:delete_enabled ?> 
    4761 <div class="buttons"> 
    4862  <input type="submit" name="remove" value="Remove selected accounts" /> 
    4963 </div> 
     64 <?cs /if ?> 
    5065</form> 
     66<?cs /if ?> 
    5167 
    52  
  • accountmanagerplugin/0.10/acct_mgr/web_ui.py

    r1535 r1549  
    123123                                'account.') 
    124124 
     125    def __init__(self): 
     126        self._write_check(log=True)  
     127         
     128    def _write_check(self, log=False):  
     129        writable = AccountManager(self.env).supports('set_password') 
     130        if not writable and log:  
     131            self.log.warn('AccountModule is disabled because the password ' 
     132                          'store does not support writing.') 
     133        return writable  
     134 
    125135    #INavigationContributor methods 
    126136    def get_active_navigation_item(self, req): 
     
    128138 
    129139    def get_navigation_items(self, req): 
     140        if not self._write_check(): 
     141            return 
    130142        if req.authname != 'anonymous': 
    131143            yield 'metanav', 'account', Markup('<a href="%s">My Account</a>', 
     
    134146    # IRequestHandler methods 
    135147    def match_request(self, req): 
    136         return req.path_info in ('/account', '/reset_password') 
     148        return (req.path_info in ('/account', '/reset_password') 
     149                and self._write_check(log=True)) 
    137150 
    138151    def process_request(self, req): 
     
    148161            req.redirect(self.env.href.wiki()) 
    149162        action = req.args.get('action') 
     163        delete_enabled = AccountManager(self.env).supports('delete_user') 
     164        req.hdf['delete_enabled'] = delete_enabled 
    150165        if req.method == 'POST': 
    151166            if action == 'change_password': 
     
    231246 
    232247    def _enable_check(self, log=False): 
     248        writable = AccountManager(self.env).supports('set_password') 
    233249        ignore_case = auth.LoginModule(self.env).ignore_case 
    234         if log and ignore_case: 
    235             self.log.warn('RegistrationModule is disabled because ' 
    236                           'ignore_auth_case is enabled in trac.ini.  ' 
    237                           'This setting needs disabled to support ' 
    238                           'registration.') 
    239         return not ignore_case 
     250        if log: 
     251            if not writable: 
     252                self.log.warn('RegistrationModule is disabled because the ' 
     253                              'password store does not support writing.') 
     254            if ignore_case: 
     255                self.log.warn('RegistrationModule is disabled because ' 
     256                              'ignore_auth_case is enabled in trac.ini.  ' 
     257                              'This setting needs disabled to support ' 
     258                              'registration.') 
     259        return writable and not ignore_case 
    240260 
    241261    #INavigationContributor methods 
  • accountmanagerplugin/0.10/setup.py

    r1502 r1549  
    55setup( 
    66    name = 'TracAccountManager', 
    7     version = '0.1.2', 
     7    version = '0.1.3', 
    88    author = 'Matthew Good', 
    99    author_email = 'trac@matt-good.net', 
     
    2929            'acct_mgr.web_ui = acct_mgr.web_ui', 
    3030            'acct_mgr.htfile = acct_mgr.htfile', 
     31            'acct_mgr.http = acct_mgr.http', 
    3132            'acct_mgr.api = acct_mgr.api', 
    3233            'acct_mgr.admin = acct_mgr.admin',