| 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 | |
|---|
| 12 | from manager import WorkLogManager |
|---|
| 13 | from tracrpc.api import IXMLRPCHandler |
|---|
| 14 | |
|---|
| 15 | |
|---|
| 16 | class WorlLogRPC(Component): |
|---|
| 17 | """Interface to the WorklogPlugin.""" |
|---|
| 18 | implements(IXMLRPCHandler) |
|---|
| 19 | |
|---|
| 20 | def __init__(self): |
|---|
| 21 | pass |
|---|
| 22 | |
|---|
| 23 | def xmlrpc_namespace(self): |
|---|
| 24 | return 'worklog' |
|---|
| 25 | |
|---|
| 26 | def xmlrpc_methods(self): |
|---|
| 27 | yield 'WIKI_VIEW', ((int,),), self.getRPCVersionSupported |
|---|
| 28 | yield 'WIKI_VIEW', ((str, int),), self.startWork |
|---|
| 29 | yield 'WIKI_VIEW', ((str,), (str, str), (str, str, int),), self.stopWork |
|---|
| 30 | yield 'WIKI_VIEW', ((dict,), (dict, str),), self.getLatestTask |
|---|
| 31 | yield 'WIKI_VIEW', ((dict,), (dict, str),), self.getActiveTask |
|---|
| 32 | yield 'WIKI_VIEW', ((str, int,),), self.whoIsWorkingOn |
|---|
| 33 | yield 'WIKI_VIEW', ((str, int,),), self.whoLastWorkedOn |
|---|
| 34 | |
|---|
| 35 | def getRPCVersionSupported(self, req): |
|---|
| 36 | """Returns 1 with this version of the Work Log XMLRPC API.""" |
|---|
| 37 | return 1 |
|---|
| 38 | |
|---|
| 39 | def startWork(self, req, ticket): |
|---|
| 40 | """Start work on a ticket. Returns the string 'OK' on success |
|---|
| 41 | or an explanation on error (requires authentication). |
|---|
| 42 | """ |
|---|
| 43 | mgr = WorkLogManager(self.env, self.config, req.authname) |
|---|
| 44 | if mgr.start_work(ticket): |
|---|
| 45 | return 'OK' |
|---|
| 46 | return mgr.get_explanation() |
|---|
| 47 | |
|---|
| 48 | def stopWork(self, req, comment='', stoptime=None): |
|---|
| 49 | """Stops work. Returns the string 'OK' on success or an explanation |
|---|
| 50 | on error (requires authentication, stoptime is seconds since epoch). |
|---|
| 51 | """ |
|---|
| 52 | mgr = WorkLogManager(self.env, self.config, req.authname) |
|---|
| 53 | if mgr.stop_work(stoptime, comment): |
|---|
| 54 | return 'OK' |
|---|
| 55 | return mgr.get_explanation() |
|---|
| 56 | |
|---|
| 57 | def getLatestTask(self, req, username=None): |
|---|
| 58 | """Returns a structure representing the info about the latest |
|---|
| 59 | task. |
|---|
| 60 | """ |
|---|
| 61 | if username: |
|---|
| 62 | mgr = WorkLogManager(self.env, self.config, username) |
|---|
| 63 | else: |
|---|
| 64 | mgr = WorkLogManager(self.env, self.config, req.authname) |
|---|
| 65 | return mgr.get_latest_task() |
|---|
| 66 | |
|---|
| 67 | def getActiveTask(self, req, username=None): |
|---|
| 68 | """Returns a structure representing the info about the active |
|---|
| 69 | task (identical to getLatestTask but does not return anything |
|---|
| 70 | if the work has stopped). |
|---|
| 71 | """ |
|---|
| 72 | if username: |
|---|
| 73 | mgr = WorkLogManager(self.env, self.config, username) |
|---|
| 74 | else: |
|---|
| 75 | mgr = WorkLogManager(self.env, self.config, req.authname) |
|---|
| 76 | return mgr.get_active_task() |
|---|
| 77 | |
|---|
| 78 | def whoIsWorkingOn(self, req, ticket): |
|---|
| 79 | """Returns the username of the person currently working on the |
|---|
| 80 | given ticket. |
|---|
| 81 | """ |
|---|
| 82 | mgr = WorkLogManager(self.env, self.config, req.authname) |
|---|
| 83 | (who, when) = mgr.who_is_working_on(ticket) |
|---|
| 84 | return who |
|---|
| 85 | |
|---|
| 86 | def whoLastWorkedOn(self, req, ticket): |
|---|
| 87 | """Returns the username of the person last worked on the |
|---|
| 88 | given ticket. |
|---|
| 89 | """ |
|---|
| 90 | mgr = WorkLogManager(self.env, self.config, req.authname) |
|---|
| 91 | return mgr.who_last_worked_on(ticket) |
|---|