diff --git a/make_post_sell/static/js/offer.js b/make_post_sell/static/js/offer.js index 9b5c6ca..2a5ef1d 100644 --- a/make_post_sell/static/js/offer.js +++ b/make_post_sell/static/js/offer.js @@ -28,6 +28,10 @@ } function handleSubmit(e) { + // An inline onsubmit="return confirm(...)" on terminal-action forms + // runs before this listener. If the user cancelled, the event is + // already defaultPrevented — bail so we don't fire the AJAX request. + if (e.defaultPrevented) return; var form = e.currentTarget; e.preventDefault(); var submitBtn = form.querySelector('[type="submit"]'); diff --git a/make_post_sell/templates/offer.j2 b/make_post_sell/templates/offer.j2 index 92a7b49..9e31883 100644 --- a/make_post_sell/templates/offer.j2 +++ b/make_post_sell/templates/offer.j2 @@ -62,7 +62,11 @@

Your turn

-
+ {# Terminal actions (accept / decline / withdraw) carry a confirm + prompt. offer.js bails if the prompt was cancelled (it checks + event.defaultPrevented), so the AJAX path respects it too. #} +
@@ -74,13 +78,15 @@ -
+
{% if actor_party == 0 %} -
+
{% endif %} diff --git a/make_post_sell/tests/test_functional.py b/make_post_sell/tests/test_functional.py index c70391d..3b6c132 100644 --- a/make_post_sell/tests/test_functional.py +++ b/make_post_sell/tests/test_functional.py @@ -5971,6 +5971,20 @@ class TestOfferRoutes(_AuthenticatedBase): ) self.assertEqual(res2.status_int, 403) + def test_terminal_action_forms_have_confirm_prompt(self): + product_id = self._make_offer_product(list_price=10000) + self.testapp.get("/log-out") + self.log_in_user(self.user2_creds) + res = self._ajax_post(f"/p/{product_id}/offer", {"amount": "70.00"}) + offer_id = res.json["offer_id"] + # Seller views the pending offer — accept/decline forms must carry + # an "are you sure" confirm. + self.testapp.get("/log-out") + self.log_in_user(self.user1_creds) + body = self.testapp.get(f"/o/{offer_id}", status=200).body.decode() + self.assertIn(f"/o/{offer_id}/accept", body) + self.assertIn('onsubmit="return confirm(', body) + def test_offers_disabled_on_fixed_price_product(self): from ..models.product import Product shop = self._create_shop_helper()