== Extension Point : ''INotificationSubscriber'' == ||'''Interface'''||''INotificationSubscriber''||'''Since'''||[wiki:TracDev/ApiChanges/1.1#INotificationSubscriber 1.1.3]|| ||'''Module'''||''trac.notification''||'''Source'''||[source:trunk/trac/notification/api.py#/INotificationSubscriber api.py]|| The ''INotificationSubscriber'' subscribes users to [TracNotification notification] events. == Purpose == Trac provides an extendible and flexible notification system. Different people are interested in different kinds of notifications. Notification subscriptions allow administrators and / or users to configure the exact rules used that trigger sending of notifications. == Usage == Implementing the interface follows the standard guidelines found in [wiki:TracDev/ComponentArchitecture] and of course [wiki:TracDev/PluginDevelopment]. The main part of this interface is the `match()` function. It returns a list of subscriptions, in the form of tuples consisting of: * `class`: The name of the Python class. (This could probably be removed.) * `distributor`: Also known as `transport`. E.g. the string `email`. See [wiki:trac.notification.api.INotificationDistributor INotificationDistributor]. * `sid`: The session ID of the subscriber. (Can be `None` if `address` is provided.) * `authenticated`: `1` for authenticated session IDs, `0` for anonymous session IDs. * `address`: The (email) address to use. (Can be `None` if `sid` is provided.) * `format`: The MIME type to be used (e.g. `text/plain` or `text/html`.) * `priority`: An integer priority. Smaller numbers have higher priority than bigger numbers. `1` is the highest priority. * `adverb`: Either the string `always` or `never`. Since more than one component can handle the same realms and categories, the priorities and adverbs are used to resolve conflicting subscriptions. The implementation can use any means to determine if a user is interested in hearing about a given event. Most check that the appropriate conditions apply and then retrieve the required information from the [wiki:TracDev/DatabaseSchema/NotificationSystem#Tablenotify_subscription notify_subscription] DB table. The subscriptions in that table are configured in a shared preferences panel that uses two other methods of this interface: The simple `description()` method returns a description string shown to the user in the preferences panel (or `None` if the plugin does use the `notify_subscriptions` DB table.) The `requires_authentication()` method allows hiding the rule from unauthenticated users. (E.g. because only authenticated users can be ticket owners.) The `default_subscriptions()` method describes any default subscriptions that automatically exist without the user configuring `subscription` DB entries in the preferences. These are also displayed on the preferences panel, but can not be directly modified there. (They usually can be overriden by non-default subscriptions.) The plugin still has to return the respective subscriptions from the `matches()` method. Default descriptions should be used when users can be determined by the event itself. For instance, ticket author has a default subscription that is controlled via trac.ini. Default subscriptions should be low priority (i.e. have a priority number much larger than `1`, like 100) so that the user can easily override them. == Examples == The following example implements a simple subscriber that can trigger notifications when a new ticket is created with a high priority level. {{{#!python from trac.core import * from trac.notification.api import INotificationSubscriber from trac.notification.model import Subscription class HighPriorityTicketNotificationSubscriber(Component): implements(INotificationSubscriber) # INotificationSubscriber methods def matches(self, event): if event.realm != 'ticket': return if event.category != 'created': return ticket = event.target if ticket['priority'] not in ('blocker', 'critical', 'major'): return klass = self.__class__.__name__ for i in Subscription.find_by_class(self.env, klass): yield i.subscription_tuple() def description(self): return "notify me when new high priority tickets are created" def requires_authentication(self): return False }}} See wiki:CookBook/Notification/Subscriptions for more examples. == Available Implementations == * [source:trunk/trac/ticket/notification.py#/TicketOwnerSubscriber trac.ticket.notification.TicketOwnerSubscriber]\\ Allows ticket owners to subscribe to (or unsubscribe from) change notifications for owned tickets. * [source:trunk/trac/ticket/notification.py#/TicketUpdaterSubscriber trac.ticket.notification.TicketUpdaterSubscriber]\\ Allows anyone to subscribe to (or unsubscribe from) change notifications for their own ticket changes. * [source:trunk/trac/ticket/notification.py#/TicketPreviousUpdatersSubscriber trac.ticket.notification.TicketPreviousUpdatersSubscriber]\\ Allows anyone to subscribe to (or unsubscribe from) change notifications for tickets they previously updated. * [source:trunk/trac/ticket/notification.py#/TicketReporterSubscriber trac.ticket.notification.TicketReporterSubscriber]\\ Allows ticket reporters to subscribe to (or unsubscribe from) change notifications for tickets they created. * [source:trunk/trac/ticket/notification.py#/CarbonCopySubscriber trac.ticket.notification.CarbonCopySubscriber]\\ Allows anyone to subscribe to (or unsubscribe from) change notifications for tickets where they are listed in CC. == Additional Information and References == * [apiref:trac.notification.api.INotificationSubscriber-class epydoc] * [apidoc:api/trac_notification#trac.notification.api.INotificationSubscriber API Reference] === History * This interface originated in ​th:AnnouncerPlugin as `IAnnouncementSubscriber`. * [wiki:TracDev/ApiChanges/1.1#INotificationSubscriber 1.1.3]: Integrated `INotificationSubscriber` in Trac as part of [wiki:TracDev/Proposals/AdvancedNotification this proposal] (#4056) * The `IAnnouncementDefaultSubscriber` from the th:AnnouncerPlugin was also folded into this interface.