Skip to content

Commit

Permalink
Serializar data de aniversário completa apenas para quem pode editar …
Browse files Browse the repository at this point in the history
…o conteúdo (Fix #3)
  • Loading branch information
ericof committed Jul 23, 2024
1 parent 6f9d6b0 commit fcec10d
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 3 deletions.
1 change: 1 addition & 0 deletions backend/news/3.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Serializar data de aniversário completa apenas para quem pode editar o conteúdo [@ericof]
11 changes: 11 additions & 0 deletions backend/src/plonegovbr/intranet/serializers/colaborador.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from Acquisition import aq_parent
from plone import api
from plone.restapi.interfaces import ISerializeToJson
from plone.restapi.interfaces import ISerializeToJsonSummary
from plone.restapi.serializer.converters import json_compatible
Expand All @@ -24,6 +25,16 @@ def get_area_info(self):

def __call__(self, version=None, include_items=True):
result = super().__call__(version, include_items)
birthdate = self.context.birthdate
if self.context.birthdate:
result["aniversario"] = f"{birthdate.day:02d}/{birthdate.month:02d}"
can_edit = api.user.has_permission(
permission="Modify portal content", obj=self.context
)
if not can_edit:
# Do not show birthdate unless user can edit the content
result.pop("birthdate", None)

result.update(
json_compatible({
"area_info": self.get_area_info(),
Expand Down
1 change: 1 addition & 0 deletions frontend/packages/portalbrasil-intranet/news/3.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Exibe data de aniversário de um colaborador [@ericof]
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { UniversalLink } from '@plone/volto/components';
import { TabPane, Tab } from 'semantic-ui-react';
import { TableRow, TableCell, TableBody, Table } from 'semantic-ui-react';

const DadosPessoais = ({ area_info, cpf, id }) => {
const DadosPessoais = ({ area_info, aniversario, id }) => {
return (
<Table className={'details'}>
<TableBody>
Expand All @@ -24,6 +24,12 @@ const DadosPessoais = ({ area_info, cpf, id }) => {
</TableCell>
</TableRow>
)}
{aniversario && (
<TableRow>
<TableCell className={'label'}>Aniversário</TableCell>
<TableCell className={'value'}>{aniversario}</TableCell>
</TableRow>
)}
</TableBody>
</Table>
);
Expand All @@ -47,14 +53,27 @@ const DadosContato = ({ email, telefone }) => {

const ColaboradorView = (props) => {
const { content } = props;
const { title, area_info, id, email, telefone, description, image } = content;
const {
title,
area_info,
id,
email,
aniversario,
telefone,
description,
image,
} = content;
const img = image?.scales?.thumb;
const panes = [
{
menuItem: 'Informações',
render: () => (
<TabPane>
<DadosPessoais area_info={area_info} id={id} />
<DadosPessoais
area_info={area_info}
id={id}
aniversario={aniversario}
/>
</TabPane>
),
},
Expand Down

0 comments on commit fcec10d

Please sign in to comment.