Edgewall Software

Changes between Initial Version and Version 1 of CookBook/Configuration/SignedTickets


Ignore:
Timestamp:
Aug 3, 2014, 10:05:49 PM (10 years ago)
Author:
Peter Suter
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • CookBook/Configuration/SignedTickets

    v1 v1  
     1[[PageOutline(2-3)]]
     2= Signed Tickets
     3
     4Some projects require a special workflow where tickets can be ''signed''.
     5
     6This recipe shows steps to implement various aspects of such a feature using a combination of configuration, existing plugins and a small custom permission policy containing the authorization rules.
     7
     8== Goals
     91. Users with `TICKET_SIGN` permission can sign tickets.
     101. Signed tickets are consideref closed them with resolution `signed`.
     111. Signed tickets are readonly, except to users with `TICKET_ADMIN` permission.
     121. Signed tickets are visually distinguished.
     13
     14== Steps
     15
     16=== TICKET_SIGN permission
     17
     18Enable the optional component [TracPermissions#CreatingNewPrivileges ExtraPermissionsProvider] and configure a new permission:
     19{{{#!ini
     20[extra-permissions]
     21_perms = TICKET_SIGN
     22}}}
     23
     24=== Sign workflow step
     25
     26Configure your [TracWorkflow workflow] adding a step to resolve as signed:
     27{{{#!ini
     28[ticket-workflow]
     29sign = new -> closed
     30sign.permissions = TICKET_SIGN
     31sign.operations = set_resolution
     32sign.set_resolution = signed
     33}}}
     34
     35=== Readonly logic
     36
     37Create a [TracDev/PluginDevelopment#Singlefileplugins single file plugin] that implements [wiki:TracDev/PluginDevelopment/ExtensionPoints/trac.perm.IPermissionPolicy IPermissionPolicy]:
     38
     39{{{#!python
     40from trac.core import *
     41from trac.perm import IPermissionPolicy
     42from trac.ticket.model import Ticket
     43
     44class ReadonlySignedTickets(Component):
     45      implements(IPermissionPolicy)
     46
     47      def check_permission(self, action, username, resource, perm):
     48          if resource is None or resource.realm != 'ticket' or \
     49             resource.id is None or action == 'TICKET_VIEW' or \
     50             action == 'TICKET_ADMIN' or 'TICKET_ADMIN' in perm:
     51              return None
     52
     53          t = Ticket(self.env, resource.id)
     54          if t['status'] == 'closed' and t['resolution'] == 'signed':
     55             return False
     56}}}
     57
     58
     59Configure the component ''before'' the default [TracPermissions permission] policy:
     60{{{#!ini
     61[trac]
     62permission_policies = ReadonlySignedTickets, ...
     63}}}
     64
     65=== Visual indication
     66
     671. Install th:ContextChromePlugin#TicketcolorbyType and enable it:
     68{{{#!ini
     69[components]
     70contextchrome.style.typeclasstoticket = enabled
     71}}}
     722. Configure it to decorate based on the ticket's resolution:
     73{{{#!ini
     74[ticket]
     75decorate_fields = resolution
     76}}}
     773. Add [TracInterfaceCustomization#SiteAppearance site.html] (the first code snippet in that section) to your Environment templates directory.
     784. Add `style.css` to your Environment htdocs directory. Add CSS using the selector `body.resolution_is_signed`. For example:
     79{{{#!css
     80body.resolution_is_signed {
     81    background: #f5deb3 url(signed.png);
     82}
     83}}}
     845. Add [attachment:signed.png] to the htdocs directory.
     85
     86== Variations
     87=== Allow ticket comments
     88If you still want to allow commenting on signed tickets, change `action == 'TICKET_VIEW'`  to `action in ['TICKET_VIEW', 'TICKET_APPEND']`.
     89
     90=== Status instead of resolution
     91If you want to use a `signed` ''status'' instead of a resolution, change the last two lines of code to:
     92{{{#!python
     93          # ...
     94          if t['status'] == 'signed':
     95             return False
     96}}}
     97And change the workflow step to:
     98{{{#!ini
     99[ticket-workflow]
     100sign = closed -> signed
     101sign.permissions = TICKET_SIGN
     102}}}
     103
     104And configure `signed` as an [CookBook/Configuration/Workflow#Multipleendstatesandmilestoneprogress end state for milestone progress]:
     105{{{#!ini
     106[milestone-groups]
     107closed = closed,signed
     108}}}
     109
     110Change ''resolution'' to ''status'' in the visual steps.
     111
     112----
     113See [Trac-ML:36200 original mailing list discussion]