Skip to content

Commit

Permalink
fix(Structures): afficher seulement aux admins l'information que la s…
Browse files Browse the repository at this point in the history
…tructure n'est pas encore inscrite (#1239)
  • Loading branch information
raphodn authored May 30, 2024
1 parent 73dd4d9 commit e26c47b
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 6 deletions.
7 changes: 6 additions & 1 deletion lemarche/templates/siaes/_card_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,19 @@
<div class="col-sm-12">
<h1 class="h2 mb-0">
{{ siae.name_display }}
{% if user.is_authenticated and user.is_admin and not siae.user_count %}
<span class="badge badge-base rounded-pill text-warning fs-sm">
pas encore inscrite
</span>
{% endif %}
</h1>
{% if siae.super_badge %}
<span class="badge badge-base rounded-pill super-badge-badge text-primary mt-2 font-weight-bold">
<i class="ri-award-fill"></i>
Super prestataire
</span>
{% endif %}
<p class="mt-3 mb-1 font-italic">(Dernière activité il y a {{ siae.latest_activity_at|timesince }})</p>
<p class="mt-3 mb-2 font-italic">(Dernière activité il y a {{ siae.latest_activity_at|timesince }})</p>
{% if user.is_authenticated %}
{% if siae.in_user_favorite_list_count_annotated %}
<a href="#" id="favorite-remove-modal-btn" class="btn btn-favorite" data-toggle="modal" data-target="#favorite_item_remove_modal" title="Dans votre liste d'achat">
Expand Down
6 changes: 4 additions & 2 deletions lemarche/templates/siaes/_card_search_result.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@
<div class="col">
<h2 class="h4 mb-0">
{{ siae.name_display }}
{% if not siae.user_count %}
<span class="fs-sm font-weight-normal">(bientôt inscrite sur le marché)</span>
{% if user.is_authenticated and user.is_admin and not siae.user_count %}
<span class="badge badge-base rounded-pill text-warning fs-sm">
pas encore inscrite
</span>
{% endif %}
</h2>
{% if siae.super_badge %}
Expand Down
28 changes: 25 additions & 3 deletions lemarche/www/siaes/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,39 @@
from lemarche.www.siaes.forms import SiaeFilterForm


class SiaeSearchFilterTest(TestCase):
class SiaeSearchDisplayResultsTest(TestCase):
@classmethod
def setUpTestData(cls):
SiaeFactory(is_active=True)
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_with_user = SiaeFactory(is_active=True, user_count=0)
cls.siae_without_user = SiaeFactory(is_active=True, user_count=1)
SiaeFactory(is_active=False)

def test_search_should_return_live_siaes(self):
url = reverse("siae:search_results")
response = self.client.get(url)
siaes = list(response.context["siaes"])
self.assertEqual(len(siaes), 1)
self.assertEqual(len(siaes), 2)
self.assertContains(response, self.siae_with_user.name_display)
self.assertContains(response, self.siae_without_user.name_display)

def test_admin_has_extra_info(self):
url = reverse("siae:search_results")
# anonymous
response = self.client.get(url)
self.assertNotContains(response, "pas encore inscrite")
# 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, "pas encore inscrite")
# admin
self.client.force_login(self.user_admin)
response = self.client.get(url)
self.assertContains(response, "pas encore inscrite")


class SiaeSearchNumQueriesTest(TestCase):
Expand Down

0 comments on commit e26c47b

Please sign in to comment.