Skip to content

Commit

Permalink
T1903 Fix /children/random redirect producing 404 error (#52)
Browse files Browse the repository at this point in the history
* Fix 404 for child with state='I'

* Fix pre-commit issue
  • Loading branch information
nlachat-compassion authored Oct 10, 2024
1 parent 2551387 commit ce1bb9a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
1 change: 0 additions & 1 deletion crowdfunding_compassion/models/crowdfunding_participant.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ class CrowdfundingParticipant(models.Model):
"and to this partner.",
)


# kanban colors
color_sponsorship = fields.Char(compute="_compute_color_sponsorship")
color_product = fields.Char(compute="_compute_color_product")
Expand Down
19 changes: 15 additions & 4 deletions website_sponsorship/controllers/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,19 @@ def load_child(self, **kwargs):
# Put a child on hold and display its page
return request.render("website_sponsorship.load_child_page")

def _ensure_child_available(self, child) -> None:
"""Checks if child is in an available state and displays a NotFound page
otherwise.
Args:
child (CompassionChild): The child to check for availability.
Raises:
NotFound: Raised if child is not available.
"""
if child.state not in child._available_states():
raise NotFound()

@http.route(
[
# [T1835] : Note: the route MUST be specified *without* a trailing
Expand All @@ -110,8 +123,7 @@ def load_child(self, **kwargs):
sitemap=False,
)
def child_page(self, child, show_sponsorship_form=False, **kwargs):
if child.state != "N":
raise NotFound()
self._ensure_child_available(child)
return request.render(
"website_sponsorship.child_page_template",
{
Expand All @@ -133,8 +145,7 @@ def child_page(self, child, show_sponsorship_form=False, **kwargs):
sitemap=False,
)
def child_sponsor_form(self, child, **kwargs):
if child.state != "N":
raise NotFound()
self._ensure_child_available(child)
reservation_uuid = self._get_reservation_uuid()
if not child.sudo().reserve_for_web_sponsorship(reservation_uuid):
raise Gone()
Expand Down

0 comments on commit ce1bb9a

Please sign in to comment.