Changeset 592


Ignore:
Timestamp:
10/16/08 04:11:52 (5 years ago)
Author:
dgynn
Message:

only show the mailing list prefs if lists have been configured
use the default domain name for users without email address configured

Location:
trunk/plugins/mailmanplugin/mailinglists
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/plugins/mailmanplugin/mailinglists/prefs.py

    r52 r592  
    1212class MailingListPrefsPanel(Component): 
    1313    """Allows users to subscribe or unsubscribe to mailing lists that 
    14        have been registerd for a project. 
     14       have been registered for a project. 
    1515       The TracMailmanPlugin module must be set in trac.ini in order to use this. 
    1616    """ 
     
    2323    #IPreferencePanelProvider methods 
    2424    def get_preference_panels(self, req): 
    25         if req.authname and req.authname != 'anonymous': 
     25        if self._mailing_lists and req.authname and req.authname != 'anonymous': 
    2626            yield 'mailinglists', 'Mail Lists' 
    2727 
     
    3131            req.redirect(req.href.prefs('mailinglists')) 
    3232 
    33         data = {'mailinglists': self._get_mailinglists(req.session['email'])} 
     33        user_email = self._get_user_email(req) 
     34        data = {'mailinglists': self._get_mailinglists(user_email)} 
    3435     
    3536        return 'prefs_mailinglists.html', data 
     37     
     38    def _get_user_email(self, req): 
     39        address = req.session.get('email') 
     40        if not address: 
     41            domain = self.config.get('notification', 'smtp_default_domain') 
     42            if domain: 
     43                address = "%s@%s" % (req.authname, domain) 
     44         
     45        return address 
    3646 
    3747    def _get_mailinglists(self, user_email): 
     
    4757    def _do_change_subscriptions(self, req): 
    4858        # determine the email for the given user 
    49         if 'email' not in req.session: 
    50             raise TracError('You must have an email address configured in \'General\' preferences') 
    51  
    5259        mlapi = MailingListAPI(self.env) 
    5360 
    54         user_email = req.session['email'] 
     61        user_email = self._get_user_email(req) 
     62        # store the users email address in the session if it wasn't already 
     63        if user_email != req.session.get('email'): 
     64            req.session['email'] = user_email 
     65            req.session.save() 
     66         
    5567        user_fullname = req.session.get('name', req.authname) 
    5668        project_name = self.config.get('project', 'name') 
  • trunk/plugins/mailmanplugin/mailinglists/templates/prefs_mailinglists.html

    r18 r592  
    1010  </head> 
    1111  <body> 
    12     <div class="system-message" py:if="not req.session['email']"> 
    13       <h2>Warning</h2> 
    14       <p>You must configure your <a href="${req.href.prefs()}">email address</a> before subscribing to mailing lists.</p> 
    15     </div> 
    16  
    1712        <table class="listing" style="width: 60%" id="existinglists"> 
    1813                <tr> 
     
    2621                        <td>${list.listname}</td> 
    2722                </tr> 
    28                 <tr py:if="not mailinglists"> 
    29                         <td colspan="2">No mailing lists have been configured for this project.</td> 
    30                 </tr> 
    3123        </table> 
    3224        <p class="hint">Subscribe or unsubscribe from mailing lists associated with this project.</p> 
Note: See TracChangeset for help on using the changeset viewer.