Edgewall Software
Modify

Opened 17 years ago

Closed 6 years ago

Last modified 6 years ago

#6613 closed enhancement (fixed)

TracNotification for new tickets only

Reported by: me@… Owned by: Ryan J Ollos
Priority: normal Milestone: 1.2.3
Component: notification Version: 0.10.3
Severity: normal Keywords:
Cc: Branch:
Release Notes:

Added a notification subscriber for new tickets.

API Changes:
Internal Changes:

Description

For a project I'm working on (Warzone 2100), I'm currently setting up a Trac environment here (with an incomplete SSL certificate as of yet).

In this project we want to be sent notices on the mailinglist when new tickets are created. So I set up TracNotification to send some mails to the mailing list. The problem is though that we only want these notices on ticket creation, not when they're updated or modified. Unfortunately TracNotification didn't do this natively, so I had to extend the TicketNotifyEmail class somewhat.

The attached patch contains this extension/modification and adds a new configuration option to the [notification] section in trac.ini.

  • cc_on_newticket: Email address(es) to send notifications about newly created tickets to, addresses can only be seen when use_public_cc is enabled (Cc:).

NOTE: This patch should work with trunk as well, it's just that I wrote it for my 0.10.3 Trac installation.


Giel

Attachments (1)

trac-notification-cc_on_newticket.patch (1.1 KB ) - added by me@… 17 years ago.
adds a TracNotification option for CC on new tickets

Download all attachments as: .zip

Change History (13)

by me@…, 17 years ago

adds a TracNotification option for CC on new tickets

comment:1 by Emmanuel Blot, 17 years ago

Milestone: 0.10.5

New features won't be integrated to the maintenance branch 0.10

The TracNotification subsystem will be rewritten for 0.12.

comment:2 by anonymous, 17 years ago

For the rewrite of TracNotification I assume you mean trac.ticket.api.ITicketChangeListener as mentioned in PluginDevelopment ?

Something like that seems to be in progress @ track-hacks: AnnouncerPlugin.

Also initially I used a patch like this (which would add these mail addresses to the public Cc: list always, indepent from the user_public_cc setting. I personally think this option (i.e. independence of user_public_cc) is better, though this patch feels more like a hack to me (as it changes the interface/function prototypes):

  • notification.py

    old new  
    5555        """Email address(es) to always send notifications to,
    5656           addresses can be see by all recipients (Cc:).""")
    5757
     58    smtp_cc_on_newticket = Option('notification', 'smtp_cc_on_newticket', '',
     59        """Email address(es) to send notifications about newly
     60           created tickets to, addresses can be seen by all
     61           recipients (Cc:).""")
     62
    5863    smtp_always_bcc = Option('notification', 'smtp_always_bcc', '',
    5964        """Email address(es) to always send notifications to,
    6065           addresses do not appear publicly (Bcc:). (''since 0.10'').""")
     
    155160    longaddr_re = re.compile(r"^\s*(.*)\s+<(" + addrfmt + ")>\s*$");
    156161    nodomaddr_re = re.compile(r"[\w\d_\.\-]+")
    157162    addrsep_re = re.compile(r"[;\s,]+")
     163    newticket = None
    158164
    159165    def __init__(self, env):
    160166        Notify.__init__(self, env)
     
    192198        else:
    193199            raise TracError, 'Invalid email encoding setting: %s' % pref
    194200
    195     def notify(self, resid, subject):
     201    def notify(self, resid, subject, newticket=False):
    196202        self.subject = subject
     203        self.newticket = newticket
    197204
    198205        if not self.config.getbool('notification', 'smtp_enabled'):
    199206            return
     
    325332        bccaddrs = bccparam and \
    326333                   build_addresses(bccparam.replace(',', ' ').split()) or []
    327334
     335        if self.newticket:
     336            naccparam = self.config.get('notification', 'smtp_cc_on_newticket')
     337            accaddrs += naccparam and \
     338                        build_addresses(naccparam.replace(',', ' ').split()) or []
     339
    328340        recipients = []
    329341        (toaddrs, recipients) = remove_dup(toaddrs, recipients)
    330342        (ccaddrs, recipients) = remove_dup(ccaddrs, recipients)
  • ticket/notification.py

    old new  
    126126                self.hdf.set_unescaped('email.changes_body', changes)
    127127        self.ticket['link'] = link
    128128        self.hdf.set_unescaped('ticket', self.ticket.values)
    129         NotifyEmail.notify(self, ticket.id, subject)
     129        NotifyEmail.notify(self, ticket.id, subject, self.newticket)
    130130
    131131    def format_props(self):
    132132        tkt = self.ticket

comment:3 by Christian Boos, 17 years ago

Milestone: 0.12

See also Stephen Hansen's mail on trac-dev, Notification Architecture.

Setting the milestone tentatively to 0.12, as I think the new notification architecture should be able to allow for such requests, though not necessarily through the way proposed in the patch, rather using some more general ways, like in Stephen's proposal.

comment:4 by AH, 10 years ago

Might still be useful 7 years later with many Trac releases in between. Has it made its way into the product?

comment:5 by Ryan J Ollos, 9 years ago

Owner: Emmanuel Blot removed

comment:6 by Peter Suter, 8 years ago

Could now be implemented as a plugin (or optional component)? Untested:

from trac.core import Component, implements
from trac.notification.api import INotificationSubscriber
from trac.notification.model import Subscription

class NewTicketSubscriber(Component):
    """Subscribe to new created tickets."""

    implements(INotificationSubscriber)

    # INotificationSubscriber methods

    def matches(self, event):
        if event.realm != 'ticket':
            return
        if event.category != 'created':
            return

        klass = self.__class__.__name__
        for s in Subscription.find_by_class(self.env, klass):
            yield s.subscription_tuple()

    def description(self):
        return _("Any ticket is created")

    def default_subscriptions(self):
        return []

    def requires_authentication(self):
        return False

comment:8 by Ryan J Ollos, 8 years ago

NewTicketSubscriber works well and I agree we should add to tracopt.

comment:9 by Ryan J Ollos, 8 years ago

Or maybe just add to trac.ticket.notification. I don't see any downsides to enabling NewTicketSubscriber in a default installation.

comment:10 by Ryan J Ollos, 6 years ago

Milestone: next-major-releases1.2.3
Owner: set to Ryan J Ollos
Release Notes: modified (diff)
Status: newassigned

Proposed changes in [99a7c844f/rjollos.git].

comment:11 by Ryan J Ollos, 6 years ago

Resolution: fixed
Status: assignedclosed

Committed to 1.2-stable in r16630, merged to trunk in r16631.

comment:12 by Ryan J Ollos, 6 years ago

Release Notes: modified (diff)

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain Ryan J Ollos.
The resolution will be deleted. Next status will be 'reopened'.
to The owner will be changed from Ryan J Ollos to the specified user.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.