Version 4 (modified by 7 years ago) ( diff ) | ,
---|
Custom Notification Subscriptions
Subscriptions allow site administrators and users to subscribe to notifications under different conditions. TracNotification customizations can often be implemented with a short plugin. Some examples of custom subscriptions are given on this page.
Subscribe to new created tickets
Some projects / users want to subscribe only to new created ticket notifications:
- Create a single file plugin that implements INotificationSubscriber:
# -*- coding: utf-8 -*- # # Copyright (C) 2017 Edgewall Software # All rights reserved. # # This software is licensed as described in the file COPYING, which # you should have received as part of this distribution. The terms # are also available at http://trac.edgewall.org/wiki/TracLicense. # # This software consists of voluntary contributions made by many # individuals. For the exact contribution history, see the revision # history and logs, available at http://trac.edgewall.org/log/. 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
- Users can manage this subscription in their preferences.
See also: #6613
Unsubscribe from ticket updates without comments
Some projects / users don't want to subscribe to ticket notifications if only some ticket properties were changed but no comment was added:
- Create a single file plugin that implements INotificationSubscriber:
# -*- coding: utf-8 -*- # # Copyright (C) 2017 Edgewall Software # All rights reserved. # # This software is licensed as described in the file COPYING, which # you should have received as part of this distribution. The terms # are also available at http://trac.edgewall.org/wiki/TracLicense. # # This software consists of voluntary contributions made by many # individuals. For the exact contribution history, see the revision # history and logs, available at http://trac.edgewall.org/log/. from trac.core import Component, implements from trac.notification.api import INotificationSubscriber from trac.notification.model import Subscription class TicketPropSubscriber(Component): """Subscribe to (or unsuubscribe from) ticket updates without comments.""" implements(INotificationSubscriber) # INotificationSubscriber methods def matches(self, event): if event.realm != 'ticket': return if event.category != 'changed': return if event.comment != '': return klass = self.__class__.__name__ for s in Subscription.find_by_class(self.env, klass): yield s.subscription_tuple() def description(self): return _("Only ticket props are changed") def default_subscriptions(self): return [] def requires_authentication(self): return False
- Users can manage this subscription in their preferences. Add a rule to
Never notify: Only ticket props are changed
to unsubscribe from ticket notifications where only ticket props are changed.
See also: #10326
Subscribe to ticket changes with blocker severity
Some projects / users want to subscribe only to ticket notifications where certain ticket field values are set. For example maybe some users are interested in tickets with blocker severity:
- Create a single file plugin that implements INotificationSubscriber:
# -*- coding: utf-8 -*- # # Copyright (C) 2017 Edgewall Software # All rights reserved. # # This software is licensed as described in the file COPYING, which # you should have received as part of this distribution. The terms # are also available at http://trac.edgewall.org/wiki/TracLicense. # # This software consists of voluntary contributions made by many # individuals. For the exact contribution history, see the revision # history and logs, available at http://trac.edgewall.org/log/. from trac.core import Component, implements from trac.notification.api import INotificationSubscriber from trac.notification.model import Subscription class BlockerSeverityTicketSubscriber(Component): """Subscribe to tickets with severity blocker.""" implements(INotificationSubscriber) # INotificationSubscriber methods def matches(self, event): if event.realm != 'ticket': return ticket = event.target if target['severity'] != 'blocker': 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
- Users can manage this subscription in their preferences.
Variations
- Change
'severity'
to'priority'
or some other ticket field, and / or'blocker'
to some other value. - Only consider changes to a specific ticket field by checking for example
event.changes['fields']['severity']['new']
. - Create complex combinations of multiple ticket field with boolean operators
and
,or
,not
etc.
See also: #11758