diff --git a/backend/src/trepr/intranet/configure.zcml b/backend/src/trepr/intranet/configure.zcml index eea0354..e2926c5 100644 --- a/backend/src/trepr/intranet/configure.zcml +++ b/backend/src/trepr/intranet/configure.zcml @@ -20,5 +20,6 @@ + diff --git a/backend/src/trepr/intranet/subscribers/__init__.py b/backend/src/trepr/intranet/subscribers/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/backend/src/trepr/intranet/subscribers/area.py b/backend/src/trepr/intranet/subscribers/area.py new file mode 100644 index 0000000..05160af --- /dev/null +++ b/backend/src/trepr/intranet/subscribers/area.py @@ -0,0 +1,15 @@ +from trepr.intranet import logger +from trepr.intranet.content.area import Area +from zope.lifecycleevent import ObjectAddedEvent + + +def _update_excluded_from_nav(obj: Area): + """Update excluded_from_nav in the Area object.""" + description = obj.description + obj.exclude_from_nav = False if description else True + logger.info(f"Atualizado o campo excluded_from_nav para {obj.title}") + + +def added(obj: Area, event: ObjectAddedEvent): + """Post creation handler for Area.""" + _update_excluded_from_nav(obj) diff --git a/backend/src/trepr/intranet/subscribers/configure.zcml b/backend/src/trepr/intranet/subscribers/configure.zcml new file mode 100644 index 0000000..402086b --- /dev/null +++ b/backend/src/trepr/intranet/subscribers/configure.zcml @@ -0,0 +1,9 @@ + + + + + diff --git a/backend/tests/content/test_content_area.py b/backend/tests/content/test_content_area.py index 29f727e..45bfa47 100644 --- a/backend/tests/content/test_content_area.py +++ b/backend/tests/content/test_content_area.py @@ -76,3 +76,22 @@ def test_create(self, area_payload, role: str, allowed: bool): else: with pytest.raises(Unauthorized): api.content.create(container=self.portal, **area_payload) + + def test_subscriber_added_with_description_value(self, area_payload): + container = self.portal + with api.env.adopt_roles(["Manager"]): + area = api.content.create( + container=container, + **area_payload, + ) + assert area.exclude_from_nav is False + + def test_subscriber_added_without_description_value(self, area_payload): + from copy import deepcopy + + container = self.portal + with api.env.adopt_roles(["Manager"]): + payload = deepcopy(area_payload) + payload["description"] = "" + area = api.content.create(container=container, **payload) + assert area.exclude_from_nav is True