Commit 142e8fab authored by Andrei Vagin's avatar Andrei Vagin Committed by Arkadiusz Hiler

permissions: add a fast path for non-authenticated users

patchwork returns a following back-trace without this patch:

Internal Server Error: /patch/858/
Traceback (most recent call last):
  File "/usr/lib/python2.7/site-packages/django/core/handlers/", line 132, in get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/srv/patchwork/lib/apache2/../../patchwork/views/", line 34, in patch
    editable = Can(request.user).edit(patch)
  File "/srv/patchwork/lib/apache2/../../patchwork/", line 38, in edit
  File "/srv/patchwork/lib/apache2/../../patchwork/", line 32, in edit
    project in self.user.profile.maintainer_projects.all())
  File "/usr/lib/python2.7/site-packages/django/utils/", line 226, in inner
    return func(self._wrapped, *args)
AttributeError: 'AnonymousUser' object has no attribute 'profile'

Fixes: e876b068 ("permissions: Introduce central point for defining permissions")
parent 1decf84c
......@@ -25,6 +25,9 @@ class Can:
self.user = user
def edit(self, obj):
if not self.user.is_authenticated():
return False
can = self
if isinstance(obj, Project):
project = obj
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment