Opened 11 years ago
Closed 10 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   | 
      ||
| API Changes: | |||
| Internal Changes: | |||
Description (last modified by )
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): 71 71 class FakePerm(dict): 72 72 def require(self, *args): 73 73 return False 74 def has_permission(self, *args): 75 return False 74 76 def __call__(self, *args): 75 77 return self 78 assert_permission = require 76 79 77 80 78 81 class RequestWithSession(Request):  
note: the #!diff and #!patch do not seem to work in the above block
Attachments (0)
Change History (6)
comment:1 by , 11 years ago
comment:2 by , 11 years ago
| Description: | modified (diff) | 
|---|
comment:3 by , 11 years ago
Replying to anonymous:
note: the
#!diffand#!patchdo not seem to work in the above block
You were probably just experiencing the problem of the patch/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.
comment:4 by , 10 years ago
| Milestone: | → 1.0.6 | 
|---|---|
| Owner: | set to | 
| Status: | new → assigned | 
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): 65 65 pass 66 66 67 67 68 class FakePerm(dict): 69 def require(self, *args): 70 return False 71 def __call__(self, *args): 68 class FakePerm(object): 69 70 username = 'anonymous' 71 72 def __call__(self, realm_or_resource, id=False, version=False): 72 73 return self 73 74 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 74 90 75 91 class RequestWithSession(Request): 76 92 """A request that saves its associated session when sending the reply."""  
comment:5 by , 10 years ago
| Milestone: | 1.0.6 → 1.0.7 | 
|---|
comment:6 by , 10 years ago
| Keywords: | permission added | 
|---|---|
| Release Notes: | modified (diff) | 
| Resolution: | → fixed | 
| Status: | assigned → closed | 



  
forgot to put my email as reporter, please cc me