Skip to content

Commit

Permalink
Petition.is_allowed_to_edit(): Code cleanup
Browse files Browse the repository at this point in the history
The code was a mess, if (x) return True else return False => return x
  • Loading branch information
fallen committed Feb 14, 2023
1 parent 9b36910 commit 3c7f4f3
Showing 1 changed file with 12 additions and 17 deletions.
29 changes: 12 additions & 17 deletions pytition/petition/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -382,23 +382,18 @@ def is_allowed_to_edit(self, user):
Check if a user is allowed to edit this petition
"""
if self.owner_type == "user":
if self.user == user:
# The user is the owner of the petition
return True
else:
return False
else:
# But it is an org petition
try:
perm = Permission.objects.get(
organization=self.org,
user=user
)
except Permission.DoesNotExist:
# No such permission, denied
return False
else:
return perm.can_modify_petitions
# The user is the owner of the petition
return self.user == user
# The petition is owned by an organization
try:
perm = Permission.objects.get(
organization=self.org,
user=user
)
except Permission.DoesNotExist:
# No such permission, denied
return False
return perm.can_modify_petitions

@property
def url(self):
Expand Down

0 comments on commit 3c7f4f3

Please sign in to comment.