Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Dépôt de besoin] Faire un encart dédié aux informations admin #926

Merged
merged 3 commits into from
Oct 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions lemarche/templates/tenders/_detail_admin_extra_info.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<div class="alert alert-warning">
<h2 class="h3">Informations Admin</h2>
<div class="row">
<div class="col-12">
<ul class="list-unstyled mb-0">
<li class="mb-2">
Publié le {{ tender.published_at|date }}
</li>
<li class="mb-2">
{% if tender.is_validated %}
Validé le {{ tender.validated_at|date }}
{% else %}
Statut : {{ tender.get_status_display }}
{% endif %}
</li>
<li class="mb-2">
<i class="ri-focus-2-line"></i>
{{ tender.siae_email_send_date_count }} prestataire{{ tender.siae_email_send_date_count|pluralize }} ciblé{{ tender.siae_email_send_date_count|pluralize }}
</li>
<li class="mb-2">
<i class="ri-focus-2-line"></i>
{{ tender.siae_email_link_click_date_or_detail_display_date_count }} prestataire{{ tender.siae_email_link_click_date_or_detail_display_date_count|pluralize }} qui {{ tender.siae_email_link_click_date_or_detail_display_date_count|pluralize:'a,ont' }} vu
</li>
<li class="mb-2">
<i class="ri-thumb-up-line"></i>
{{ tender.siae_detail_contact_click_date_count }} prestataire{{ tender.siae_detail_contact_click_date_count|pluralize }} intéressé{{ tender.siae_detail_contact_click_date_count|pluralize }}
</li>
{% if not tender.deadline_date_outdated %}
<li class="mb-2">
Transactionné :
{% if tender.siae_transactioned == None %}
Inconnu
{% else %}
{{ tender.siae_transactioned.value|yesno:"Oui,Non" }}
{% endif %}
</li>
{% endif %}
<li>
<a href="{% url 'admin:tenders_tender_change' tender.id %}" target="_blank" id="tender-detail-admin-btn" class="btn btn-sm btn-outline-primary btn-ico">
<span>
Lien vers l'admin&nbsp;
<i class="ri-external-link-line" aria-hidden="true"></i>
</span>
</a>
</li>
</ul>
</div>
</div>
</div>
9 changes: 6 additions & 3 deletions lemarche/templates/tenders/detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,11 @@
</div>
{# Sidebar with actions #}
<div class="col-12 col-lg-4 order-1 order-lg-2">
{% if is_admin %}
{% include "tenders/_detail_admin_extra_info.html" with tender=tender %}
{% endif %}
{% if user == tender.author %}
{% if is_draft %}
{% if tender.is_draft %}
<div class="alert alert-warning fade show" role="status">
<div class="row">
<div class="col-auto pr-0">
Expand All @@ -75,7 +78,7 @@
<span>Modifier</span>
</a>
{% endif %}
{% if is_pending_validation %}
{% if tender.is_pending_validation %}
<div class="alert alert-info fade show" role="status">
<div class="row">
<div class="col-auto pr-0">
Expand All @@ -87,7 +90,7 @@
</div>
</div>
{% endif %}
{% if is_validated %}
{% if tender.is_validated %}
<div class="alert alert-success fade show" role="status">
<div class="row">
<div class="col-auto pr-0">
Expand Down
8 changes: 8 additions & 0 deletions lemarche/tenders/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions lemarche/tenders/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
34 changes: 29 additions & 5 deletions lemarche/www/siaes/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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="[email protected]")
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")
15 changes: 15 additions & 0 deletions lemarche/www/tenders/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 2 additions & 5 deletions lemarche/www/tenders/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
Expand Down