From 24d7079c514904506194eb739603634b9d6b820e Mon Sep 17 00:00:00 2001 From: Raphael Odini Date: Fri, 26 Jan 2024 14:56:21 +0100 Subject: [PATCH] =?UTF-8?q?D=C3=A9p=C3=B4t=20de=20besoin=20:=20D=C3=A9tail?= =?UTF-8?q?=20:=20Template=20d=C3=A9di=C3=A9=20=C3=A0=20la=20sidebar=20(#1?= =?UTF-8?q?048)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Tender detail: create sidebar template * Try to simplify a bit * Add tests --- lemarche/templates/tenders/_detail_card.html | 2 + lemarche/templates/tenders/_detail_cta.html | 2 +- .../templates/tenders/_detail_sidebar.html | 84 +++++++++++++++++ .../tenders/_detail_success_contact.html | 6 +- lemarche/templates/tenders/detail.html | 94 ++----------------- lemarche/www/tenders/tests.py | 92 +++++++++++++----- 6 files changed, 169 insertions(+), 111 deletions(-) create mode 100644 lemarche/templates/tenders/_detail_sidebar.html diff --git a/lemarche/templates/tenders/_detail_card.html b/lemarche/templates/tenders/_detail_card.html index 25fc853a0..d3ec24561 100644 --- a/lemarche/templates/tenders/_detail_card.html +++ b/lemarche/templates/tenders/_detail_card.html @@ -8,6 +8,7 @@ {% endif %}
+

@@ -32,6 +33,7 @@

{{ tender.sectors_list_string|safe }}

+ {% if not source_form %} {% if user.is_authenticated %} {% if user == tender.author %} diff --git a/lemarche/templates/tenders/_detail_cta.html b/lemarche/templates/tenders/_detail_cta.html index 3fa063cba..c692aadee 100644 --- a/lemarche/templates/tenders/_detail_cta.html +++ b/lemarche/templates/tenders/_detail_cta.html @@ -5,7 +5,7 @@

{{ tender.cta_card_title_text|safe }}

{{ tender.cta_card_paragraph_text|safe }}

{% if user_can_click %} - {% if tender_is_anonymous %} + {% if tender_response_is_anonymous %}
{% csrf_token %} diff --git a/lemarche/templates/tenders/_detail_sidebar.html b/lemarche/templates/tenders/_detail_sidebar.html new file mode 100644 index 000000000..c5c3c39ca --- /dev/null +++ b/lemarche/templates/tenders/_detail_sidebar.html @@ -0,0 +1,84 @@ + +{% if is_admin %} + {% include "tenders/_detail_admin_extra_info.html" with tender=tender %} +{% endif %} + +{% if user == tender.author %} + {% include "tenders/_detail_side_infos_author.html" %} +{% else %} + {% if not tender.deadline_date_outdated %} + + {% if tender.siae_email_link_click_date_or_detail_display_date_count > 0 %} + + {% endif %} + {% if not tender.response_is_anonymous %} + + {% if user.is_authenticated %} + + {% if user.kind == user.KIND_PARTNER %} + {% if not user_partner_can_display_tender_contact_details %} + + {% endif %} + + {% elif user.kind == user.KIND_SIAE %} + {% if not user.has_siae %} + + {% elif not siae_has_detail_contact_click_date %} + {% include "tenders/_detail_cta.html" with tender=tender user_can_click=True %} + {% include "tenders/_detail_cta_cocontracting.html" with tender=tender %} + {% include "tenders/_detail_cta_not_interested.html" with tender=tender user_can_click=True %} + {% endif %} + {% endif %} + + {% elif siae_id %} + {% if not siae_has_detail_contact_click_date %} + {% include "tenders/_detail_cta.html" with tender=tender user_can_click=True siae_id=siae_id %} + {% include "tenders/_detail_cta_cocontracting.html" with tender=tender siae_id=siae_id %} + {% include "tenders/_detail_cta_not_interested.html" with tender=tender siae_id=siae_id %} + {% else %} + {% include "tenders/_detail_contact.html" with tender=tender %} + {% endif %} + {% endif %} + + {% else %} + {% if user.is_authenticated or siae_id %} + {% if not siae_has_detail_contact_click_date %} + {% include "tenders/_detail_cta.html" with tender=tender user_can_click=True tender_response_is_anonymous=True %} + {% else %} + {% include "tenders/_detail_success_contact.html" %} + {% endif %} + {% endif %} + {% endif %} + + {% if not user.is_authenticated and not siae_id %} + {% include "tenders/_detail_cta.html" with tender=tender user_can_click=False %} + {% include "tenders/_detail_cta_not_interested.html" with tender=tender user_can_click=False %} + {% endif %} + {% endif %} +{% endif %} diff --git a/lemarche/templates/tenders/_detail_success_contact.html b/lemarche/templates/tenders/_detail_success_contact.html index 9ab89b439..96dd0dfb3 100644 --- a/lemarche/templates/tenders/_detail_success_contact.html +++ b/lemarche/templates/tenders/_detail_success_contact.html @@ -2,7 +2,9 @@

Votre intérêt a été signalé au client

-

S’il est intéressé, il vous recontactera via vos coordonnées de contact présentes sur votre fiche commerciale (Vérifier votre fiche).

- +

+ S'il est intéressé, il vous recontactera via vos coordonnées de contact présentes sur + votre fiche commerciale (Vérifier votre fiche). +

diff --git a/lemarche/templates/tenders/detail.html b/lemarche/templates/tenders/detail.html index da01f709f..42379f49c 100644 --- a/lemarche/templates/tenders/detail.html +++ b/lemarche/templates/tenders/detail.html @@ -27,17 +27,15 @@ {% block content %}
- {# Afficher les contacts en haut + conseil #} + {% if not tender.deadline_date_outdated and not tender.response_is_anonymous %} {% if siae_has_detail_contact_click_date %}
- {% if not tender.response_is_anonymous %} -
-
- {% include "tenders/_detail_contact.html" with tender=tender source="alert" %} -
+
+
+ {% include "tenders/_detail_contact.html" with tender=tender source="alert" %}
- {% endif %} +
diff --git a/lemarche/www/tenders/tests.py b/lemarche/www/tenders/tests.py index aed0ecbcb..88c7f611a 100644 --- a/lemarche/www/tenders/tests.py +++ b/lemarche/www/tenders/tests.py @@ -99,16 +99,16 @@ def _check_every_step(self, tenders_step_data, final_redirect_page: str = revers ) def test_anyone_can_access_create_tender(self): - # anonymous + # anonymous user url = reverse("tenders:create") response = self.client.get(url) self.assertEqual(response.status_code, 200) - # buyer + # user buyer self.client.force_login(self.user_buyer) url = reverse("tenders:create") response = self.client.get(url) self.assertEqual(response.status_code, 200) - # siae + # user siae self.client.force_login(self.user_siae) url = reverse("tenders:create") response = self.client.get(url) @@ -617,19 +617,36 @@ def setUpTestData(cls): status=tender_constants.STATUS_SENT, first_sent_at=timezone.now(), ) + cls.tender_3_response_is_anonymous = TenderFactory( + author=cls.user_buyer_1, + contact_company_name="Another company", + status=tender_constants.STATUS_SENT, + first_sent_at=timezone.now(), + response_is_anonymous=True, + ) + cls.tendersiae_3_1 = TenderSiae.objects.create( + tender=cls.tender_3_response_is_anonymous, + siae=cls.siae_1, + source="EMAIL", + email_send_date=timezone.now(), + email_link_click_date=timezone.now(), + detail_display_date=timezone.now(), + detail_contact_click_date=timezone.now(), + ) def test_anyone_can_view_sent_tenders(self): - # anonymous - url = reverse("tenders:detail", kwargs={"slug": self.tender_1.slug}) - response = self.client.get(url) - self.assertEqual(response.status_code, 200) - self.assertContains(response, "Voir l'appel d'offres") - # users - for user in User.objects.all(): - self.client.force_login(user) - url = reverse("tenders:detail", kwargs={"slug": self.tender_1.slug}) + for tender in Tender.objects.all(): + # anonymous user + url = reverse("tenders:detail", kwargs={"slug": tender.slug}) response = self.client.get(url) self.assertEqual(response.status_code, 200) + self.assertContains(response, tender.title) + # users + for user in User.objects.all(): + self.client.force_login(user) + url = reverse("tenders:detail", kwargs={"slug": tender.slug}) + response = self.client.get(url) + self.assertEqual(response.status_code, 200) def test_only_author_or_admin_can_view_non_sent_tender(self): tender_draft = TenderFactory(author=self.user_buyer_1, status=tender_constants.STATUS_DRAFT) @@ -643,7 +660,7 @@ def test_only_author_or_admin_can_view_non_sent_tender(self): validated_at=timezone.now(), ) for tender in [tender_draft, tender_published, tender_validated_but_not_sent]: - # anonymous + # anonymous user url = reverse("tenders:detail", kwargs={"slug": tender.slug}) response = self.client.get(url) self.assertEqual(response.status_code, 302) @@ -768,7 +785,7 @@ def test_tender_author_has_additional_stats(self): def test_admin_has_extra_info(self): url = reverse("tenders:detail", kwargs={"slug": self.tender_1.slug}) - # anonymous + # anonymous user response = self.client.get(url) self.assertNotContains(response, "Informations Admin") # other users @@ -782,7 +799,7 @@ def test_admin_has_extra_info(self): self.assertContains(response, "Informations Admin") def test_tender_contact_display(self): - # anonymous + # anonymous user url = reverse("tenders:detail", kwargs={"slug": self.tender_1.slug}) response = self.client.get(url) self.assertNotContains(response, "Clôturé") @@ -811,6 +828,37 @@ def test_tender_contact_display(self): self.assertContains(response, "Coordonnées") self.assertNotContains(response, "Voir l'appel d'offres") + def test_tender_response_is_anonymous_contact_display(self): + # anonymous user + url = reverse("tenders:detail", kwargs={"slug": self.tender_3_response_is_anonymous.slug}) + response = self.client.get(url) + self.assertNotContains(response, "Clôturé") + self.assertNotContains(response, "Voir l'appel d'offres") + # siae user interested + self.client.force_login(self.siae_user_1) + url = reverse("tenders:detail", kwargs={"slug": self.tender_3_response_is_anonymous.slug}) + response = self.client.get(url) + self.assertNotContains(response, "Contactez le client dès maintenant") + self.assertNotContains(response, "Voir l'appel d'offres") + self.assertContains(response, "Votre intérêt a été signalé au client") + # siae user not concerned + self.client.force_login(self.siae_user_2) + url = reverse("tenders:detail", kwargs={"slug": self.tender_3_response_is_anonymous.slug}) + response = self.client.get(url) + self.assertNotContains(response, "Voir l'appel d'offres") + # siae user without siae + self.client.force_login(self.siae_user_3) + url = reverse("tenders:detail", kwargs={"slug": self.tender_3_response_is_anonymous.slug}) + response = self.client.get(url) + self.assertNotContains(response, "veuillez d'abord vous") + self.assertNotContains(response, "Voir l'appel d'offres") + # author + self.client.force_login(self.user_buyer_1) + url = reverse("tenders:detail", kwargs={"slug": self.tender_3_response_is_anonymous.slug}) + response = self.client.get(url) + self.assertContains(response, "Coordonnées") + self.assertNotContains(response, "Voir l'appel d'offres") + def test_tender_outdated_contact_display(self): tender_2 = TenderFactory( kind=tender_constants.KIND_QUOTE, @@ -818,7 +866,7 @@ def test_tender_outdated_contact_display(self): deadline_date=timezone.now() - timedelta(days=1), ) TenderSiae.objects.create(tender=tender_2, siae=self.siae_1, detail_contact_click_date=timezone.now()) - # anonymous + # anonymous user url = reverse("tenders:detail", kwargs={"slug": tender_2.slug}) response = self.client.get(url) self.assertContains(response, "Clôturé") @@ -965,11 +1013,11 @@ def test_tender_contact_details_display(self): self.assertContains(response, "Lien partagé") def test_tender_cocontracting_display(self): - # anonymous + # anonymous user url = reverse("tenders:detail", kwargs={"slug": self.tender_1.slug}) response = self.client.get(url) self.assertNotContains(response, "Répondre en co-traitance ?") - # anonymous but with siae_id in url + # anonymous user but with siae_id in url url = reverse("tenders:detail", kwargs={"slug": self.tender_1.slug}) response = self.client.get(f"{url}?siae_id=15") self.assertContains(response, "Répondre en co-traitance ?") @@ -1009,12 +1057,12 @@ def test_update_tendersiae_stats_on_tender_view(self): self.assertEqual(self.tender_1.tendersiae_set.last().siae, self.siae_1) self.assertIsNotNone(self.tender_1.tendersiae_set.last().email_link_click_date) self.assertIsNotNone(self.tender_1.tendersiae_set.last().detail_display_date) - # first load anonymous + # first load anonymous user url = reverse("tenders:detail", kwargs={"slug": self.tender_1.slug}) response = self.client.get(url) self.assertEqual(response.status_code, 200) self.assertContains(response, "Déjà 1 prestataire inclusif") - # reload anonymous with ?siae_id= + # reload anonymous user with ?siae_id= url = reverse("tenders:detail", kwargs={"slug": self.tender_1.slug}) + f"?siae_id={self.siae_2.id}" response = self.client.get(url) self.assertEqual(response.status_code, 200) @@ -1055,7 +1103,7 @@ def test_create_tendersiae_stats_on_tender_view_by_existing_user(self): self.assertEqual(self.tender_1.tendersiae_set.last().siae, self.siae_1) self.assertIsNotNone(self.tender_1.tendersiae_set.last().email_link_click_date) self.assertIsNotNone(self.tender_1.tendersiae_set.last().detail_display_date) - # first load anonymous + # first load anonymous user url = reverse("tenders:detail", kwargs={"slug": self.tender_1.slug}) response = self.client.get(url) self.assertContains(response, "Déjà 1 prestataire inclusif") @@ -1074,7 +1122,7 @@ def test_create_tendersiae_stats_on_tender_view_by_new_user(self): self.assertEqual(self.tender_1.tendersiae_set.count(), 1) self.assertEqual(self.tender_1.tendersiae_set.first().siae, self.siae_1) self.assertIsNotNone(self.tender_1.tendersiae_set.first().detail_display_date) # siae_1 - # first load anonymous + # first load anonymous user url = reverse("tenders:detail", kwargs={"slug": self.tender_1.slug}) response = self.client.get(url) self.assertContains(response, "Déjà 1 prestataire inclusif")