Modify

Opened 6 years ago

Closed 6 years ago

#3358 closed defect (wontfix)

TracTags 0.6 appears to break IPermissionPolicy example

Reported by: jamesyonan Owned by: athomas
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 jamesyonan 6 years ago.
patch to api.py

Download all attachments as: .zip

Change History (4)

comment:1 Changed 6 years ago by athomas

  • Resolution set to invalid
  • Status changed from new to closed

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

Changed 6 years ago by jamesyonan

patch to api.py

comment:2 Changed 6 years ago by jamesyonan

  • Resolution invalid deleted
  • Status changed from closed to reopened
  • Trac Release changed from 0.10 to 0.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 6 years ago by athomas

  • Resolution set to wontfix
  • Status changed from reopened to closed

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())
...

Add Comment

Modify Ticket

Action
as closed .
as The resolution will be set. Next status will be 'closed'.
to The owner will be changed from athomas. Next status will be 'closed'.
The resolution will be deleted. Next status will be 'reopened'.
Author


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

 
Note: See TracTickets for help on using tickets.