Ticket #1069: trac-xmlrpc-ticketnitify.patch

File trac-xmlrpc-ticketnitify.patch, 3.3 kB (added by stp, 2 years ago)

Patch for email notification

  • tracrpc/api.py

    old new  
    224224        version number, second is the minor. Changes to the major version 
    225225        indicate API breaking changes, while minor version changes are simple 
    226226        additions, bug fixes, etc. """ 
    227         return [0, 1
     227        return [0, 2
  • tracrpc/ticket.py

    old new  
    55import trac.ticket.model as model 
    66import trac.ticket.query as query 
    77from trac.ticket.api import TicketSystem 
     8from trac.ticket.notification import TicketNotifyEmail 
    89 
     10import time 
    911import pydoc 
    1012import xmlrpclib 
    1113from StringIO import StringIO 
     
    2426        yield ('TICKET_VIEW', ((list, xmlrpclib.DateTime),), self.getRecentChanges) 
    2527        yield ('TICKET_VIEW', ((list, int),), self.getAvailableActions) 
    2628        yield ('TICKET_VIEW', ((list, int),), self.get) 
    27         yield ('TICKET_CREATE', ((int, str, str), (int, str, str, dict)), self.create) 
    28         yield ('TICKET_APPEND', ((list, int, str), (list, int, str, dict)), self.update) 
     29        yield ('TICKET_CREATE', ((int, str, str), (int, str, str, dict), (int, str, str, dict, bool)), self.create) 
     30        yield ('TICKET_APPEND', ((list, int, str), (list, int, str, dict), (list, int, str, dict, bool)), self.update) 
    2931        yield ('TICKET_ADMIN', ((None, int),), self.delete) 
    3032        yield ('TICKET_VIEW', ((dict, int), (dict, int, int)), self.changeLog) 
    3133        yield ('TICKET_VIEW', ((list, int),), self.listAttachments) 
     
    6971        t = model.Ticket(self.env, id) 
    7072        return (t.id, t.time_created, t.time_changed, t.values) 
    7173 
    72     def create(self, req, summary, description, attributes = {}): 
     74    def create(self, req, summary, description, attributes = {}, notify=False): 
    7375        """ Create a new ticket, returning the ticket ID. """ 
    7476        t = model.Ticket(self.env) 
    7577        t['status'] = 'new' 
     
    7981        for k, v in attributes.iteritems(): 
    8082            t[k] = v 
    8183        t.insert() 
     84 
     85        if notify: 
     86            try: 
     87                tn = TicketNotifyEmail(self.env) 
     88                tn.notify(t, newticket=True) 
     89            except Exception, e: 
     90                self.log.exception("Failure sending notification on creation " 
     91                                   "of ticket #%s: %s" % (t.id, e)) 
     92                 
    8293        return t.id 
    8394 
    84     def update(self, req, id, comment, attributes = {}): 
     95    def update(self, req, id, comment, attributes = {}, notify=False): 
    8596        """ Update a ticket, returning the new ticket in the same form as getTicket(). """ 
     97        now = int(time.time()) 
     98 
    8699        t = model.Ticket(self.env, id) 
    87100        for k, v in attributes.iteritems(): 
    88101            t[k] = v 
    89102        t.save_changes(req.authname or 'anonymous', comment) 
     103 
     104        if notify: 
     105            try: 
     106                tn = TicketNotifyEmail(self.env) 
     107                tn.notify(t, newticket=False, modtime=now) 
     108            except Exception, e: 
     109                self.log.exception("Failure sending notification on change of " 
     110                                   "ticket #%s: %s" % (t.id, e)) 
     111 
    90112        return self.get(req, t.id) 
    91113 
    92114    def delete(self, req, id):