Modify

Opened 9 years ago

Closed 9 years ago

#3358 closed defect (wontfix)

TracTags 0.6 appears to break IPermissionPolicy example

Reported by: James Yonan Owned by: Alec Thomas
Priority: normal Component: TagsPlugin
Severity: normal Keywords:
Cc: Trac Release: 0.11

Description

This is an important example showing how to build a fine-grained permission policy using tags:

http://cmrg.fifthhorseman.net/browser/trunk/tracplugins/publictags/public_tags.py

The sample now appears to be broken, due to non-existence of TagEngine object in TracTags 0.6.

It would be great if someone who understands TracTags 0.6 could fix this example, or point me to an IPermissionPolicy sample that uses the new TracTags 0.6 API.

Thanks, James

Attachments (1)

api.diff (683 bytes) - added by James Yonan 9 years ago.
patch to api.py

Download all attachments as: .zip

Change History (4)

comment:1 Changed 9 years ago by Alec Thomas

Resolution: invalid
Status: newclosed

Urm , you'd be better off creating this ticket on that Trac rather than here.

Changed 9 years ago by James Yonan

Attachment: api.diff added

patch to api.py

comment:2 Changed 9 years ago by James Yonan

Resolution: invalid
Status: closedreopened
Trac Release: 0.100.11

I was able to fix the issue, but I had to add a small patch (attached) to api.py to allow get_resource_tags to be called with req==None, since the IPermissionPolicy plugin might want to query the tags for a page outside the context of a request for that page.

After adding this patch, it is then possible to easily get the tags for a resource in an IPermissionPolicy plugin as such:

tags = TagSystem(self.env).get_tags(None, resource)

I added the patch since it was not clear to me how an IPermissionPolicy plugin could pass a reasonable 'req' object given the context in which it is called. In fact, it would seem that if the IPermissionPolicy plugin passed the current request object, it would set up an infinite recursion because the IPermissionPolicy plugin would get recursively called again asking if TAGS_VIEW is permitted on the requested page.

Please merge if this seems like a reasonable approach.

comment:3 Changed 9 years ago by Alec Thomas

Resolution: wontfix
Status: reopenedclosed

req usage is pervasive in Trac, selectively avoiding it isn't really feasible. Fortunately, Trac provides a couple of mock objects that are perfect for this situation:

from trac.tests import Mock, MockPerm

req = Mock(perm=MockPerm())
...

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain Alec Thomas.
The resolution will be deleted.

Add Comment


E-mail address and name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.