fix: Fix broken user check when anonymous

This commit is contained in:
James Graham
2020-03-03 13:42:46 +00:00
parent 7784ab3e09
commit 40afbc1908

View File

@@ -30,4 +30,8 @@ class UserIsLinkedPersonMixin(UserPassesTestMixin):
return getattr(self.get_object(), self.related_person_field)
def test_func(self) -> bool:
return self.request.user.is_staff or self.get_test_person() == self.request.user.person
"""
Require that user is either staff or is the linked person.
"""
user = self.request.user
return user.is_authenticated and (user.is_staff or self.get_test_person() == user.person)