| | 352 | |
|---|
| | 353 | |
|---|
| | 354 | class TicketWorkflowOpXRef(TicketWorkflowOpBase): |
|---|
| | 355 | """Adds a cross reference to another ticket |
|---|
| | 356 | |
|---|
| | 357 | <someaction>.operations = xref |
|---|
| | 358 | <someaction>.xref = "Ticket %s is related to this ticket" |
|---|
| | 359 | |
|---|
| | 360 | Don't forget to add the `TicketWorkflowOpXRef` to the workflow |
|---|
| | 361 | option in [ticket]. |
|---|
| | 362 | If there is no workflow option, the line will look like this: |
|---|
| | 363 | |
|---|
| | 364 | workflow = ConfigurableTicketWorkflow,TicketWorkflowOpXRef |
|---|
| | 365 | """ |
|---|
| | 366 | |
|---|
| | 367 | _op_name = 'xref' |
|---|
| | 368 | |
|---|
| | 369 | # ITicketActionController methods |
|---|
| | 370 | |
|---|
| | 371 | def render_ticket_action_control(self, req, ticket, action): |
|---|
| | 372 | """Returns the action control""" |
|---|
| | 373 | id = 'action_%s_xref' % action |
|---|
| | 374 | ticketnum = req.args.get(id, '') |
|---|
| | 375 | actions = ConfigurableTicketWorkflow(self.env).actions |
|---|
| | 376 | label = actions[action]['name'] |
|---|
| | 377 | hint = 'The specified ticket will be cross-referenced with this ticket' |
|---|
| | 378 | control = tag.input(type='text', id=id, name=id, value=ticketnum) |
|---|
| | 379 | return (label, control, hint) |
|---|
| | 380 | |
|---|
| | 381 | def get_ticket_changes(self, req, ticket, action): |
|---|
| | 382 | """Returns no changes.""" |
|---|
| | 383 | return {} |
|---|
| | 384 | |
|---|
| | 385 | def apply_action_side_effects(self, req, ticket, action): |
|---|
| | 386 | """Add a cross-reference comment to the other ticket""" |
|---|
| | 387 | # TODO: This needs a lot more error checking. |
|---|
| | 388 | id = 'action_%s_xref' % action |
|---|
| | 389 | ticketnum = req.args.get(id).strip('#') |
|---|
| | 390 | actions = ConfigurableTicketWorkflow(self.env).actions |
|---|
| | 391 | format_string = actions[action].get('xref', |
|---|
| | 392 | 'Ticket %s is related to this ticket') |
|---|
| | 393 | author = req.authname |
|---|
| | 394 | comment = format_string % ('#%s' % ticket.id) |
|---|
| | 395 | xticket = model.Ticket(self.env, ticketnum) |
|---|
| | 396 | # We _assume_ we have sufficient permissions to comment on the other |
|---|
| | 397 | # ticket. |
|---|
| | 398 | xticket.save_changes(author, comment) |
|---|