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

SUP-29258_linked_opinion_editors_permissions #5

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions news/SUP-29258.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Give opinion editor roles on road decree's bound licence
[daggelpop]
122 changes: 122 additions & 0 deletions src/liege/urban/tests/test_permissions.py
Original file line number Diff line number Diff line change
@@ -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="[email protected]", 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))
6 changes: 3 additions & 3 deletions src/liege/urban/tests/test_setup.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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."""
Expand All @@ -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']
Expand Down