Edgewall Software

Changes between Version 10 and Version 11 of CookBook/PermissionPolicies


Ignore:
Timestamp:
May 8, 2017, 1:15:57 AM (7 years ago)
Author:
Ryan J Ollos
Comment:

Fix issues with RestrictTicketActionsPolicy: the policy would grant/deny even if user didn't possess TICEKT_CHANGE_STATE and non-existent ticket would raise ResourceNotFound.

Legend:

Unmodified
Added
Removed
Modified
  • CookBook/PermissionPolicies

    v10 v11  
    55== Restrict a Workflow Action to the Ticket Owner
    66
    7 This permissions policy can be used to restrict a workflow action to the ticket's owner.
     7This permissions policy can be used to restrict a workflow action to the ticket owner that possesses `TICKET_CHANGE_STATE`. User with `TICKET_ADMIN` can perform the action even if they are not the owner.
    88
    99To install and activate the plugin:
     
    2525from trac.core import *
    2626from trac.perm import IPermissionPolicy, IPermissionRequestor
     27from trac.resource import ResourceNotFound
    2728from trac.ticket.model import Ticket
    2829
     
    4748                resource.realm == 'ticket' and \
    4849                resource.id is not None:
    49             ticket = Ticket(self.env, resource.id)
    50             return ticket['owner'] == username
    51         return None
     50            try:
     51                ticket = Ticket(self.env, resource.id)
     52            except ResourceNotFound:
     53                pass
     54            else:
     55                if ticket['owner'] != username:
     56                    return 'TICKET_ADMIN' in perm
    5257}}}
    5358 1. Edit the `permission_policies` option in the [TracIni#trac-section "[trac]"] section of trac.ini, adding the `RestrictTicketActions` component ''before'' the default [TracPermissions permission] policy: