#6263 Update email footer when used for monitoring email addresses

v1.0.0
closed
nobody
42cc (432)
General
2015-08-20
2013-05-21
No

Tickets & forums support monitoring emails. The email footers should reflect that. Currently a ticket email footer looks like:

Sent from sourceforge.net because you indicated interest in https://sf-dbrondsema-7020.sb.sf.net/p/testall/tickets/3/

To unsubscribe from further messages, please visit https://sf-dbrondsema-7020.sb.sf.net/auth/subscriptions/

It should look something like:

Sent from sourceforge.net because {{mailing-list-address}} is subscribed to https://sf-dbrondsema-7020.sb.sf.net/p/testall/tickets/

To unsubscribe from further messages, a project admin can change settings at https://sf-dbrondsema-7020.sb.sf.net/p/testall/admin/tickets/options  Or if this is a mailing list, you can unsubscribe from the mailing list.

Make similar changes for forums.

Related

Tickets: #6263

Discussion

  • Dave Brondsema

    Dave Brondsema - 2013-05-22
    • labels: --> 42cc
     
  • Igor Bondarenko - 2013-05-23
    • status: open --> in-progress
     
  • Igor Bondarenko - 2013-05-23

    Created #361: [#6263] Update email footer when used for monitoring email addresses (1cp)

     

    Related

    Tickets: #6263

  • Igor Bondarenko - 2013-06-05
    • status: in-progress --> code-review
     
  • Igor Bondarenko - 2013-06-05

    Closed #361. je/42cc_6263

     
    • QA: Tim Van Steenburgh
    • Milestone: forge-backlog --> forge-jun-14
     
    • status: code-review --> in-progress
     
  • While the functionality is correct, this method needs to be refactored for architectural reasons:

        def footer(self, toaddr=''):
            template = self.view.get_template('mail/footer.txt')
            params = dict(
                notification=self,
                prefix=config.get('forgemail.url', 'https://sourceforge.net'))
            tool_name = c.app.tool_label.lower()
            if (tool_name in ['discussion', 'tickets']) and toaddr and toaddr == self.ref.artifact.monitoring_email:
                template = self.view.get_template('mail/monitor_email_footer.txt')
                if tool_name == 'tickets':
                    app_url = h.absurl(c.app.url)
                    setting_url = h.absurl('%sadmin/%s/options' % (c.project.url(), c.app.config.options.mount_point))
                elif tool_name == 'discussion':
                    app_url = h.absurl(self.ref.artifact.url())
                    setting_url = h.absurl('%sadmin/%s/forums' % (c.project.url(), c.app.config.options.mount_point))
    
                params = dict(
                        email=toaddr,
                        app_url=app_url,
                        setting_url=setting_url)
            return template.render(params)
    

    In the Allura platform code, it is rarely (if ever) correct to have an if statement on tool name or type. Doing so implies that the platform has some knowledge of its tools' implementations, which should not be the case.

    I would instead suggest something like:

    # model/notification.py
    def footer(self, toaddr=''):
        return self.ref.artifact.get_mail_footer(self, toaddr)
    
    class MailFooter(object):
        view = jinja2.Environment(
            loader=jinja2.PackageLoader('allura', 'templates'),
            auto_reload=asbool(config.get('auto_reload_templates', True)),
        )
    
        @classmethod
        def _render(cls, template, **kw):
            return cls.view.get_template(template).render(kw)
    
        @classmethod
        def standard(cls, notification):
            return cls._render('mail/footer.txt',
                notification=notification,
                prefix=config.get('forgemail.url', 'https://sourceforge.net'))
    
        @classmethod
        def monitored(cls, notification, toaddr, app_url, setting_url):
            return cls._render('mail/monitor_email_footer.txt',
                email=toaddr,
                app_url=app_url,
                setting_url=setting_url)
    
    # model/artifact.py
    from .notification import MailFooter
    
    class Artifact(MappedClass):
        def get_mail_footer(self, notification, toaddr):
            return MailFooter.standard(notification)
    
    # forgetracker/model/ticket.py
    from allura.model.notification import MailFooter
    
    class Ticket(VersionedArtifact, ActivityObject, VotableArtifact):
        def get_mail_footer(self, notification, toaddr):
            if toaddr and toaddr == self.monitoring_email:
                return MailFooter.monitored(notification,
                    toaddr,
                    h.absurl(self.app.url),
                    h.absurl('{0}admin/{1}/options'.format(
                        self.project.url(),
                        self.app.config.options.mount_point)))
            return super(Ticket, self).get_mail_footer(notification, toaddr)
    
    # forgediscussion/model/forum.py
    from allura.model.notification import MailFooter
    
    class Forum(M.Discussion):
        def get_mail_footer(self, notification, toaddr):
            if toaddr and toaddr == self.monitoring_email:
                return MailFooter.monitored(notification,
                    toaddr,
                    h.absurl(self.url()),
                    h.absurl('{0}admin/{1}/forums'.format(
                        self.project.url(),
                        self.app.config.options.mount_point)))
            return super(Forum, self).get_mail_footer(notification, toaddr)
    

    That code is not tested and could probably be improved, but hopefully you get the idea.

     
  • Igor Bondarenko - 2013-06-10

    Created #373: [#6263] Mail footer refactoring (1cp)

     

    Related

    Tickets: #6263

  • Dave Brondsema

    Dave Brondsema - 2013-06-14
    • Milestone: forge-jun-14 --> forge-jun-28
     
  • Igor Bondarenko - 2013-06-17
    • status: in-progress --> code-review
     
  • Igor Bondarenko - 2013-06-17

    Closed #373. je/42cc_6263 (forced update)

     
    • status: code-review --> closed
     

Log in to post a comment.