I have seen several people, including myself, asking if it were possible
to limit the ticket properties fields to owner or admin only. Here's how
I did it, using the blackmagictweaks plugin.

 

In the source file blackmagic.py ( lines I added are marked as #NEW:

 

    def filter_stream(self, req, method, filename, stream, data):

        if filename == "ticket.html":

            tkt=data['ticket']      #NEW

            owner=tkt['owner']   #NEW

            status=tkt['status']  #NEW

            user=req.authname #NEW

            self.env.log.info("user %s owner %s status %s" %
(user,owner,status))  #NEW

            enchants = self.config.get('blackmagic', 'tweaks', '')

            for field in (x.strip() for x in enchants.split(',')):

 

                disabled = False

                hidden = False

                perm = self.config.get('blackmagic', '%s.permission' %
field, '').upper()

                if perm and perm not in req.perm:

                    denial = self.config.get('blackmagic', '%s.ondenial'
% field, None)

                    if denial:

                        if denial == "disable":

                            disabled = True

                        elif denial == "hide":

                            hidden = True

                        else:

                            disabled = True

                    else:

                        disabled = True

 

                if owner != user and not 'TRAC_ADMIN' in req.perm:
#NEW

                    disabled=True
#NEW

 

 

 

This is a very simplistic method, but effective. It will cause any field
listed in the tweaks config line to be disabled except when being viewed
by the owner or by the admin. It is very easy to set up conditional
based on status, like so :

 

                statuslist = self.config.get('blackmagic',
'%s.owner_only' % field, '')

                self.env.log.info("  checking %s.owner_only for status
%s" % (field,status))

                for statusfield in (sf.strip() for sf in
statuslist.split(',')):

                    self.env.log.info("    statusfield %s" %
(statusfield))

                    if status == statusfield:

                        self.env.log.info("    found matching status %s"
% (statusfield))

                        if owner != user and not 'TRAC_ADMIN' in
req.perm:

                           self.env.log.info("      disabling field %s"
% (field))

                           disabled=True

 

 

which would read a line like this in the [blackmagic] section:

 

estimate_hours.owner_only = accepted, assigned, Assigned_Costing,
closed, completed, inforequested, Needs Costing, Needs Review, new,
onhold, reviewed, started, tested 

 

and disable the field based on the workflow status. Other combinations
are possible as well, but I decided to go the simple route for now.

 

 

 

 

Dan Winslow
Director of Information Technology, AIM INSTITUTE
1905 Harney Street, Suite 700
Omaha, NE 68102
402-345-5025 x156
[email protected]
www.aiminstitute.org

 


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Trac 
Users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/trac-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to