| 1 | # -*- coding: utf-8 -*- |
|---|
| 2 | # |
|---|
| 3 | # Copyright (c) 2007-2012 Colin Guthrie <trac@colin.guthr.ie> |
|---|
| 4 | # Copyright (c) 2011-2016 Ryan J Ollos <ryan.j.ollos@gmail.com> |
|---|
| 5 | # All rights reserved. |
|---|
| 6 | # |
|---|
| 7 | # This software is licensed as described in the file COPYING, which |
|---|
| 8 | # you should have received as part of this distribution. |
|---|
| 9 | |
|---|
| 10 | from trac.core import Component, implements |
|---|
| 11 | from trac.ticket import ITicketChangeListener |
|---|
| 12 | |
|---|
| 13 | from manager import WorkLogManager |
|---|
| 14 | |
|---|
| 15 | |
|---|
| 16 | class WorkLogTicketObserver(Component): |
|---|
| 17 | implements(ITicketChangeListener) |
|---|
| 18 | |
|---|
| 19 | def ticket_created(self, ticket): |
|---|
| 20 | """Called when a ticket is created.""" |
|---|
| 21 | pass |
|---|
| 22 | |
|---|
| 23 | def ticket_changed(self, ticket, comment, author, old_values): |
|---|
| 24 | """Called when a ticket is modified. |
|---|
| 25 | |
|---|
| 26 | `old_values` is a dictionary containing the previous values of the |
|---|
| 27 | fields that have changed. |
|---|
| 28 | """ |
|---|
| 29 | if self.config.getbool('worklog', 'autostop') \ |
|---|
| 30 | and 'closed' == ticket['status'] \ |
|---|
| 31 | and 'status' in old_values \ |
|---|
| 32 | and 'closed' != old_values['status']: |
|---|
| 33 | mgr = WorkLogManager(self.env, self.config) |
|---|
| 34 | who, since = mgr.who_is_working_on(ticket.id) |
|---|
| 35 | if who: |
|---|
| 36 | mgr = WorkLogManager(self.env, self.config, who) |
|---|
| 37 | mgr.stop_work() |
|---|
| 38 | |
|---|
| 39 | def ticket_deleted(self, ticket): |
|---|
| 40 | """Called when a ticket is deleted.""" |
|---|
| 41 | pass |
|---|