diff --git a/tools/trac/plugins/newticketnotification/.gitignore b/tools/trac/plugins/newticketnotification/.gitignore deleted file mode 100644 index 4760c9b0d..000000000 --- a/tools/trac/plugins/newticketnotification/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -/build -/dist -/NewTicketNotification.egg-info diff --git a/tools/trac/plugins/ticketnotifications/.gitignore b/tools/trac/plugins/ticketnotifications/.gitignore new file mode 100644 index 000000000..20d28da13 --- /dev/null +++ b/tools/trac/plugins/ticketnotifications/.gitignore @@ -0,0 +1,3 @@ +/build +/dist +/TicketNotifications.egg-info diff --git a/tools/trac/plugins/newticketnotification/COPYING b/tools/trac/plugins/ticketnotifications/COPYING similarity index 100% rename from tools/trac/plugins/newticketnotification/COPYING rename to tools/trac/plugins/ticketnotifications/COPYING diff --git a/tools/trac/plugins/ticketnotifications/attachmentnotification/main.py b/tools/trac/plugins/ticketnotifications/attachmentnotification/main.py new file mode 100644 index 000000000..31ca8a5e9 --- /dev/null +++ b/tools/trac/plugins/ticketnotifications/attachmentnotification/main.py @@ -0,0 +1,60 @@ +# vim: set et sts=4 sw=4 encoding=utf8: +# -*- coding: utf-8 -*- + +from model import * + +from trac.attachment import IAttachmentChangeListener +from trac.core import * +from trac.ticket import Ticket +from trac.ticket.notification import TicketNotifyEmail +from trac.util.text import exception_to_unicode +from trac.web.chrome import ITemplateProvider + +class TicketAttachmentNotifyEmail(TicketNotifyEmail): + template_name = 'attachment_email.txt' + +class AttachmentTicketNotification(Component): + """Extends Trac to notify ticket subscribers when a new attachment is + created and attached to a ticket. + """ + + implements(ITemplateProvider, IAttachmentChangeListener) + + # ITemplateProvider methods + def get_htdocs_dirs(self): + """Return a list of directories with static resources (such as style + sheets, images, etc.) + + Each item in the list must be a `(prefix, abspath)` tuple. The + `prefix` part defines the path in the URL that requests to these + resources are prefixed with. + + The `abspath` is the absolute path to the directory containing the + resources on the local file system. + """ + return [] + + def get_templates_dirs(self): + """Return a list of directories containing the provided template + files. + """ + from pkg_resources import resource_filename + return [resource_filename(__name__, 'templates')] + + # IAttachmentChangeListener methods + def attachment_added(self, attachment): + if attachment.parent_realm == 'ticket': + try: + tn = TicketAttachmentNotifyEmail(self.env) + # ticket that this attachment will modify + ticket = Ticket(self.env, tkt_id=attachment.parent_id) + tn.data.update({ + 'attachment': attachment, + }) + tn.notify(ticket, newticket=False, modtime=attachment.date) + except Exception, e: + self.log.exception("Failure sending notification for attachment " + "on ticket #%s: %s" % (ticket.id, exception_to_unicode(e))) + + def attachment_deleted(self, attachment): + pass diff --git a/tools/trac/plugins/ticketnotifications/attachmentnotification/templates/attachment_email.txt b/tools/trac/plugins/ticketnotifications/attachmentnotification/templates/attachment_email.txt new file mode 100644 index 000000000..1fa5fccdd --- /dev/null +++ b/tools/trac/plugins/ticketnotifications/attachmentnotification/templates/attachment_email.txt @@ -0,0 +1,14 @@ +$ticket_body_hdr +$ticket_props + +Attachment $attachment.filename (${pretty_size(attachment.size)}) - added by ${attachment.author and format_author(attachment.author) or 'anonymous'} +#if attachment.description + +Description: +$attachment.description +#end + +-- +Ticket URL: <$ticket.link> +$project.name <${project.url or abs_href()}> +$project.descr diff --git a/tools/trac/plugins/newticketnotification/newticketnotification/admin.py b/tools/trac/plugins/ticketnotifications/newticketnotification/admin.py similarity index 100% rename from tools/trac/plugins/newticketnotification/newticketnotification/admin.py rename to tools/trac/plugins/ticketnotifications/newticketnotification/admin.py diff --git a/tools/trac/plugins/newticketnotification/newticketnotification/main.py b/tools/trac/plugins/ticketnotifications/newticketnotification/main.py similarity index 100% rename from tools/trac/plugins/newticketnotification/newticketnotification/main.py rename to tools/trac/plugins/ticketnotifications/newticketnotification/main.py diff --git a/tools/trac/plugins/newticketnotification/newticketnotification/model.py b/tools/trac/plugins/ticketnotifications/newticketnotification/model.py similarity index 100% rename from tools/trac/plugins/newticketnotification/newticketnotification/model.py rename to tools/trac/plugins/ticketnotifications/newticketnotification/model.py diff --git a/tools/trac/plugins/newticketnotification/newticketnotification/templates/newticketnotification_admin.html b/tools/trac/plugins/ticketnotifications/newticketnotification/templates/newticketnotification_admin.html similarity index 100% rename from tools/trac/plugins/newticketnotification/newticketnotification/templates/newticketnotification_admin.html rename to tools/trac/plugins/ticketnotifications/newticketnotification/templates/newticketnotification_admin.html diff --git a/tools/trac/plugins/newticketnotification/setup.cfg b/tools/trac/plugins/ticketnotifications/setup.cfg similarity index 100% rename from tools/trac/plugins/newticketnotification/setup.cfg rename to tools/trac/plugins/ticketnotifications/setup.cfg diff --git a/tools/trac/plugins/newticketnotification/setup.py b/tools/trac/plugins/ticketnotifications/setup.py similarity index 71% rename from tools/trac/plugins/newticketnotification/setup.py rename to tools/trac/plugins/ticketnotifications/setup.py index 622fa7c3a..cf5f56cf7 100755 --- a/tools/trac/plugins/newticketnotification/setup.py +++ b/tools/trac/plugins/ticketnotifications/setup.py @@ -5,11 +5,17 @@ from setuptools import setup setup( - name = 'NewTicketNotification', + name = 'TicketNotifications', version = '0.1', - packages = ['newticketnotification'], - package_data = { 'newticketnotification': ['templates/*.html'] }, + packages = [ + 'attachmentnotification', + 'newticketnotification', + ], + package_data = { + 'attachmentnotification': ['templates/*.txt'], + 'newticketnotification': ['templates/*.html'], + }, install_requires = ['trac>=0.11'], @@ -26,6 +32,7 @@ setup( entry_points = { 'trac.plugins': [ + 'attachmentnotification.main = attachmentnotification.main', 'newticketnotification.admin = newticketnotification.admin', 'newticketnotification.main = newticketnotification.main', ],