Skip to content

Commit

Permalink
NGO slug validator handling of Anonymous User
Browse files Browse the repository at this point in the history
  • Loading branch information
danniel committed May 25, 2024
1 parent de367ca commit 19de6f1
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions backend/donations/views/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,13 @@ def validate_ngo_slug(cls, user, slug):
return HttpResponseBadRequest()

ngo_queryset = Ngo.objects
if user.ngo:
ngo_queryset = ngo_queryset.exclude(id=user.ngo.id)

try:
if user.ngo:
ngo_queryset = ngo_queryset.exclude(id=user.ngo.id)
except AttributeError:
# Anonymous users don't have the .ngo attribute
pass

if ngo_queryset.filter(slug=slug.lower()).count():
return HttpResponseBadRequest()
Expand Down

0 comments on commit 19de6f1

Please sign in to comment.