Ticket #1075: ExecuteAction.patch

File ExecuteAction.patch, 2.6 KB (added by Mark Curtis, 16 years ago)

Patch that allows XMLRPC to execute an action

  • tracrpc/ticket.py

     
    66import trac.ticket.model as model
    77import trac.ticket.query as query
    88from trac.ticket.api import TicketSystem
     9from trac.ticket.web_ui import TicketModule
    910from trac.ticket.notification import TicketNotifyEmail
    1011from trac.util.datefmt import utc
    1112
     
    2728        yield ('TICKET_VIEW', ((list,), (list, str)), self.query)
    2829        yield ('TICKET_VIEW', ((list, xmlrpclib.DateTime),), self.getRecentChanges)
    2930        yield ('TICKET_VIEW', ((list, int),), self.getAvailableActions)
     31        yield ('TICKET_MODIFY', ((list, int, str, str),), self.executeAction)
    3032        yield ('TICKET_VIEW', ((list, int),), self.get)
    3133        yield ('TICKET_CREATE', ((int, str, str), (int, str, str, dict), (int, str, str, dict, bool)), self.create)
    3234        yield ('TICKET_ADMIN', ((list, int, str), (list, int, str, dict), (list, int, str, dict, bool)), self.update)
     
    6769        ticketSystem = TicketSystem(self.env)
    6870        t = model.Ticket(self.env, id)
    6971        return ticketSystem.get_available_actions(req, t)
     72   
     73    def executeAction(self, req, id, action, comment):
     74        """Executes the given action on the ticket."""
     75        ticket = model.Ticket(self.env, id)
     76        TicketModule(self.env)._populate(req, ticket)
     77        valid = TicketModule(self.env)._validate_ticket(req, ticket)
     78        actions = TicketSystem(self.env).get_available_actions(
     79                req, ticket)
     80        if action not in actions:
     81            raise TracError(_('Invalid action "%(name)s"', name=action))
     82        field_changes, problems = TicketModule(self.env).get_ticket_changes(req, ticket,
     83                                                              action)
     84        if problems:
     85            valid = False
     86            for problem in problems:
     87                add_warning(req, problem)
     88                add_warning(req,
     89                        tag(tag.p('Please review your configuration, '
     90                                  'probably starting with'),
     91                            tag.pre('[trac]\nworkflow = ...\n'),
     92                            tag.p('in your ', tag.tt('trac.ini'), '.'))
     93                        )
     94        if valid:
     95            TicketModule(self.env)._apply_ticket_changes(ticket, field_changes)
     96            ticket.save_changes(req.authname or 'anonymous', comment)
    7097
    7198    def get(self, req, id):
    7299        """ Fetch a ticket. Returns [id, time_created, time_changed, attributes]. """