From ff759e5d51b24e6c25a9216957a0cb4d85e4f4f3 Mon Sep 17 00:00:00 2001 From: vincent porte Date: Thu, 8 Feb 2024 12:06:16 +0100 Subject: [PATCH] (surveys) manage permission to access survey create form, with tally waiting list --- lacommunaute/surveys/tests/test_views.py | 27 +++++---- .../partials/header_nav_secondary_items.html | 8 +-- lacommunaute/templates/surveys/dsp_form.html | 59 ++++++++++++------- lacommunaute/users/factories.py | 6 ++ 4 files changed, 62 insertions(+), 38 deletions(-) diff --git a/lacommunaute/surveys/tests/test_views.py b/lacommunaute/surveys/tests/test_views.py index 20b024f21..501ead442 100644 --- a/lacommunaute/surveys/tests/test_views.py +++ b/lacommunaute/surveys/tests/test_views.py @@ -1,7 +1,7 @@ import pytest # noqa from django.urls import reverse from pytest_django.asserts import assertContains, assertNotContains - +from django.contrib.auth.models import Permission from lacommunaute.surveys.factories import DSPFactory from lacommunaute.surveys.models import DSP from lacommunaute.users.factories import UserFactory @@ -25,6 +25,18 @@ def test_login_required(self, db, client): response = client.get(url) assert response.status_code == 302 + def test_user_has_no_permission(self, db, client): + client.force_login(UserFactory()) + response = client.get(reverse("surveys:dsp_create")) + assertContains(response, ' + {% endif %} {% endblock content %} +{% block extra_js %} + {{ block.super }} + +{% endblock extra_js %} diff --git a/lacommunaute/users/factories.py b/lacommunaute/users/factories.py index cda945d53..d9a6a826a 100644 --- a/lacommunaute/users/factories.py +++ b/lacommunaute/users/factories.py @@ -33,3 +33,9 @@ class Meta: last_name = factory.Faker("last_name") email = factory.Faker("email") password = factory.LazyFunction(default_password) + + @factory.post_generation + def with_perm(obj, create, extracted, **kwargs): + if not create or not extracted: + return + obj.user_permissions.add(*extracted)