File: StatusFixer.py

package info (click to toggle)
trac 1.6-2~bpo12%2B1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm-backports
  • size: 26,624 kB
  • sloc: python: 81,903; javascript: 2,219; makefile: 561; sh: 92; xml: 12
file content (81 lines) | stat: -rw-r--r-- 3,067 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# -*- coding: utf-8 -*-
#
# Copyright (C) 2007-2023 Edgewall Software
# 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
# are also available at https://trac.edgewall.org/wiki/TracLicense.
#
# This software consists of voluntary contributions made by many
# individuals. For the exact contribution history, see the revision
# history and logs, available at https://trac.edgewall.org/.

from trac.core import Component, implements
from trac.perm import IPermissionRequestor
from trac.ticket.api import ITicketActionController, TicketSystem
from trac.util.html import tag

revision = "$Rev: 17657 $"
url = "$URL: https://svn.edgewall.org/repos/trac/trunk/sample-plugins/workflow/StatusFixer.py $"


class StatusFixerActionController(Component):
    """Provides the admin with a way to correct a ticket's status.

    This plugin is especially useful when you made changes to your
    workflow, and some ticket status are no longer valid. The tickets
    with invalid status can be set to a valid state.

    Don't forget to add `StatusFixerActionController` to the `workflow`
    option in the `[ticket]` section of TracIni. When added to the
    default value of `workflow`, the line will look like this:
    {{{#!ini
    workflow = ConfigurableTicketWorkflow,StatusFixerActionController
    }}}
    """

    implements(IPermissionRequestor, ITicketActionController)

    id_for_action = 'action_%s_fixed_status'

    # IPermissionRequestor methods

    def get_permission_actions(self):
        return ['TICKET_STATUSFIX']

    # ITicketActionController methods

    def get_ticket_actions(self, req, ticket):
        actions = []
        if ticket.exists and 'TICKET_STATUSFIX' in req.perm(ticket.resource):
            actions.append((0, 'force_status'))
        return actions

    def get_all_status(self):
        """Return all the status that are present in the database,
        so that queries for status no longer in use can be made.
        """
        return [status for status, in self.env.db_query("""
                  SELECT DISTINCT status FROM ticket
                  """)]

    def render_ticket_action_control(self, req, ticket, action):
        # Need to use the list of all status so you can't manually set
        # something to an invalid state.
        id = self.id_for_action % action
        selected_value = req.args.get(id, 'new')
        all_status = TicketSystem(self.env).get_all_status()
        render_control = tag.select(
            [tag.option(x, selected=(x == selected_value or None))
             for x in all_status], id=id, name=id)
        return ("force status to", render_control,
                "The next status will be the selected one")

    def get_ticket_changes(self, req, ticket, action):
        id = self.id_for_action % action
        return {'status': req.args.get(id)}

    def apply_action_side_effects(self, req, ticket, action):
        pass