From 5ff9c17e117e9e3fa29fbc103d2b5da68abf6d49 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20Demont=C3=A9?= Date: Tue, 16 Jan 2024 09:45:12 +0100 Subject: [PATCH 1/2] Fix layer used for test_setup --- src/liege/urban/tests/test_setup.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/liege/urban/tests/test_setup.py b/src/liege/urban/tests/test_setup.py index 61996b78..1e69cc7b 100644 --- a/src/liege/urban/tests/test_setup.py +++ b/src/liege/urban/tests/test_setup.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- """Setup tests for this package.""" -from Products.urban.testing import URBAN_TESTS_PROFILE_INTEGRATION +from Products.urban.testing import URBAN_TESTS_CONFIG from plone import api import unittest @@ -9,7 +9,7 @@ class TestSetup(unittest.TestCase): """Test that liege.urban is properly installed.""" - layer = URBAN_TESTS_PROFILE_INTEGRATION + layer = URBAN_TESTS_CONFIG def setUp(self): """Custom shared utility setup for tests.""" @@ -31,7 +31,7 @@ def test_browserlayer(self): class TestUninstall(unittest.TestCase): - layer = URBAN_TESTS_PROFILE_INTEGRATION + layer = URBAN_TESTS_CONFIG def setUp(self): self.portal = self.layer['portal'] From 52a0f8c6e38bada187b0f4ed832d8521831d6c9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20Demont=C3=A9?= Date: Tue, 16 Jan 2024 09:50:07 +0100 Subject: [PATCH 2/2] SUP-29258: Give opinion editor roles for road decree's bound licence --- news/SUP-29258.feature | 2 + src/liege/urban/tests/test_permissions.py | 122 ++++++++++++++++++++++ 2 files changed, 124 insertions(+) create mode 100644 news/SUP-29258.feature create mode 100644 src/liege/urban/tests/test_permissions.py diff --git a/news/SUP-29258.feature b/news/SUP-29258.feature new file mode 100644 index 00000000..99d0a9de --- /dev/null +++ b/news/SUP-29258.feature @@ -0,0 +1,2 @@ +Give opinion editor roles on road decree's bound licence +[daggelpop] \ No newline at end of file diff --git a/src/liege/urban/tests/test_permissions.py b/src/liege/urban/tests/test_permissions.py new file mode 100644 index 00000000..f177da1c --- /dev/null +++ b/src/liege/urban/tests/test_permissions.py @@ -0,0 +1,122 @@ +# -*- coding: utf-8 -*- +"""Setup tests for this package.""" +import unittest + +from plone import api +from zope.event import notify +from zope.lifecycleevent import ObjectModifiedEvent + +from Products.urban.browser.urbanconfigview import AddInternalServiceForm +from Products.urban.testing import URBAN_TESTS_CONFIG_FUNCTIONAL + + +class TestOpinionEditors(unittest.TestCase): + + layer = URBAN_TESTS_CONFIG_FUNCTIONAL + + def setUp(self): + """Custom shared utility setup for tests.""" + self.portal = self.layer['portal'] + self.installer = api.portal.get_tool('portal_quickinstaller') + + with api.env.adopt_roles(["Manager"]): + + self.setup_opinion_request_type() + + self.create_internal_service( + "access", + "ACCESS", + ) + + api.user.create(email="claude@claude.com", username="claude") + api.group.add_user(groupname='Access_editors', username='claude') + api.group.add_user(groupname='opinions_editors', username='claude') + + aaa_id = self.portal.urban.codt_article127s.invokeFactory("CODT_Article127", id="aaa") + self.aaa = getattr(self.portal.urban.codt_article127s, aaa_id) + notify(ObjectModifiedEvent(self.aaa)) + + bbb_id = self.portal.urban.roaddecrees.invokeFactory("RoadDecree", id="bbb") + self.bbb = getattr(self.portal.urban.roaddecrees, bbb_id) + self.bbb.setBound_licence(self.aaa.UID()) + self.bbb.setSolicitOpinionsTo(["access"]) + self.bbb.createAllAdvices() + notify(ObjectModifiedEvent(self.bbb)) + + opinion_request = self.bbb.getAllOpinionRequests()[0] + api.user.grant_roles(username="claude", roles=["Editor"], obj=opinion_request) + + def tearDown(self): + with api.env.adopt_roles(['Manager']): + api.content.delete(self.aaa) + api.content.delete(self.bbb) + api.user.delete(username="claude") + + def setup_opinion_request_type(self): + urbaneventtypes_folder = self.portal.portal_urban.roaddecree.urbaneventtypes + + term_id = urbaneventtypes_folder.invokeFactory( + "OpinionRequestEventType", + id="ask_access_opinion", + title="Demande d'avis (ACCESS)", + description="access", + internal_service="access", + is_internal_service=True, + eventTypeType=u'Products.urban.interfaces.IOpinionRequestEvent', + eventPortalType='UrbanEventOpinionRequest', + ) + + urbaneventtypes_folder.invokeFactory( + 'UrbanEventType', + id="config-opinion-request", + title="*** Demande d'avis CONFIG ***", + activatedFields=[], + TALCondition="python: False", + podTemplates=({'id': "cu2-avis.odt", 'title': "Courrier de demande d'avis"},), + eventTypeType='Products.urban.interfaces.IOpinionRequestEvent', + eventPortalType='UrbanEventOpinionRequest' + ) + + def create_internal_service(self, service_id, service_name): + add_internal_service_form = AddInternalServiceForm({}, {}) + editor_group_id, validator_group_id = add_internal_service_form.create_groups( + service_id.capitalize(), service_name + ) + ( + task_config_answer, + task_config_validate, + ) = add_internal_service_form.create_task_configs( + service_id, service_name, editor_group_id, validator_group_id + ) + add_internal_service_form.set_registry_mapping( + service_id, + service_name, + editor_group_id, + validator_group_id, + task_config_answer, + task_config_validate, + ) + + def test_linked_opinion_editors_view(self): + # before + self.assertFalse(api.user.has_permission('View', username='claude', obj=self.aaa)) + self.assertFalse(api.user.has_permission('View', username='claude', obj=self.bbb)) + self.assertNotIn("ExternalReader", api.user.get_roles(username='claude', obj=self.aaa)) + self.assertNotIn("ExternalReader", api.user.get_roles(username='claude', obj=self.bbb)) + + opinion_request = self.bbb.getAllOpinionRequests()[0] + with api.env.adopt_user("claude"): + api.content.transition(opinion_request, "ask_opinion") + api.content.transition(opinion_request, "ask_validation") + + with api.env.adopt_roles(["Manager"]): + api.content.transition(self.aaa, "ask_address_validation") + api.content.transition(self.aaa, "validate_address") + api.content.transition(self.bbb, "to_public_investigation") + api.content.transition(self.bbb, "to_technical_analysis_post_investigation") + + # after + self.assertTrue(api.user.has_permission('View', username='claude', obj=self.aaa)) + self.assertTrue(api.user.has_permission('View', username='claude', obj=self.bbb)) + self.assertIn("ExternalReader", api.user.get_roles(username='claude', obj=self.aaa)) + self.assertIn("ExternalReader", api.user.get_roles(username='claude', obj=self.bbb))