diff --git a/lemarche/tenders/models.py b/lemarche/tenders/models.py
index ca82050d7..dc261e9ac 100644
--- a/lemarche/tenders/models.py
+++ b/lemarche/tenders/models.py
@@ -588,6 +588,14 @@ def set_hubspot_id(self, hubspot_deal_id, with_save=True):
if with_save:
self.save()
+ @property
+ def is_draft(self) -> bool:
+ return self.status == self.STATUS_DRAFT
+
+ @property
+ def is_pending_validation(self) -> bool:
+ return self.status == self.STATUS_PUBLISHED
+
@property
def is_validated(self) -> bool:
return self.validated_at and self.status == self.STATUS_VALIDATED
diff --git a/lemarche/tenders/tests.py b/lemarche/tenders/tests.py
index 8f84d22a3..201bc4f6e 100644
--- a/lemarche/tenders/tests.py
+++ b/lemarche/tenders/tests.py
@@ -103,6 +103,16 @@ def test_questions_list(self):
self.assertEqual(len(tender_with_questions.questions_list()), 2)
self.assertEqual(tender_with_questions.questions_list()[0].get("text"), tender_question_1.text)
+ def test_status(self):
+ tender_draft = TenderFactory(status=tender_constants.STATUS_DRAFT)
+ tender_pending_validation = TenderFactory(status=tender_constants.STATUS_PUBLISHED)
+ tender_validated_half = TenderFactory(status=tender_constants.STATUS_VALIDATED)
+ tender_validated_full = TenderFactory(status=tender_constants.STATUS_VALIDATED, validated_at=timezone.now())
+ self.assertTrue(tender_draft.is_draft, True)
+ self.assertTrue(tender_pending_validation.is_pending_validation, True)
+ self.assertTrue(tender_validated_half.is_validated, False)
+ self.assertTrue(tender_validated_full.is_validated, True)
+
class TenderModelSaveTest(TestCase):
def test_set_slug(self):
diff --git a/lemarche/www/siaes/tests.py b/lemarche/www/siaes/tests.py
index a4da1e291..460f8e22b 100644
--- a/lemarche/www/siaes/tests.py
+++ b/lemarche/www/siaes/tests.py
@@ -1088,11 +1088,35 @@ def test_should_bring_the_siae_closer_to_the_city_to_the_top(self):
class SiaeDetailTest(TestCase):
@classmethod
def setUpTestData(cls):
- cls.user = UserFactory()
+ cls.user_buyer = UserFactory(kind="BUYER")
+ cls.user_partner = UserFactory(kind="PARTNER")
+ cls.user_siae = UserFactory(kind="SIAE")
+ cls.user_admin = UserFactory(kind="ADMIN")
+ cls.siae = SiaeFactory(name="ABC Insertion")
+ cls.siae.users.add(cls.user_siae)
- def test_should_display_contact_fields_to_authenticated_users(self):
- siae = SiaeFactory(name="Ma boite", contact_email="contact@example.com")
- self.client.force_login(self.user)
- url = reverse("siae:detail", args=[siae.slug])
+ def test_should_display_contact_cta(self):
+ url = reverse("siae:detail", args=[self.siae.slug])
+ # anonymous
response = self.client.get(url)
self.assertContains(response, "Contacter la structure")
+ # authenticated
+ for user in [self.user_buyer, self.user_partner, self.user_siae, self.user_admin]:
+ self.client.force_login(user)
+ response = self.client.get(url)
+ self.assertContains(response, "Contacter la structure")
+
+ def test_admin_has_extra_info(self):
+ url = reverse("siae:detail", args=[self.siae.slug])
+ # anonymous
+ response = self.client.get(url)
+ self.assertNotContains(response, "Informations Admin")
+ # other users
+ for user in [self.user_buyer, self.user_partner, self.user_siae]:
+ self.client.force_login(user)
+ response = self.client.get(url)
+ self.assertNotContains(response, "Informations Admin")
+ # admin
+ self.client.force_login(self.user_admin)
+ response = self.client.get(url)
+ self.assertContains(response, "Informations Admin")
diff --git a/lemarche/www/tenders/tests.py b/lemarche/www/tenders/tests.py
index 3f1f97a67..e99dc36e6 100644
--- a/lemarche/www/tenders/tests.py
+++ b/lemarche/www/tenders/tests.py
@@ -609,6 +609,21 @@ def test_tender_author_has_additional_stats(self):
self.assertNotContains(response, "1 prestataire ciblé")
self.assertNotContains(response, "1 prestataire intéressé")
+ def test_admin_has_extra_info(self):
+ url = reverse("tenders:detail", kwargs={"slug": self.tender_1.slug})
+ # anonymous
+ response = self.client.get(url)
+ self.assertNotContains(response, "Informations Admin")
+ # other users
+ for user in [self.user_buyer_1, self.user_partner, self.siae_user_1]:
+ self.client.force_login(user)
+ response = self.client.get(url)
+ self.assertNotContains(response, "Informations Admin")
+ # admin
+ self.client.force_login(self.user_admin)
+ response = self.client.get(url)
+ self.assertContains(response, "Informations Admin")
+
def test_update_tendersiae_stats_on_tender_view(self):
self.tender_1.siaes.add(self.siae_2)
self.assertEqual(self.tender_1.tendersiae_set.count(), 1 + 1)
diff --git a/lemarche/www/tenders/views.py b/lemarche/www/tenders/views.py
index f0528273f..c33c2abf3 100644
--- a/lemarche/www/tenders/views.py
+++ b/lemarche/www/tenders/views.py
@@ -327,6 +327,7 @@ def get_context_data(self, **kwargs):
user_kind = user.kind if user.is_authenticated else "anonymous"
show_nps = self.request.GET.get("nps", None)
# enrich context
+ context["is_admin"] = self.request.user.is_authenticated and self.request.user.is_admin
context["parent_title"] = TITLE_DETAIL_PAGE_SIAE if user_kind == User.KIND_SIAE else TITLE_DETAIL_PAGE_OTHERS
context["tender_kind_display"] = (
TITLE_KIND_SOURCING_SIAE
@@ -339,11 +340,7 @@ def get_context_data(self, **kwargs):
tender=self.object, siae_id=int(self.siae_id), detail_contact_click_date__isnull=False
).exists()
if user.is_authenticated:
- if self.object.author == user:
- context["is_draft"] = self.object.status == tender_constants.STATUS_DRAFT
- context["is_pending_validation"] = self.object.status == tender_constants.STATUS_PUBLISHED
- context["is_validated"] = self.object.status == tender_constants.STATUS_VALIDATED
- elif user.kind == User.KIND_SIAE:
+ if user.kind == User.KIND_SIAE:
context["user_siae_has_detail_contact_click_date"] = TenderSiae.objects.filter(
tender=self.object, siae__in=user.siaes.all(), detail_contact_click_date__isnull=False
).exists()