fix: Only allow users to create rels as source

There is now no field for users to define the source of a relationship
The source is always the person in the URL
And only that user or staff can access the form
This commit is contained in:
James Graham
2020-08-14 17:38:22 +01:00
parent 6435ec69a1
commit a94db2713e
4 changed files with 50 additions and 39 deletions

View File

@@ -23,7 +23,9 @@ class UserIsLinkedPersonMixin(UserPassesTestMixin):
test_person = self.get_object()
if not isinstance(test_person, models.Person):
raise AttributeError('View incorrectly configured: \'related_person_field\' must be defined.')
raise AttributeError(
'View incorrectly configured: \'related_person_field\' must be defined.'
)
return test_person
@@ -34,4 +36,5 @@ class UserIsLinkedPersonMixin(UserPassesTestMixin):
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)
return user.is_authenticated and (
user.is_staff or self.get_test_person() == user.person)