Skip to content

Commit

Permalink
Exercício 31 - Tipo Pessoa
Browse files Browse the repository at this point in the history
  • Loading branch information
jadirj committed Oct 14, 2024
1 parent e1d5a03 commit fb71ab1
Show file tree
Hide file tree
Showing 11 changed files with 226 additions and 2 deletions.
12 changes: 12 additions & 0 deletions backend/src/trepr/intranet/content/pessoa.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from plone.dexterity.content import Container
from plone.supermodel import model
from zope.interface import implementer


class IPessoa(model.Schema):
"""Definição de uma Pessoa."""


@implementer(IPessoa)
class Pessoa(Container):
"""Uma Pessoa no TRE-PR."""
5 changes: 5 additions & 0 deletions backend/src/trepr/intranet/permissions.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@
title="trepr.intranet: Add Area"
/>

<permission
id="trepr.intranet.pessoa.add"
title="trepr.intranet: Add Pessoa"
/>

</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>1004</version>
<version>1005</version>
<dependencies>
<dependency>profile-plone.volto:default</dependency>
</dependencies>
Expand Down
7 changes: 7 additions & 0 deletions backend/src/trepr/intranet/profiles/default/rolemap.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,12 @@
<role name="Manager" />
<role name="Site Administrator" />
</permission>
<permission acquire="False"
name="trepr.intranet: Add Pessoa"
>
<role name="Manager" />
<role name="Editor" />
<role name="Site Administrator" />
</permission>
</permissions>
</rolemap>
4 changes: 4 additions & 0 deletions backend/src/trepr/intranet/profiles/default/types.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,8 @@
name="Area"
/>

<object meta_type="Dexterity FTI"
name="Pessoa"
/>

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

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

<property name="allow_discussion">False</property>
<property name="factory">Pessoa</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.pessoa.add</property>
<property name="klass">trepr.intranet.content.pessoa.Pessoa</property>
<property name="schema">trepr.intranet.content.pessoa.IPessoa</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="trepr.intranet.behavior.contato" />
<element value="trepr.intranet.behavior.endereco" />
<element value="plone.leadimage" />
<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 @@ -55,4 +55,19 @@
/>
</genericsetup:upgradeSteps>

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

</configure>
77 changes: 77 additions & 0 deletions backend/tests/content/test_content_pessoa.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
from AccessControl import Unauthorized
from plone import api
from plone.dexterity.fti import DexterityFTI
from trepr.intranet.content.pessoa import Pessoa
from zope.component import createObject

import pytest


CONTENT_TYPE = "Pessoa"


@pytest.fixture
def area_payload() -> dict:
"""Return a payload to create a new pessoa."""
return {
"type": "Pessoa",
"id": "jadir",
"title": "Jadir Junior",
"description": ("Trabalha no NWEB"),
"email": "[email protected]",
"telefone": "(41) 3330.8485",
}


class TestPessoa:
@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, Pessoa)

@pytest.mark.parametrize(
"behavior",
[
"plone.basic",
"plone.namefromtitle",
"plone.shortname",
"plone.excludefromnavigation",
"plone.versioning",
"trepr.intranet.behavior.contato",
"trepr.intranet.behavior.endereco",
"plone.leadimage",
"plone.constraintypes",
],
)
def test_has_behavior(self, get_behaviors, behavior):
assert behavior in get_behaviors(CONTENT_TYPE)

@pytest.mark.parametrize(
"role,allowed",
[
["Manager", True],
["Site Administrator", True],
["Editor", True],
["Reviewer", False],
["Contributor", False],
["Reader", False],
],
)
def test_create(self, area_payload, role: str, allowed: bool):
with api.env.adopt_roles([role]):
if allowed:
content = api.content.create(container=self.portal, **area_payload)
assert content.portal_type == CONTENT_TYPE
assert isinstance(content, Pessoa)
else:
with pytest.raises(Unauthorized):
api.content.create(container=self.portal, **area_payload)
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") == "1004"
assert profile_last_version(f"{PACKAGE_NAME}:default") == "1005"
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import React from 'react';
import PropTypes from 'prop-types';
import { Container } from '@plone/components';
import { Image } from '@plone/volto/components';
import ContactInfo from '../ContactInfo/ContactInfo';
import EnderecoInfo from '../EnderecoInfo/EnderecoInfo';

const PessoaView = (props) => {
const { content } = props;
return (
<Container narrow id="page-document" className="view-wrapper pessoa-view">
{content.image && (
<Container className={'image'}>
<Image
className="documentImage ui right floated image"
alt={content.title}
title={content.title}
item={content}
imageField="image"
responsive={true}
/>
</Container>
)}
<h1 className="documentFirstHeading">{content.title}</h1>
{content.description && (
<p className="documentDescription">{content.description}</p>
)}
<EnderecoInfo content={content} />
<ContactInfo content={content} />
</Container>
);
};
/**
* Property types.
* @property {Object} propTypes Property types.
* @static
*/
PessoaView.propTypes = {
content: PropTypes.shape({
title: PropTypes.string,
description: PropTypes.string,
image: PropTypes.shape({
scales: PropTypes.shape({
preview: PropTypes.shape({
download: PropTypes.string,
}),
}),
}),
email: PropTypes.string,
telefone: PropTypes.string,
endereco: PropTypes.string,
complemento: PropTypes.string,
cidade: PropTypes.string,
estado: PropTypes.string,
cep: PropTypes.string,
}).isRequired,
};
export default PessoaView;
2 changes: 2 additions & 0 deletions frontend/packages/volto-trepr-intranet/src/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Views
import AreaView from './components/Views/AreaView';
import PessoaView from './components/Views/PessoaView';

const applyConfig = (config) => {
config.settings = {
Expand All @@ -26,6 +27,7 @@ const applyConfig = (config) => {
config.views.contentTypesViews = {
...config.views.contentTypesViews,
Area: AreaView,
Pessoa: PessoaView,
};
return config;
};
Expand Down

0 comments on commit fb71ab1

Please sign in to comment.