2013-10-09 19:50:17 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
#
|
2023-01-28 10:00:43 +00:00
|
|
|
# Copyright (C) 2007-2023 Edgewall Software
|
2013-10-09 19:50:17 +00:00
|
|
|
# Copyright (C) 2007 Eli Carter <retracile@gmail.com>
|
|
|
|
|
# All rights reserved.
|
|
|
|
|
#
|
|
|
|
|
# This software is licensed as described in the file COPYING, which
|
|
|
|
|
# you should have received as part of this distribution. The terms
|
2019-08-08 00:01:21 +00:00
|
|
|
# are also available at https://trac.edgewall.org/wiki/TracLicense.
|
2013-10-09 19:50:17 +00:00
|
|
|
#
|
|
|
|
|
# This software consists of voluntary contributions made by many
|
|
|
|
|
# individuals. For the exact contribution history, see the revision
|
2019-08-08 00:01:21 +00:00
|
|
|
# history and logs, available at https://trac.edgewall.org/.
|
2013-10-09 19:50:17 +00:00
|
|
|
|
2018-04-21 18:54:51 +00:00
|
|
|
from collections import OrderedDict
|
|
|
|
|
|
2014-04-23 23:32:11 +00:00
|
|
|
from trac.core import Component, implements
|
|
|
|
|
from trac.perm import IPermissionRequestor
|
2007-05-19 17:19:54 +00:00
|
|
|
from trac.ticket.api import ITicketActionController
|
|
|
|
|
from trac.ticket.default_workflow import ConfigurableTicketWorkflow
|
2018-04-21 18:54:51 +00:00
|
|
|
from trac.util import to_list
|
2017-02-01 10:15:21 +00:00
|
|
|
from trac.util.html import tag
|
WorkFlow: Merge workflow to trunk using svnmerge.py.
5012-5168,5171-5198,5201-5253,5255-5289,5291-5292,5294-5299,5301-5302,5304-5314,5316-5356,5358-5360,5362-5373,5375-5377
git-svn-id: http://trac.edgewall.org/intertrac/log:/trunk@5378 af82e41b-90c4-0310-8c96-b1721e28e2e2
2007-05-11 16:15:21 +00:00
|
|
|
|
2007-12-13 10:51:05 +00:00
|
|
|
revision = "$Rev$"
|
|
|
|
|
url = "$URL$"
|
|
|
|
|
|
2018-04-21 18:54:51 +00:00
|
|
|
|
WorkFlow: Merge workflow to trunk using svnmerge.py.
5012-5168,5171-5198,5201-5253,5255-5289,5291-5292,5294-5299,5301-5302,5304-5314,5316-5356,5358-5360,5362-5373,5375-5377
git-svn-id: http://trac.edgewall.org/intertrac/log:/trunk@5378 af82e41b-90c4-0310-8c96-b1721e28e2e2
2007-05-11 16:15:21 +00:00
|
|
|
class CodeReviewActionController(Component):
|
|
|
|
|
"""Support for simple code reviews.
|
|
|
|
|
|
|
|
|
|
The action that supports the `code_review` operation will present
|
|
|
|
|
an extra choice for the review decision. Depending on that decision,
|
|
|
|
|
a specific state will be selected.
|
|
|
|
|
|
|
|
|
|
Example (from the enterprise-review-workflow.ini):
|
2018-04-21 18:54:51 +00:00
|
|
|
{{{#!ini
|
|
|
|
|
request_review = in_work -> in_review
|
WorkFlow: Merge workflow to trunk using svnmerge.py.
5012-5168,5171-5198,5201-5253,5255-5289,5291-5292,5294-5299,5301-5302,5304-5314,5316-5356,5358-5360,5362-5373,5375-5377
git-svn-id: http://trac.edgewall.org/intertrac/log:/trunk@5378 af82e41b-90c4-0310-8c96-b1721e28e2e2
2007-05-11 16:15:21 +00:00
|
|
|
review = in_review -> *
|
|
|
|
|
review.operations = code_review
|
|
|
|
|
review.code_review =
|
|
|
|
|
approve -> in_QA,
|
|
|
|
|
approve as noted -> post_review,
|
|
|
|
|
request changes -> in_work
|
2012-06-22 09:42:00 +00:00
|
|
|
}}}
|
2018-04-21 18:54:51 +00:00
|
|
|
|
WorkFlow: Merge workflow to trunk using svnmerge.py.
5012-5168,5171-5198,5201-5253,5255-5289,5291-5292,5294-5299,5301-5302,5304-5314,5316-5356,5358-5360,5362-5373,5375-5377
git-svn-id: http://trac.edgewall.org/intertrac/log:/trunk@5378 af82e41b-90c4-0310-8c96-b1721e28e2e2
2007-05-11 16:15:21 +00:00
|
|
|
Don't forget to add the `CodeReviewActionController` to the workflow
|
2018-04-21 18:54:51 +00:00
|
|
|
option in the `[ticket]` section in TracIni. When added to the default
|
|
|
|
|
value of `workflow`, the line will look like this:
|
|
|
|
|
{{{#!ini
|
2007-05-19 15:38:21 +00:00
|
|
|
workflow = ConfigurableTicketWorkflow,CodeReviewActionController
|
2012-06-22 09:42:00 +00:00
|
|
|
}}}
|
WorkFlow: Merge workflow to trunk using svnmerge.py.
5012-5168,5171-5198,5201-5253,5255-5289,5291-5292,5294-5299,5301-5302,5304-5314,5316-5356,5358-5360,5362-5373,5375-5377
git-svn-id: http://trac.edgewall.org/intertrac/log:/trunk@5378 af82e41b-90c4-0310-8c96-b1721e28e2e2
2007-05-11 16:15:21 +00:00
|
|
|
"""
|
|
|
|
|
|
2018-04-21 18:54:51 +00:00
|
|
|
implements(IPermissionRequestor, ITicketActionController)
|
WorkFlow: Merge workflow to trunk using svnmerge.py.
5012-5168,5171-5198,5201-5253,5255-5289,5291-5292,5294-5299,5301-5302,5304-5314,5316-5356,5358-5360,5362-5373,5375-5377
git-svn-id: http://trac.edgewall.org/intertrac/log:/trunk@5378 af82e41b-90c4-0310-8c96-b1721e28e2e2
2007-05-11 16:15:21 +00:00
|
|
|
|
|
|
|
|
# IPermissionRequestor methods
|
2013-01-13 15:18:06 +00:00
|
|
|
|
WorkFlow: Merge workflow to trunk using svnmerge.py.
5012-5168,5171-5198,5201-5253,5255-5289,5291-5292,5294-5299,5301-5302,5304-5314,5316-5356,5358-5360,5362-5373,5375-5377
git-svn-id: http://trac.edgewall.org/intertrac/log:/trunk@5378 af82e41b-90c4-0310-8c96-b1721e28e2e2
2007-05-11 16:15:21 +00:00
|
|
|
def get_permission_actions(self):
|
|
|
|
|
return ['TICKET_REVIEW']
|
|
|
|
|
|
|
|
|
|
# ITicketActionController methods
|
2013-01-13 15:18:06 +00:00
|
|
|
|
WorkFlow: Merge workflow to trunk using svnmerge.py.
5012-5168,5171-5198,5201-5253,5255-5289,5291-5292,5294-5299,5301-5302,5304-5314,5316-5356,5358-5360,5362-5373,5375-5377
git-svn-id: http://trac.edgewall.org/intertrac/log:/trunk@5378 af82e41b-90c4-0310-8c96-b1721e28e2e2
2007-05-11 16:15:21 +00:00
|
|
|
def get_ticket_actions(self, req, ticket):
|
2007-05-20 09:53:41 +00:00
|
|
|
# The review action is available in those status where it has been
|
WorkFlow: Merge workflow to trunk using svnmerge.py.
5012-5168,5171-5198,5201-5253,5255-5289,5291-5292,5294-5299,5301-5302,5304-5314,5316-5356,5358-5360,5362-5373,5375-5377
git-svn-id: http://trac.edgewall.org/intertrac/log:/trunk@5378 af82e41b-90c4-0310-8c96-b1721e28e2e2
2007-05-11 16:15:21 +00:00
|
|
|
# configured, for those users who have the TICKET_REVIEW permission, as
|
|
|
|
|
# long as they are not the owner of the ticket (you can't review your
|
2018-04-21 18:54:51 +00:00
|
|
|
# own work).
|
WorkFlow: Merge workflow to trunk using svnmerge.py.
5012-5168,5171-5198,5201-5253,5255-5289,5291-5292,5294-5299,5301-5302,5304-5314,5316-5356,5358-5360,5362-5373,5375-5377
git-svn-id: http://trac.edgewall.org/intertrac/log:/trunk@5378 af82e41b-90c4-0310-8c96-b1721e28e2e2
2007-05-11 16:15:21 +00:00
|
|
|
actions_we_handle = []
|
2007-12-12 14:10:45 +00:00
|
|
|
if req.authname != ticket['owner'] and \
|
|
|
|
|
'TICKET_REVIEW' in req.perm(ticket.resource):
|
2007-05-19 15:38:21 +00:00
|
|
|
controller = ConfigurableTicketWorkflow(self.env)
|
2007-05-20 09:53:41 +00:00
|
|
|
actions_we_handle = controller.get_actions_by_operation_for_req(
|
|
|
|
|
req, ticket, 'code_review')
|
2014-11-04 21:28:09 +00:00
|
|
|
self.log.debug('code review handles actions: %r', actions_we_handle)
|
WorkFlow: Merge workflow to trunk using svnmerge.py.
5012-5168,5171-5198,5201-5253,5255-5289,5291-5292,5294-5299,5301-5302,5304-5314,5316-5356,5358-5360,5362-5373,5375-5377
git-svn-id: http://trac.edgewall.org/intertrac/log:/trunk@5378 af82e41b-90c4-0310-8c96-b1721e28e2e2
2007-05-11 16:15:21 +00:00
|
|
|
return actions_we_handle
|
|
|
|
|
|
2007-05-19 13:20:22 +00:00
|
|
|
def get_all_status(self):
|
2007-05-20 09:53:41 +00:00
|
|
|
all_status = set()
|
2007-05-19 15:38:21 +00:00
|
|
|
controller = ConfigurableTicketWorkflow(self.env)
|
2018-04-21 18:54:51 +00:00
|
|
|
for weight, action \
|
|
|
|
|
in controller.get_actions_by_operation('code_review'):
|
|
|
|
|
review_options = self._get_review_options(action)
|
2020-12-19 03:04:54 +00:00
|
|
|
all_status.update(iter(review_options.values()))
|
2007-05-20 09:53:41 +00:00
|
|
|
return all_status
|
WorkFlow: Merge workflow to trunk using svnmerge.py.
5012-5168,5171-5198,5201-5253,5255-5289,5291-5292,5294-5299,5301-5302,5304-5314,5316-5356,5358-5360,5362-5373,5375-5377
git-svn-id: http://trac.edgewall.org/intertrac/log:/trunk@5378 af82e41b-90c4-0310-8c96-b1721e28e2e2
2007-05-11 16:15:21 +00:00
|
|
|
|
|
|
|
|
def render_ticket_action_control(self, req, ticket, action):
|
2018-04-21 18:54:51 +00:00
|
|
|
id, selected = self._get_selected(req, action)
|
2007-05-19 14:58:12 +00:00
|
|
|
|
2007-05-20 09:53:41 +00:00
|
|
|
review_options = self._get_review_options(action)
|
2007-05-19 15:38:21 +00:00
|
|
|
actions = ConfigurableTicketWorkflow(self.env).actions
|
2007-05-20 09:53:41 +00:00
|
|
|
|
2014-12-01 06:15:00 +00:00
|
|
|
label = actions[action]['label']
|
2007-05-20 09:53:41 +00:00
|
|
|
control = tag(["as: ",
|
2018-04-21 18:54:51 +00:00
|
|
|
tag.select([
|
|
|
|
|
tag.option(option,
|
|
|
|
|
selected=(option == selected or None))
|
|
|
|
|
for option in review_options],
|
|
|
|
|
name=id, id=id)])
|
|
|
|
|
if selected:
|
|
|
|
|
new_status = self._get_new_status(req, action, review_options)
|
2007-05-20 09:53:41 +00:00
|
|
|
hint = "Next status will be '%s'" % new_status
|
|
|
|
|
else:
|
|
|
|
|
hint = "Next status will be one of " + \
|
2020-12-19 03:04:54 +00:00
|
|
|
', '.join("'%s'" % st for st in review_options.values())
|
2016-07-28 05:20:13 +00:00
|
|
|
return label, control, hint
|
WorkFlow: Merge workflow to trunk using svnmerge.py.
5012-5168,5171-5198,5201-5253,5255-5289,5291-5292,5294-5299,5301-5302,5304-5314,5316-5356,5358-5360,5362-5373,5375-5377
git-svn-id: http://trac.edgewall.org/intertrac/log:/trunk@5378 af82e41b-90c4-0310-8c96-b1721e28e2e2
2007-05-11 16:15:21 +00:00
|
|
|
|
|
|
|
|
def get_ticket_changes(self, req, ticket, action):
|
2018-04-21 18:54:51 +00:00
|
|
|
new_status = self._get_new_status(req, action)
|
2007-05-20 09:53:41 +00:00
|
|
|
return {'status': new_status or 'new'}
|
WorkFlow: Merge workflow to trunk using svnmerge.py.
5012-5168,5171-5198,5201-5253,5255-5289,5291-5292,5294-5299,5301-5302,5304-5314,5316-5356,5358-5360,5362-5373,5375-5377
git-svn-id: http://trac.edgewall.org/intertrac/log:/trunk@5378 af82e41b-90c4-0310-8c96-b1721e28e2e2
2007-05-11 16:15:21 +00:00
|
|
|
|
|
|
|
|
def apply_action_side_effects(self, req, ticket, action):
|
|
|
|
|
pass
|
2007-05-20 09:53:41 +00:00
|
|
|
|
|
|
|
|
# Internal methods
|
|
|
|
|
|
2018-04-21 18:54:51 +00:00
|
|
|
def _get_selected(self, req, action):
|
|
|
|
|
id = 'action_%s_code_review' % action
|
2007-05-20 09:53:41 +00:00
|
|
|
return id, req.args.get(id)
|
2013-01-13 15:18:06 +00:00
|
|
|
|
2007-05-20 09:53:41 +00:00
|
|
|
def _get_review_options(self, action):
|
2018-04-21 18:54:51 +00:00
|
|
|
values = self.config.getlist('ticket-workflow', action + '.code_review')
|
|
|
|
|
return OrderedDict(to_list(v, sep='->') for v in values)
|
2007-05-20 09:53:41 +00:00
|
|
|
|
2018-04-21 18:54:51 +00:00
|
|
|
def _get_new_status(self, req, action, review_options=None):
|
|
|
|
|
selected = self._get_selected(req, action)[1]
|
2007-05-20 09:53:41 +00:00
|
|
|
if not review_options:
|
|
|
|
|
review_options = self._get_review_options(action)
|
2018-04-21 18:54:51 +00:00
|
|
|
return review_options[selected]
|