Skip to content

Commit

Permalink
handle invalid club code in request creation
Browse files Browse the repository at this point in the history
  • Loading branch information
gabeweng committed Nov 17, 2024
1 parent 87af1ab commit 6315065
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
6 changes: 0 additions & 6 deletions backend/clubs/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1107,11 +1107,8 @@ def __str__(self):

def send_request(self, request=None):
domain = get_domain(request)

edit_url = settings.EDIT_URL.format(domain=domain, club=self.club.code)

club_name = self.club.name

full_name = self.requester.get_full_name()

context = {
Expand Down Expand Up @@ -1141,11 +1138,8 @@ def __str__(self):

def send_request(self, request=None):
domain = get_domain(request)

edit_url = settings.EDIT_URL.format(domain=domain, club=self.club.code)

club_name = self.club.name

full_name = self.requester.get_full_name()

context = {
Expand Down
14 changes: 10 additions & 4 deletions backend/clubs/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -3781,8 +3781,11 @@ def create(self, request, *args, **kwargs):
If a membership request object already exists, reuse it.
"""
club = request.data.get("club", None)

club_instance = Club.objects.get(code=club)
club_instance = Club.objects.filter(code=club).first()
if club_instance is None:
return Response(

Check warning on line 3786 in backend/clubs/views.py

View check run for this annotation

Codecov / codecov/patch

backend/clubs/views.py#L3786

Added line #L3786 was not covered by tests
{"detail": "Invalid club code"}, status=status.HTTP_400_BAD_REQUEST
)

create_defaults = {"club": club_instance, "requester": request.user}

Expand Down Expand Up @@ -3886,8 +3889,11 @@ def create(self, request, *args, **kwargs):
If a ownership request object already exists, reuse it.
"""
club = request.data.get("club", None)

club_instance = Club.objects.get(code=club)
club_instance = Club.objects.filter(code=club).first()
if club_instance is None:
return Response(

Check warning on line 3894 in backend/clubs/views.py

View check run for this annotation

Codecov / codecov/patch

backend/clubs/views.py#L3894

Added line #L3894 was not covered by tests
{"detail": "Invalid club code"}, status=status.HTTP_400_BAD_REQUEST
)

create_defaults = {"club": club_instance, "requester": request.user}

Expand Down

0 comments on commit 6315065

Please sign in to comment.