Restrição de operação de crud para criação e edição de filas. Apenas o master tem esse poder

pull/1/head
adriano 2022-06-15 20:36:21 -03:00
parent 755584a881
commit 9bb316a0cf
3 changed files with 279 additions and 236 deletions

View File

@ -215,60 +215,60 @@ const Connections = () => {
yes={() => ( yes={() => (
<> <>
{whatsApp.status === "qrcode" && ( {whatsApp.status === "qrcode" && (
<Button <Button
size="small" size="small"
variant="contained" variant="contained"
color="primary" color="primary"
onClick={() => handleOpenQrModal(whatsApp)} onClick={() => handleOpenQrModal(whatsApp)}
> >
{i18n.t("connections.buttons.qrcode")} {i18n.t("connections.buttons.qrcode")}
</Button> </Button>
)} )}
{whatsApp.status === "DISCONNECTED" && ( {whatsApp.status === "DISCONNECTED" && (
<> <>
<Button <Button
size="small" size="small"
variant="outlined" variant="outlined"
color="primary" color="primary"
onClick={() => handleStartWhatsAppSession(whatsApp.id)} onClick={() => handleStartWhatsAppSession(whatsApp.id)}
> >
{i18n.t("connections.buttons.tryAgain")} {i18n.t("connections.buttons.tryAgain")}
</Button>{" "} </Button>{" "}
<Button <Button
size="small" size="small"
variant="outlined" variant="outlined"
color="secondary" color="secondary"
onClick={() => handleRequestNewQrCode(whatsApp.id)} onClick={() => handleRequestNewQrCode(whatsApp.id)}
> >
{i18n.t("connections.buttons.newQr")} {i18n.t("connections.buttons.newQr")}
</Button> </Button>
</>
)}
{(whatsApp.status === "CONNECTED" ||
whatsApp.status === "PAIRING" ||
whatsApp.status === "TIMEOUT") && (
<Button
size="small"
variant="outlined"
color="secondary"
onClick={() => {
handleOpenConfirmationModal("disconnect", whatsApp.id);
}}
>
{i18n.t("connections.buttons.disconnect")}
</Button>
)}
{whatsApp.status === "OPENING" && (
<Button size="small" variant="outlined" disabled color="default">
{i18n.t("connections.buttons.connecting")}
</Button>
)}
</> </>
)}
{(whatsApp.status === "CONNECTED" ||
whatsApp.status === "PAIRING" ||
whatsApp.status === "TIMEOUT") && (
<Button
size="small"
variant="outlined"
color="secondary"
onClick={() => {
handleOpenConfirmationModal("disconnect", whatsApp.id);
}}
>
{i18n.t("connections.buttons.disconnect")}
</Button>
)}
{whatsApp.status === "OPENING" && (
<Button size="small" variant="outlined" disabled color="default">
{i18n.t("connections.buttons.connecting")}
</Button>
)}
</>
)} )}
/> />
); );
}; };
@ -315,156 +315,162 @@ const Connections = () => {
return ( return (
<Can <Can
role={user.profile} role={user.profile}
perform="connections-view:show" perform="connections-view:show"
yes={() => ( yes={() => (
<MainContainer> <MainContainer>
<ConfirmationModal <ConfirmationModal
title={confirmModalInfo.title} title={confirmModalInfo.title}
open={confirmModalOpen} open={confirmModalOpen}
onClose={setConfirmModalOpen} onClose={setConfirmModalOpen}
onConfirm={handleSubmitConfirmationModal} onConfirm={handleSubmitConfirmationModal}
> >
{confirmModalInfo.message} {confirmModalInfo.message}
</ConfirmationModal> </ConfirmationModal>
<QrcodeModal <QrcodeModal
open={qrModalOpen} open={qrModalOpen}
onClose={handleCloseQrModal} onClose={handleCloseQrModal}
whatsAppId={!whatsAppModalOpen && selectedWhatsApp?.id} whatsAppId={!whatsAppModalOpen && selectedWhatsApp?.id}
/> />
<WhatsAppModal <WhatsAppModal
open={whatsAppModalOpen} open={whatsAppModalOpen}
onClose={handleCloseWhatsAppModal} onClose={handleCloseWhatsAppModal}
whatsAppId={!qrModalOpen && selectedWhatsApp?.id} whatsAppId={!qrModalOpen && selectedWhatsApp?.id}
/> />
<MainHeader> <MainHeader>
<Title>{i18n.t("connections.title")}</Title> <Title>{i18n.t("connections.title")}</Title>
<MainHeaderButtonsWrapper> <MainHeaderButtonsWrapper>
<Can
role={user.profile}
perform="btn-add-whatsapp"
yes={() => (
<Button
variant="contained"
color="primary"
onClick={handleOpenWhatsAppModal}>
{i18n.t("connections.buttons.add")}
</Button>
)}
/>
</MainHeaderButtonsWrapper>
</MainHeader>
<Paper className={classes.mainPaper} variant="outlined">
<Table size="small">
<TableHead>
<TableRow>
<TableCell align="center">
{i18n.t("connections.table.name")}
</TableCell>
<TableCell align="center">
{i18n.t("connections.table.status")}
</TableCell>
<Can <Can
role={user.profile} role={user.profile}
perform="connection-button:show" perform="btn-add-whatsapp"
yes={() => ( yes={() => (
<TableCell align="center"> <Button
{i18n.t("connections.table.session")} variant="contained"
</TableCell> color="primary"
)} onClick={handleOpenWhatsAppModal}>
{i18n.t("connections.buttons.add")}
</Button>
)}
/> />
<TableCell align="center"> </MainHeaderButtonsWrapper>
{i18n.t("connections.table.lastUpdate")} </MainHeader>
</TableCell> <Paper className={classes.mainPaper} variant="outlined">
<TableCell align="center"> <Table size="small">
{i18n.t("connections.table.default")} <TableHead>
</TableCell> <TableRow>
<TableCell align="center"> <TableCell align="center">
{i18n.t("connections.table.actions")} {i18n.t("connections.table.name")}
</TableCell> </TableCell>
</TableRow> <TableCell align="center">
</TableHead> {i18n.t("connections.table.status")}
<TableBody> </TableCell>
{loading ? (
<TableRowSkeleton />
) : ( <Can
<> role={user.profile}
{whatsApps?.length > 0 && perform="connection-button:show"
whatsApps.map(whatsApp => ( yes={() => (
<TableRow key={whatsApp.id}>
<TableCell align="center">{whatsApp.name}</TableCell>
<TableCell align="center"> <TableCell align="center">
{renderStatusToolTips(whatsApp)} {i18n.t("connections.table.session")}
</TableCell> </TableCell>
)}
<Can />
role={user.profile}
perform="connection-button:show"
yes={() => (
<TableCell align="center">
{renderActionButtons(whatsApp)}
</TableCell>
)}
/>
<TableCell align="center"> <TableCell align="center">
{format(parseISO(whatsApp.updatedAt), "dd/MM/yy HH:mm")} {i18n.t("connections.table.lastUpdate")}
</TableCell> </TableCell>
<TableCell align="center"> <TableCell align="center">
{whatsApp.isDefault && ( {i18n.t("connections.table.default")}
<div className={classes.customTableCell}> </TableCell>
<CheckCircle style={{ color: green[500] }} /> <TableCell align="center">
</div> {i18n.t("connections.table.actions")}
)} </TableCell>
</TableCell> </TableRow>
<TableCell align="center"> </TableHead>
<IconButton <TableBody>
size="small" {loading ? (
onClick={() => handleEditWhatsApp(whatsApp)} <TableRowSkeleton />
> ) : (
<Edit /> <>
</IconButton> {whatsApps?.length > 0 &&
whatsApps.map(whatsApp => (
<TableRow key={whatsApp.id}>
<TableCell align="center">{whatsApp.name}</TableCell>
<TableCell align="center">
{renderStatusToolTips(whatsApp)}
</TableCell>
<Can
<Can
role={user.profile} role={user.profile}
perform="btn-remove-whatsapp" perform="connection-button:show"
yes={() => ( yes={() => (
<IconButton <TableCell align="center">
size="small" {renderActionButtons(whatsApp)}
onClick={e => { </TableCell>
handleOpenConfirmationModal("delete", whatsApp.id);
}}
>
<DeleteOutline />
</IconButton>
)} )}
/> />
</TableCell>
</TableRow>
))} <TableCell align="center">
</> {format(parseISO(whatsApp.updatedAt), "dd/MM/yy HH:mm")}
)} </TableCell>
</TableBody> <TableCell align="center">
</Table> {whatsApp.isDefault && (
</Paper> <div className={classes.customTableCell}>
</MainContainer> <CheckCircle style={{ color: green[500] }} />
)} </div>
/> )}
</TableCell>
<TableCell align="center">
<Can
role={user.profile}
perform="show-icon-edit-whatsapp"
yes={() => (
<IconButton
size="small"
onClick={() => handleEditWhatsApp(whatsApp)}
>
<Edit />
</IconButton>
)}
/>
<Can
role={user.profile}
perform="btn-remove-whatsapp"
yes={() => (
<IconButton
size="small"
onClick={e => {
handleOpenConfirmationModal("delete", whatsApp.id);
}}
>
<DeleteOutline />
</IconButton>
)}
/>
</TableCell>
</TableRow>
))}
</>
)}
</TableBody>
</Table>
</Paper>
</MainContainer>
)}
/>
); );
}; };

View File

@ -165,15 +165,14 @@ const Queues = () => {
return ( return (
<Can <Can
role={user.profile} role={user.profile}
perform="queues-view:show" perform="queues-view:show"
yes={() => ( yes={() => (
<MainContainer> <MainContainer>
<ConfirmationModal <ConfirmationModal
title={ title={
selectedQueue && selectedQueue &&
`${i18n.t("queues.confirmationModal.deleteTitle")} ${ `${i18n.t("queues.confirmationModal.deleteTitle")} ${selectedQueue.name
selectedQueue.name
}?` }?`
} }
open={confirmModalOpen} open={confirmModalOpen}
@ -189,15 +188,25 @@ const Queues = () => {
/> />
<MainHeader> <MainHeader>
<Title>{i18n.t("queues.title")}</Title> <Title>{i18n.t("queues.title")}</Title>
<MainHeaderButtonsWrapper>
<Button
variant="contained" <Can
color="primary" role={user.profile}
onClick={handleOpenQueueModal} perform="show-icon-add-queue"
> yes={() => (
{i18n.t("queues.buttons.add")} <MainHeaderButtonsWrapper>
</Button> <Button
</MainHeaderButtonsWrapper> variant="contained"
color="primary"
onClick={handleOpenQueueModal}
>
{i18n.t("queues.buttons.add")}
</Button>
</MainHeaderButtonsWrapper>
)}
/>
</MainHeader> </MainHeader>
<Paper className={classes.mainPaper} variant="outlined"> <Paper className={classes.mainPaper} variant="outlined">
<Table size="small"> <Table size="small">
@ -245,23 +254,42 @@ const Queues = () => {
</Typography> </Typography>
</div> </div>
</TableCell> </TableCell>
<TableCell align="center">
<IconButton
size="small"
onClick={() => handleEditQueue(queue)}
>
<Edit />
</IconButton>
<IconButton
size="small"
onClick={() => { <TableCell align="center">
setSelectedQueue(queue);
setConfirmModalOpen(true);
}} <Can
> role={user.profile}
<DeleteOutline /> perform="show-icon-edit-queue"
</IconButton> yes={() => (
<IconButton
size="small"
onClick={() => handleEditQueue(queue)}
>
<Edit />
</IconButton>
)}
/>
<Can
role={user.profile}
perform="show-icon-delete-queue"
yes={() => (
<IconButton
size="small"
onClick={() => {
setSelectedQueue(queue);
setConfirmModalOpen(true);
}}
>
<DeleteOutline />
</IconButton>
)}
/>
</TableCell> </TableCell>
</TableRow> </TableRow>
))} ))}
@ -271,8 +299,8 @@ const Queues = () => {
</Table> </Table>
</Paper> </Paper>
</MainContainer> </MainContainer>
)} )}
/> />
); );
}; };

View File

@ -5,6 +5,8 @@ const rules = {
admin: { admin: {
static: [ static: [
"show-icon-edit-whatsapp",
"drawer-admin-items:view", "drawer-admin-items:view",
"tickets-manager:showall", "tickets-manager:showall",
"user-modal:editProfile", "user-modal:editProfile",
@ -22,6 +24,13 @@ const rules = {
master: { master: {
static: [ static: [
"show-icon-edit-whatsapp",
"show-icon-add-queue",
"show-icon-edit-queue",
"show-icon-delete-queue",
"drawer-admin-items:view", "drawer-admin-items:view",
"tickets-manager:showall", "tickets-manager:showall",
"user-modal:editProfile", "user-modal:editProfile",