diff --git a/lemarche/templates/tenders/_detail_cta_not_interested.html b/lemarche/templates/tenders/_detail_cta_not_interested.html
index 82909cdc1..7f7d73935 100644
--- a/lemarche/templates/tenders/_detail_cta_not_interested.html
+++ b/lemarche/templates/tenders/_detail_cta_not_interested.html
@@ -1,38 +1,19 @@
- {% if not tender.siae_detail_not_interested_click_date_count %}
-
diff --git a/lemarche/templates/tenders/_detail_not_interested_click_confirm_modal.html b/lemarche/templates/tenders/_detail_not_interested_click_confirm_modal.html
new file mode 100644
index 000000000..1dd086b73
--- /dev/null
+++ b/lemarche/templates/tenders/_detail_not_interested_click_confirm_modal.html
@@ -0,0 +1,45 @@
+
+
+
+
+
+
+
+
+
+
diff --git a/lemarche/templates/tenders/_detail_not_interested_click_error.html b/lemarche/templates/tenders/_detail_not_interested_click_error.html
deleted file mode 100644
index 9776a479e..000000000
--- a/lemarche/templates/tenders/_detail_not_interested_click_error.html
+++ /dev/null
@@ -1,5 +0,0 @@
-
-
- N'ayant pu identifier votre structure, nous n'avons pas pu prendre en compte votre non intérêt pour ce besoin.
-
-
diff --git a/lemarche/templates/tenders/detail.html b/lemarche/templates/tenders/detail.html
index 42379f49c..be1fba027 100644
--- a/lemarche/templates/tenders/detail.html
+++ b/lemarche/templates/tenders/detail.html
@@ -68,6 +68,7 @@
{% block modals %}
{% include "auth/_login_or_signup_siae_tender_modal.html" %}
{% include "tenders/_detail_contact_click_confirm_modal.html" %}
+{% include "tenders/_detail_not_interested_click_confirm_modal.html" %}
{% endblock %}
{% block extra_js %}
diff --git a/lemarche/www/tenders/tests.py b/lemarche/www/tenders/tests.py
index 0156ad522..090995e20 100644
--- a/lemarche/www/tenders/tests.py
+++ b/lemarche/www/tenders/tests.py
@@ -1312,6 +1312,7 @@ def setUpTestData(self):
def test_user_can_notify_cocontracting_wish_with_siae_id(self):
url = reverse("tenders:detail-cocontracting-click", kwargs={"slug": self.tender.slug})
+ detail_url = reverse("tenders:detail", kwargs={"slug": self.tender.slug}) + f"?siae_id={self.siae.id}"
# missing data
with mock.patch("lemarche.www.tenders.tasks.send_mail_async") as mock_send_mail_async:
response = self.client.post(url, data={})
@@ -1326,8 +1327,6 @@ def test_user_can_notify_cocontracting_wish_with_siae_id(self):
)
mock_send_mail_async.assert_not_called()
self.assertIsNone(tendersiae.detail_cocontracting_click_date)
-
- detail_url = reverse("tenders:detail", kwargs={"slug": self.tender.slug}) + f"?siae_id={self.siae.id}"
response = self.client.get(detail_url)
self.assertContains(response, "Répondre en co-traitance ?")
self.assertNotContains(response, "Votre intérêt a bien été signalé au client.")
@@ -1346,13 +1345,12 @@ def test_user_can_notify_cocontracting_wish_with_siae_id(self):
def test_user_can_notify_cocontracting_wish_with_authenticated_user(self):
self.client.force_login(self.siae_user)
-
+ url = reverse("tenders:detail-cocontracting-click", kwargs={"slug": self.tender.slug})
detail_url = reverse("tenders:detail", kwargs={"slug": self.tender.slug})
+
response = self.client.get(detail_url)
self.assertContains(response, "Répondre en co-traitance ?")
self.assertNotContains(response, "Votre intérêt a bien été signalé au client.")
-
- url = reverse("tenders:detail-cocontracting-click", kwargs={"slug": self.tender.slug})
tendersiae = TenderSiae.objects.get(tender=self.tender, siae=self.siae)
self.assertIsNone(tendersiae.detail_cocontracting_click_date)
with mock.patch("lemarche.www.tenders.tasks.send_mail_async") as mock_send_mail_async:
@@ -1363,11 +1361,9 @@ def test_user_can_notify_cocontracting_wish_with_authenticated_user(self):
email_body = mock_send_mail_async.call_args[1]["email_body"]
self.assertTrue(f"La structure {self.siae.name } souhaite répondre en co-traitance" in email_body)
self.assertIsNotNone(tendersiae.detail_cocontracting_click_date)
-
response = self.client.get(detail_url)
self.assertContains(response, "Votre intérêt a bien été signalé au client.")
self.assertNotContains(response, "Répondre en co-traitance ?")
-
user_without_siae = UserFactory(kind=User.KIND_SIAE)
self.client.force_login(user_without_siae)
with mock.patch("lemarche.www.tenders.tasks.send_mail_async") as mock_send_mail_async:
@@ -1381,9 +1377,8 @@ def test_user_can_notify_cocontracting_wish_with_authenticated_user(self):
class TenderDetailNotInterestedClickView(TestCase):
@classmethod
def setUpTestData(self):
- self.cta_message = "Pas intéressé ?"
+ self.cta_message = "Cette demande ne vous intéresse pas ?"
self.cta_message_success = "Vous n'êtes pas intéressé par ce besoin."
- self.cta_message_error = "nous n'avons pas pu prendre en compte votre non intérêt pour ce besoin"
self.siae = SiaeFactory(name="ZZ ESI")
self.siae_user = UserFactory(kind=User.KIND_SIAE, siaes=[self.siae])
self.user_buyer = UserFactory(kind=User.KIND_BUYER, company_name="Entreprise Buyer")
@@ -1402,58 +1397,51 @@ def setUpTestData(self):
email_link_click_date=timezone.now(),
detail_display_date=timezone.now(),
)
- TenderQuestionFactory(tender=self.tender)
+ self.tender_detail_url = reverse("tenders:detail", kwargs={"slug": self.tender.slug})
+ self.tender_not_interested_url = reverse(
+ "tenders:detail-not-interested-click", kwargs={"slug": self.tender.slug}
+ )
def test_user_can_notify_not_interested_wish_with_siae_id(self):
- url = reverse("tenders:detail-not-interested-click", kwargs={"slug": self.tender.slug})
- # missing data
- response = self.client.post(url, data={})
+ response = self.client.get(self.tender_detail_url)
+ self.assertContains(response, self.cta_message)
+ # anonymous user
+ response = self.client.post(self.tender_not_interested_url, data={})
self.assertEqual(response.status_code, 403)
- # missing siae
- response = self.client.post(f"{url}?siae_id=999999", data={})
- tendersiae = TenderSiae.objects.get(tender=self.tender, siae=self.siae)
- self.assertContains(response, self.cta_message_error)
- self.assertIsNone(tendersiae.detail_not_interested_click_date)
-
- detail_url = reverse("tenders:detail", kwargs={"slug": self.tender.slug}) + f"?siae_id={self.siae.id}"
- response = self.client.get(detail_url)
+ # wrong siae_id
+ response = self.client.post(f"{self.tender_not_interested_url}?siae_id=999999", data={}, follow=True)
+ self.assertContains(response, self.cta_message)
+ # workflow
+ response = self.client.get(self.tender_detail_url)
self.assertContains(response, self.cta_message)
self.assertNotContains(response, self.cta_message_success)
-
- response = self.client.post(f"{url}?siae_id={self.siae.id}", data={})
tendersiae = TenderSiae.objects.get(tender=self.tender, siae=self.siae)
+ self.assertIsNone(tendersiae.detail_not_interested_click_date)
+ response = self.client.post(f"{self.tender_not_interested_url}?siae_id={self.siae.id}", data={}, follow=True)
self.assertContains(response, self.cta_message_success)
+ tendersiae = TenderSiae.objects.get(tender=self.tender, siae=self.siae)
self.assertIsNotNone(tendersiae.detail_not_interested_click_date)
- response = self.client.get(detail_url)
+ response = self.client.get(f"{self.tender_detail_url}?siae_id={self.siae.id}")
self.assertContains(response, self.cta_message_success)
self.assertNotContains(response, self.cta_message)
def test_user_can_notify_not_interested_wish_with_authenticated_user(self):
self.client.force_login(self.siae_user)
-
- detail_url = reverse("tenders:detail", kwargs={"slug": self.tender.slug})
- response = self.client.get(detail_url)
+ # workflow
+ response = self.client.get(self.tender_detail_url)
self.assertContains(response, self.cta_message)
self.assertNotContains(response, self.cta_message_success)
-
- url = reverse("tenders:detail-not-interested-click", kwargs={"slug": self.tender.slug})
- tendersiae = TenderSiae.objects.get(tender=self.tender, siae=self.siae)
- self.assertIsNone(tendersiae.detail_not_interested_click_date)
- response = self.client.post(url, data={"detail_not_interested_feedback": "reason"})
+ response = self.client.post(
+ self.tender_not_interested_url, data={"detail_not_interested_feedback": "reason"}, follow=True
+ )
tendersiae = TenderSiae.objects.get(tender=self.tender, siae=self.siae)
self.assertContains(response, self.cta_message_success)
self.assertIsNotNone(tendersiae.detail_not_interested_click_date)
self.assertEqual(tendersiae.detail_not_interested_feedback, "reason")
-
- response = self.client.get(detail_url)
+ response = self.client.get(self.tender_detail_url)
self.assertContains(response, self.cta_message_success)
self.assertNotContains(response, self.cta_message)
- user_without_siae = UserFactory(kind=User.KIND_SIAE)
- self.client.force_login(user_without_siae)
- response = self.client.post(url, data={})
- self.assertContains(response, self.cta_message_error)
-
# TODO: this test doesn't work anymore. find a way to test logging post-email in non-prod environments?
# class TenderTasksTest(TestCase):
diff --git a/lemarche/www/tenders/views.py b/lemarche/www/tenders/views.py
index 62e614376..6bf0e0373 100644
--- a/lemarche/www/tenders/views.py
+++ b/lemarche/www/tenders/views.py
@@ -506,25 +506,34 @@ def get_object(self):
def post(self, request, *args, **kwargs):
self.object = self.get_object()
user = self.request.user
-
- if self.request.user.is_authenticated:
- siae = user.siaes.first()
- else:
- siae = Siae.objects.filter(pk=self.request.GET.get("siae_id", None)).first()
-
- if siae:
- # save the datetime of this action
- TenderSiae.objects.filter(
- tender=self.object, siae=siae, detail_not_interested_click_date__isnull=True
- ).update(
- detail_not_interested_feedback=self.request.POST.get("detail_not_interested_feedback", ""),
- detail_not_interested_click_date=timezone.now(),
- updated_at=timezone.now(),
- )
+ siae_id = request.GET.get("siae_id", None)
+ if (user.is_authenticated and user.kind == User.KIND_SIAE) or siae_id:
+ if user.is_authenticated:
+ TenderSiae.objects.filter(
+ tender=self.object, siae__in=user.siaes.all(), detail_not_interested_click_date__isnull=True
+ ).update(
+ detail_not_interested_feedback=self.request.POST.get("detail_not_interested_feedback", ""),
+ detail_not_interested_click_date=timezone.now(),
+ updated_at=timezone.now(),
+ )
+ else:
+ TenderSiae.objects.filter(
+ tender=self.object, siae_id=int(siae_id), detail_not_interested_click_date__isnull=True
+ ).update(
+ detail_not_interested_feedback=self.request.POST.get("detail_not_interested_feedback", ""),
+ detail_not_interested_click_date=timezone.now(),
+ updated_at=timezone.now(),
+ )
+ # redirect
+ return HttpResponseRedirect(self.get_success_url(siae_id))
else:
- self.template_name = "tenders/_detail_not_interested_click_error.html"
+ return HttpResponseForbidden()
- return self.get(request)
+ def get_success_url(self, siae_id=None):
+ success_url = reverse_lazy("tenders:detail", args=[self.kwargs.get("slug")])
+ if siae_id:
+ success_url += f"?siae_id={siae_id}"
+ return success_url
class TenderSiaeListView(TenderAuthorOrAdminRequiredMixin, FormMixin, ListView):