Skip to content

Commit

Permalink
Exercício 21: Passo de atualização para o tipo Área
Browse files Browse the repository at this point in the history
  • Loading branch information
jadirj committed Oct 10, 2024
1 parent 3164c0a commit 86d1d2c
Show file tree
Hide file tree
Showing 10 changed files with 180 additions and 6 deletions.
1 change: 1 addition & 0 deletions backend/src/trepr/intranet/configure.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

<include file="dependencies.zcml" />
<include file="profiles.zcml" />
<include file="permissions.zcml" />

<include package=".controlpanel" />
<include package=".indexers" />
Expand Down
34 changes: 34 additions & 0 deletions backend/src/trepr/intranet/content/area.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
from plone.dexterity.content import Container
from plone.schema.email import Email
from plone.supermodel import model
from trepr.intranet import _
from zope import schema
from zope.interface import implementer


class IArea(model.Schema):
"""Definição de uma Área."""

model.fieldset(
"contato",
_("Contato"),
fields=[
"email",
"telefone",
],
)
email = Email(
title=_("Email"),
required=True,
)

telefone = schema.TextLine(
title=_("Telefone"),
description=_("Informe o telefone de contato"),
required=False,
)


@implementer(IArea)
class Area(Container):
"""Uma Área no TRE-PR."""
16 changes: 16 additions & 0 deletions backend/src/trepr/intranet/permissions.zcml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<configure
xmlns="http://namespaces.zope.org/zope"
xmlns:zcml="http://namespaces.zope.org/zcml"
i18n_domain="trepr.intranet"
>

<configure zcml:condition="installed AccessControl.security">

<permission
id="trepr.intranet.area.add"
title="trepr.intranet: Add Area"
/>

</configure>

</configure>
2 changes: 1 addition & 1 deletion backend/src/trepr/intranet/profiles/default/metadata.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<metadata>
<version>1002</version>
<version>1003</version>
<dependencies>
<dependency>profile-plone.volto:default</dependency>
</dependencies>
Expand Down
7 changes: 6 additions & 1 deletion backend/src/trepr/intranet/profiles/default/rolemap.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<rolemap>
<permissions>

<permission acquire="False"
name="trepr.intranet: Add Area"
>
<role name="Manager" />
<role name="Site Administrator" />
</permission>
</permissions>
</rolemap>
6 changes: 3 additions & 3 deletions backend/src/trepr/intranet/profiles/default/types.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
<object meta_type="Plone Types Tool"
name="portal_types"
>
<!--

<object meta_type="Dexterity FTI"
name="MyType"
name="Area"
/>
-->

</object>
43 changes: 43 additions & 0 deletions backend/src/trepr/intranet/profiles/default/types/Area.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?xml version="1.0" encoding="utf-8"?>
<object xmlns:i18n="http://xml.zope.org/namespaces/i18n"
meta_type="Dexterity FTI"
name="Area"
i18n:domain="trepr.intranet"
>

<!-- Basic properties -->
<property name="title"
i18n:translate=""
>Área</property>
<property name="description"
i18n:translate=""
>Uma Área dentro do TRE-PR</property>

<property name="allow_discussion">False</property>
<property name="factory">Area</property>

<!-- Hierarchy control -->
<property name="filter_content_types">False</property>
<property name="allowed_content_types" />
<property name="global_allow">True</property>

<!-- Schema, class and security -->
<property name="add_permission">trepr.intranet.area.add</property>
<property name="klass">trepr.intranet.content.area.Area</property>
<property name="schema">trepr.intranet.content.area.IArea</property>

<!-- Enabled behaviors -->
<property name="behaviors"
purge="false"
>
<element value="plone.basic" />
<element value="plone.namefromtitle" />
<element value="plone.shortname" />
<element value="plone.excludefromnavigation" />
<element value="volto.blocks" />
<element value="volto.preview_image" />
<element value="plone.constraintypes" />
<element value="plone.versioning" />
</property>

</object>
15 changes: 15 additions & 0 deletions backend/src/trepr/intranet/upgrades/configure.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,19 @@
/>
</genericsetup:upgradeSteps>

<genericsetup:upgradeSteps
profile="trepr.intranet:default"
source="1002"
destination="1003"
>
<genericsetup:upgradeDepends
title="Adiciona o tipo Área"
import_steps="typeinfo"
/>
<genericsetup:upgradeDepends
title="Aplica permissionamento para tipo de conteúdo Área"
import_steps="rolemap"
/>
</genericsetup:upgradeSteps>

</configure>
60 changes: 60 additions & 0 deletions backend/tests/content/test_content_area.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
from plone import api
from plone.dexterity.fti import DexterityFTI
from trepr.intranet.content.area import Area
from zope.component import createObject

import pytest


CONTENT_TYPE = "Area"


@pytest.fixture
def area_payload() -> dict:
"""Return a payload to create a new area."""
return {
"type": "Area",
"id": "ti",
"title": "Tecnologia da Informação",
"description": ("Área responsável por TI"),
"email": "[email protected]",
"telefone": "(41) 3210.1234",
}


class TestArea:
@pytest.fixture(autouse=True)
def _setup(self, get_fti, portal):
self.fti = get_fti(CONTENT_TYPE)
self.portal = portal

def test_fti(self):
assert isinstance(self.fti, DexterityFTI)

def test_factory(self):
factory = self.fti.factory
obj = createObject(factory)
assert obj is not None
assert isinstance(obj, Area)

@pytest.mark.parametrize(
"behavior",
[
"plone.basic",
"plone.namefromtitle",
"plone.shortname",
"plone.excludefromnavigation",
"plone.versioning",
"volto.blocks",
"plone.constraintypes",
"volto.preview_image",
],
)
def test_has_behavior(self, get_behaviors, behavior):
assert behavior in get_behaviors(CONTENT_TYPE)

def test_create(self, area_payload):
with api.env.adopt_roles(["Manager"]):
content = api.content.create(container=self.portal, **area_payload)
assert content.portal_type == CONTENT_TYPE
assert isinstance(content, Area)
2 changes: 1 addition & 1 deletion backend/tests/setup/test_setup_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ def test_browserlayer(self, browser_layers):

def test_latest_version(self, profile_last_version):
"""Test latest version of default profile."""
assert profile_last_version(f"{PACKAGE_NAME}:default") == "1002"
assert profile_last_version(f"{PACKAGE_NAME}:default") == "1003"

0 comments on commit 86d1d2c

Please sign in to comment.