| | 301 | |
|---|
| | 302 | |
|---|
| | 303 | class TicketWorkflowOpTriage(TicketWorkflowOpBase): |
|---|
| | 304 | """Action to split a workflow based on a field |
|---|
| | 305 | |
|---|
| | 306 | <someaction> = somestatus -> * |
|---|
| | 307 | <someaction>.operations = triage |
|---|
| | 308 | <someaction>.triage_field = type |
|---|
| | 309 | <someaction>.traige_split = defect -> new_defect, task -> new_task, enhancement -> new_enhancement |
|---|
| | 310 | |
|---|
| | 311 | Don't forget to add the `TicketWorkflowOpTriage` to the workflow option in |
|---|
| | 312 | [ticket]. |
|---|
| | 313 | If there is no workflow option, the line will look like this: |
|---|
| | 314 | |
|---|
| | 315 | workflow = ConfigurableTicketWorkflow,TicketWorkflowOpTriage |
|---|
| | 316 | """ |
|---|
| | 317 | |
|---|
| | 318 | _op_name = 'triage' |
|---|
| | 319 | |
|---|
| | 320 | # ITicketActionController methods |
|---|
| | 321 | |
|---|
| | 322 | def render_ticket_action_control(self, req, ticket, action): |
|---|
| | 323 | """Returns the action control""" |
|---|
| | 324 | actions = ConfigurableTicketWorkflow(self.env).actions |
|---|
| | 325 | label = actions[action]['name'] |
|---|
| | 326 | new_status = self._new_status(ticket, action) |
|---|
| | 327 | if new_status != ticket['status']: |
|---|
| | 328 | hint = 'The status will change.' |
|---|
| | 329 | else: |
|---|
| | 330 | hint = '' |
|---|
| | 331 | control = tag('') |
|---|
| | 332 | return (label, control, hint) |
|---|
| | 333 | |
|---|
| | 334 | def get_ticket_changes(self, req, ticket, action): |
|---|
| | 335 | """Returns the change of status.""" |
|---|
| | 336 | return {'status': self._new_status(ticket, action)} |
|---|
| | 337 | |
|---|
| | 338 | def _new_status(self, ticket, action): |
|---|
| | 339 | """Determines the new status""" |
|---|
| | 340 | field = self.config.get('ticket-workflow', |
|---|
| | 341 | action + '.triage_field').strip() |
|---|
| | 342 | transitions = self.config.get('ticket-workflow', |
|---|
| | 343 | action + '.triage_split').strip() |
|---|
| | 344 | for transition in [x.strip() for x in transitions.split(',')]: |
|---|
| | 345 | value, status = [y.strip() for y in transition.split('->')] |
|---|
| | 346 | if value == ticket[field].strip(): |
|---|
| | 347 | break |
|---|
| | 348 | else: |
|---|
| | 349 | self.env.log.error("Bad configuration for 'triage' operation in action '%s'" % action) |
|---|
| | 350 | status = 'new' |
|---|
| | 351 | return status |
|---|