Edgewall Software
Modify

Opened 5 years ago

Closed 5 years ago

#12062 closed defect (fixed)

Missing attributes in FakePerm class

Reported by: anonymous Owned by: Jun Omae
Priority: normal Milestone: 1.0.7
Component: general Version: 1.1.3
Severity: normal Keywords: permission
Cc: Branch:
Release Notes:

Add missing attributes and methods of FakePerm to PermissionCache.

API Changes:
Internal Changes:

Description (last modified by Ryan J Ollos)

As I understand it, FakeSession and FakePerm objects are returned when Trac is not able to get the real information from the database.

However, the FakePerm class lacks the has_permission and assert_permission functions, which has lead to traces like this in our logs:

2015-05-06 16:11:16,671 Trac[main] ERROR: can't retrieve session: TimeoutError: Unable to get database connection within 0 seconds.
2015-05-06 16:11:16,673 Trac[chrome] ERROR: Traceback (most recent call last):
  File "/local/engine/trac/trac/web/chrome.py", line 773, in prepare_request
    contributor.get_navigation_items(req) or []:
  File "/local/engine/trac-plugins/xmlrpc-plugin/tracrpc/web_ui.py", line 205, in get_navigation_items
    if req.perm.has_permission('XML_RPC'):
AttributeError: 'FakePerm' object has no attribute 'has_permission'

This also happen in bitten/master.py and bitten/admin.py

The server is Lighttpd running Trac v1.1.3

For the moment, I simply did this :

  • trac/web/main.py

    diff --git a/trac/web/main.py b/trac/web/main.py
    index f52444f..cc718df 100644
    a b class FakeSession(dict):  
    7171class FakePerm(dict):
    7272    def require(self, *args):
    7373        return False
     74    def has_permission(self, *args):
     75        return False
    7476    def __call__(self, *args):
    7577        return self
     78    assert_permission = require
    7679
    7780
    7881class RequestWithSession(Request):

note: the #!diff and #!patch do not seem to work in the above block

Attachments (0)

Change History (6)

comment:1 by ebouaziz@…, 5 years ago

forgot to put my email as reporter, please cc me

comment:2 by Ryan J Ollos, 5 years ago

Description: modified (diff)

in reply to:  description comment:3 by Ryan J Ollos, 5 years ago

Replying to anonymous:

note: the #!diff and #!patch do not seem to work in the above block

You were probably just experiencing the problem of the path/diff not being rendered during autopreview. The issue has been fixed, but this Trac site hasn't been upgraded to the version that includes the fix.

Version 0, edited 5 years ago by Ryan J Ollos (next)

comment:4 by Jun Omae, 5 years ago

Milestone: 1.0.6
Owner: set to Jun Omae
Status: newassigned

Okay. It seems that also username property is needed by reference to MockPerm in tags/trac-1.0.5/trac/test.py#L101.

  • trac/web/main.py

    diff --git a/trac/web/main.py b/trac/web/main.py
    index 7694bea..18a6e9a 100644
    a b class FakeSession(dict):  
    6565        pass
    6666
    6767
    68 class FakePerm(dict):
    69     def require(self, *args):
    70         return False
    71     def __call__(self, *args):
     68class FakePerm(object):
     69
     70    username = 'anonymous'
     71
     72    def __call__(self, realm_or_resource, id=False, version=False):
    7273        return self
    7374
     75    def has_permission(self, action, realm_or_resource=None, id=False,
     76                       version=False):
     77        return False
     78
     79    __contains__ = has_permission
     80
     81    def require(self, action, realm_or_resource=None, id=False, version=False,
     82                message=None):
     83        if message is None:
     84            raise PermissionError(action)
     85        else:
     86            raise PermissionError(msg=message)
     87
     88    assert_permission = require
     89
    7490
    7591class RequestWithSession(Request):
    7692    """A request that saves its associated session when sending the reply."""

comment:5 by Jun Omae, 5 years ago

Milestone: 1.0.61.0.7

comment:6 by Jun Omae, 5 years ago

Keywords: permission added
Release Notes: modified (diff)
Resolution: fixed
Status: assignedclosed

Fixed in [14145] and merged to trunk in [14146].

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain Jun Omae.
The resolution will be deleted. Next status will be 'reopened'.
to The owner will be changed from Jun Omae to the specified user.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.