Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Front fix permissions selection #16

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions src/Components/SideBar/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import { RiLogoutCircleRLine } from "react-icons/ri";
import { useNavigate } from "react-router-dom";
import AuthContext, { useAuth } from "../../Context/auth";
import { usePermissions, checkModule } from "../../Utils/permission";

Check failure on line 13 in src/Components/SideBar/index.jsx

View workflow job for this annotation

GitHub Actions / lint

'checkModule' is defined but never used

Check failure on line 13 in src/Components/SideBar/index.jsx

View workflow job for this annotation

GitHub Actions / lint

'checkModule' is defined but never used
import { getRoleById } from "../../Services/RoleService/roleService";

export default function SideBar() {
Expand All @@ -19,10 +19,10 @@
const navigate = useNavigate();
const context = useContext(AuthContext);
const { user } = useAuth();
const permissions = usePermissions();

Check failure on line 22 in src/Components/SideBar/index.jsx

View workflow job for this annotation

GitHub Actions / lint

'permissions' is assigned a value but never used

Check failure on line 22 in src/Components/SideBar/index.jsx

View workflow job for this annotation

GitHub Actions / lint

'permissions' is assigned a value but never used
const [role, setRole] = useState("");

useEffect(() => {}, [navigate]);
useEffect(() => { }, [navigate]);

const handleItemClick = async (user) => {
if (user) {
Expand Down Expand Up @@ -54,7 +54,7 @@
}}
/>,
<SideButton
hidden={checkModule(permissions, "users") ? "flex" : "none"}
// hidden={checkModule(permissions, "users") ? "flex" : "none"}
key="filiacao"
text="CADASTROS"
onClick={() => {
Expand All @@ -63,7 +63,7 @@
}}
/>,
<SideButton
hidden={checkModule(permissions, "finance") ? "flex" : "none"}
// hidden={checkModule(permissions, "finance") ? "flex" : "none"}
key="financeiro"
text="FINANCEIRO"
onClick={() => {
Expand All @@ -72,14 +72,23 @@
}}
/>,
<SideButton
hidden={checkModule(permissions, "benefits") ? "flex" : "none"}
// hidden={checkModule(permissions, "benefits") ? "flex" : "none"}
key="beneficios"
text="BENEFÍCIOS"
onClick={() => {
navigate("/beneficios");
setIsSideBarOpen(false);
}}
/>,
<SideButton
// hidden={checkModule(permissions, "benefits") ? "flex" : "none"}
key="permissions"
text="PERMISSIONS"
onClick={() => {
navigate("/permissions");
setIsSideBarOpen(false);
}}
/>,
<SideButton
hidden={user ? "none" : "flex"}
key="login"
Expand All @@ -98,7 +107,7 @@
}}
/>,
<SideButton
hidden={checkModule(permissions, "users") ? "flex" : "none"}
// hidden={checkModule(permissions, "users") ? "flex" : "none"}
key="carteirinha"
text="CARTEIRINHA"
onClick={() => {
Expand All @@ -116,7 +125,7 @@
}}
/>,
<SideButton
hidden={checkModule(permissions, "users") ? "flex" : "none"}
// hidden={checkModule(permissions, "users") ? "flex" : "none"}
key="Verificarsindicalizado"
text="VERIFICAR SINDICALIZADO"
onClick={() => {
Expand Down
2 changes: 1 addition & 1 deletion src/Pages/Protected/Benefit/Benefits/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const Benefits = () => {
const navigate = useNavigate();
const { user } = useAuth();
const permissions = usePermissions();
const canCreate = checkAction(permissions, "benefits", "create");
const canCreate = checkAction(permissions, "create");

const handleBenefitsList = () => {
navigate("/beneficios/lista");
Expand Down
2 changes: 1 addition & 1 deletion src/Pages/Protected/Benefit/BenefitsList/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export default function BenefitsList() {
const [benefits, setBenefits] = useState([]);
const navigate = useNavigate();
const permissions = usePermissions();
const canCreate = checkAction(permissions, "benefits", "create");
const canCreate = checkAction(permissions, "create");

const handleSubmit = () => {
navigate("/beneficios/criar");
Expand Down
4 changes: 2 additions & 2 deletions src/Pages/Protected/Benefit/BenefitsUpdate/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ export default function BenefitsUpdate() {
const [showDeletedModal, setShowDeletedModal] = useState(false);
const [openError, setOpenError] = useState(false);
const permissions = usePermissions();
const canUpdate = checkAction(permissions, "benefits", "update");
const canDelete = checkAction(permissions, "benefits", "delete");
const canUpdate = checkAction(permissions,"update");
const canDelete = checkAction(permissions, "delete");

const tipoPessoaList = ["Jurídica", "Física"];
const categoriaList = [
Expand Down
2 changes: 1 addition & 1 deletion src/Pages/Protected/Finance/BankAccountList/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export default function ListBankAccount() {
const { user } = useAuth();
const [bankAccounts, setBankAccounts] = useState([]);
const permissions = usePermissions();
const canCreate = checkAction(permissions, "finance", "create");
const canCreate = checkAction(permissions, "create");

useEffect(() => {
const fetchBankAccounts = async () => {
Expand Down
4 changes: 2 additions & 2 deletions src/Pages/Protected/Finance/BankAccountUpdate/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ const BankAccountId = () => {
const [agency, setAgency] = useState("");
const [openError, setOpenError] = useState(false);
const permissions = usePermissions();
const canUpdate = checkAction(permissions, "finance", "update");
const canDelete = checkAction(permissions, "finance", "delete");
const canUpdate = checkAction(permissions, "update");
const canDelete = checkAction(permissions, "delete");

const { user } = useAuth();
const { id } = useParams(); // Pega o ID da URL
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
const [dataInicio, setDataInicio] = useState(null);
const [dataFinal, setDataFinal] = useState(null);
const permissions = usePermissions();
const canCreate = checkAction(permissions, "finance", "create");
const canCreate = checkAction(permissions, "create");

const storagedUser = JSON.parse(localStorage.getItem("@App:user"));

Expand All @@ -44,7 +44,7 @@
};

fetchMovements();
}, []);

Check warning on line 47 in src/Pages/Protected/FinancialMovements/FinancialList/index.jsx

View workflow job for this annotation

GitHub Actions / lint

React Hook useEffect has a missing dependency: 'storagedUser.token'. Either include it or remove the dependency array

Check warning on line 47 in src/Pages/Protected/FinancialMovements/FinancialList/index.jsx

View workflow job for this annotation

GitHub Actions / lint

React Hook useEffect has a missing dependency: 'storagedUser.token'. Either include it or remove the dependency array

const handleSubmit = () => {
navigate("/movimentacoes/criar");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ export default function FinancialUpdate() {
const [nomesDestino, setNomesDestino] = useState([]);
const maxDescricaoLength = 130;
const permissions = usePermissions();
const canUpdate = checkAction(permissions, "finance", "update");
const canDelete = checkAction(permissions, "finance", "delete");
const canUpdate = checkAction(permissions, "update");
const canDelete = checkAction(permissions, "delete");

const navigate = useNavigate();
const location = useLocation();
Expand Down
2 changes: 1 addition & 1 deletion src/Pages/Protected/Organ/ListOrgan/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export default function OrganList() {
const [organs, setOrgans] = useState([]);
const navigate = useNavigate();

const canCreate = checkAction(permissions, "users", "create");
const canCreate = checkAction(permissions,"create");
useEffect(() => {
const getOrgansInfo = async () => {
const response = await listOrgans();
Expand Down
4 changes: 2 additions & 2 deletions src/Pages/Protected/Organ/OrganUpdate/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ export const OrganId = () => {
const organsId = state?.organsId;
const navigate = useNavigate();
const permissions = usePermissions();
const canUpdate = checkAction(permissions, "users", "update");
const canDelete = checkAction(permissions, "users", "delete");
const canUpdate = checkAction(permissions, "update");
const canDelete = checkAction(permissions, "delete");

const [openSave, setOpenSave] = useState(false);
const [openDeleteOrgan, setOpenDeleteOrgan] = useState(false);
Expand Down
126 changes: 126 additions & 0 deletions src/Pages/Protected/Permissions/permissionsHandler.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
import React, { useState, useEffect } from 'react';

Check failure on line 1 in src/Pages/Protected/Permissions/permissionsHandler.jsx

View workflow job for this annotation

GitHub Actions / lint

'React' is defined but never used

Check failure on line 1 in src/Pages/Protected/Permissions/permissionsHandler.jsx

View workflow job for this annotation

GitHub Actions / lint

'React' is defined but never used
import axios from 'axios';

Check failure on line 2 in src/Pages/Protected/Permissions/permissionsHandler.jsx

View workflow job for this annotation

GitHub Actions / lint

'axios' is defined but never used

Check failure on line 2 in src/Pages/Protected/Permissions/permissionsHandler.jsx

View workflow job for this annotation

GitHub Actions / lint

'axios' is defined but never used
import { Box, Button, TextField, Typography, Table, TableBody, TableCell, TableContainer, TableHead, TableRow, Paper, IconButton } from '@mui/material';
import { Delete, Edit, Search } from '@mui/icons-material';

Check failure on line 4 in src/Pages/Protected/Permissions/permissionsHandler.jsx

View workflow job for this annotation

GitHub Actions / lint

'Search' is defined but never used

Check failure on line 4 in src/Pages/Protected/Permissions/permissionsHandler.jsx

View workflow job for this annotation

GitHub Actions / lint

'Search' is defined but never used
import { APIUsers } from "./../../../Services/BaseService/index";
import { getToken, getUser } from "./../../../Services/Functions/loader";

Check failure on line 6 in src/Pages/Protected/Permissions/permissionsHandler.jsx

View workflow job for this annotation

GitHub Actions / lint

'getUser' is defined but never used

Check failure on line 6 in src/Pages/Protected/Permissions/permissionsHandler.jsx

View workflow job for this annotation

GitHub Actions / lint

'getUser' is defined but never used


const PermissionCRUD = () => {
const [permissions, setPermissions] = useState([]);
const [form, setForm] = useState({ name: '' });
const [searchQuery, setSearchQuery] = useState('');

Check failure on line 12 in src/Pages/Protected/Permissions/permissionsHandler.jsx

View workflow job for this annotation

GitHub Actions / lint

'setSearchQuery' is assigned a value but never used

Check failure on line 12 in src/Pages/Protected/Permissions/permissionsHandler.jsx

View workflow job for this annotation

GitHub Actions / lint

'setSearchQuery' is assigned a value but never used
const [search, setSearch] = useState("");

Check failure on line 13 in src/Pages/Protected/Permissions/permissionsHandler.jsx

View workflow job for this annotation

GitHub Actions / lint

'setSearch' is assigned a value but never used

Check failure on line 13 in src/Pages/Protected/Permissions/permissionsHandler.jsx

View workflow job for this annotation

GitHub Actions / lint

'setSearch' is assigned a value but never used
const [editId, setEditId] = useState(null);

useEffect(() => {
fetchPermissions();
}, []);

const fetchPermissions = async () => {
try {
const response = await APIUsers.get('permission');
setPermissions(response.data);
} catch (error) {
console.error('Error fetching permissions:', error);
}
};

const handleSubmit = async (e) => {
e.preventDefault();
try {
if (editId) {
await APIUsers.patch(`permission/patch/${editId}`, form);
} else {
await APIUsers.post('permission/create/', form);
}
setForm({ name: '' });
setEditId(null);
fetchPermissions();
} catch (error) {
console.error('Error saving permission:', error);
}
};

const handleEdit = (permission) => {
setForm({ name: permission.name });
setEditId(permission._id);
};

const handleDelete = async (id) => {
try {
await APIUsers.delete(`permission/delete/${id}`);
fetchPermissions();
} catch (error) {
console.error('Error deleting permission:', error);
}
};

const handleSearch = async () => {

Check failure on line 59 in src/Pages/Protected/Permissions/permissionsHandler.jsx

View workflow job for this annotation

GitHub Actions / lint

'handleSearch' is assigned a value but never used

Check failure on line 59 in src/Pages/Protected/Permissions/permissionsHandler.jsx

View workflow job for this annotation

GitHub Actions / lint

'handleSearch' is assigned a value but never used
try {
const response = await APIUsers.get(`permissions/search`,
{ name: searchQuery },
{headers: {
Authorization: `Bearer ${getToken()}`,
}}
);
setPermissions(response.data);
} catch (error) {
console.error('Error searching permissions:', error);
}
};

const filteredPermissions = permissions.filter((permission) =>
permission.name.toLowerCase().includes(search.toLowerCase())
);

return (
<Box sx={{ padding: 4 }}>
<Typography variant="h4" gutterBottom>
Permission Management
</Typography>

<Box component="form" onSubmit={handleSubmit} sx={{ marginBottom: 4 }}>
<TextField
label="Permission Name"
value={form.name}
onChange={(e) => setForm({ ...form, name: e.target.value })}
required
fullWidth
margin="normal"
/>
<Button sx={{ backgroundColor: '#ae883c', '&:hover': { backgroundColor: '#936d30' }}} type="submit" variant="contained" color="primary">
{editId ? 'Atualizar Permissão' : 'Criar Permissão'}
</Button>
</Box>

<TableContainer component={Paper}>
<Table sx={{ backgroundColor: '#eae3d7', '&:hover': { backgroundColor: '#eae3d7' }}}>
<TableHead>
<TableRow>
<TableCell>Name</TableCell>
<TableCell>Actions</TableCell>
</TableRow>
</TableHead>
<TableBody>
{filteredPermissions.map((permission, index) => (

Check failure on line 106 in src/Pages/Protected/Permissions/permissionsHandler.jsx

View workflow job for this annotation

GitHub Actions / lint

'index' is defined but never used

Check failure on line 106 in src/Pages/Protected/Permissions/permissionsHandler.jsx

View workflow job for this annotation

GitHub Actions / lint

'index' is defined but never used
<TableRow key={permission._id}>
<TableCell>{permission.name}</TableCell>
<TableCell>
<IconButton color="primary" onClick={() => handleEdit(permission)}>
<Edit />
</IconButton>
<IconButton color="error" onClick={() => handleDelete(permission._id)}>
<Delete />
</IconButton>
</TableCell>
</TableRow>
))}
</TableBody>
</Table>
</TableContainer>
</Box>
);
};

export default PermissionCRUD;
2 changes: 1 addition & 1 deletion src/Pages/Protected/Roles/RolesListPage/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export default function RolesListPage() {
fetchRoleForm();
}, []);

const hasPermission = checkAction(permissions, "users", "create");
const hasPermission = checkAction(permissions, "create");

const handleSubmit = () => {
navigate("/perfis/criar");
Expand Down
4 changes: 2 additions & 2 deletions src/Pages/Protected/Roles/RolesUpdatePage/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ export default function RolesUpdatePage() {
const location = useLocation();
const { roleId } = location.state;

const canDelete = checkAction(permissions, "users", "delete");
const canUpdate = checkAction(permissions, "users", "update");
const canDelete = checkAction(permissions, "delete");
const canUpdate = checkAction(permissions, "update");

useEffect(() => {
const fetchRole = async () => {
Expand Down
2 changes: 1 addition & 1 deletion src/Pages/Protected/Supplier/ListSupplier/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export default function ListSupplier() {
const [search, setSearch] = useState("");
const navigate = useNavigate();
const permissions = usePermissions();
const canCreate = checkAction(permissions, "finance", "create");
const canCreate = checkAction(permissions, "create");
useEffect(() => {
const fetchSupplierForm = async () => {
const response = await getSupplierForm();
Expand Down
4 changes: 2 additions & 2 deletions src/Pages/Protected/Supplier/UpdateSupplier/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ import { checkAction, usePermissions } from "../../../../Utils/permission";

export default function UpdateSupplier() {
const permissions = usePermissions();
const canUpdate = checkAction(permissions, "finance", "update");
const canDelete = checkAction(permissions, "finance", "delete");
const canUpdate = checkAction(permissions, "update");
const canDelete = checkAction(permissions, "delete");
const [nome, setNome] = useState("");
const [tipoPessoa, setTipoPessoa] = useState("");
const [cpfCnpj, setCpfCnpj] = useState("");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
vi.mock("../../../../Utils/permission", () => {
return {
...vi.importActual("../../../../Utils/permission"), // Importa o módulo real
checkAction: vi.fn((permissions, module, action) => {
checkAction: vi.fn((permissions, action) => {
if (
module === "finance" &&
(action === "update" || action === "delete")
Expand Down Expand Up @@ -111,7 +111,7 @@
target: { value: "invalid-email" },
});

await userEvent.click(screen.getByText("Salvar"));

Check failure on line 114 in src/Pages/Protected/Supplier/UpdateSupplier/index.test.jsx

View workflow job for this annotation

GitHub Actions / test

src/Pages/Protected/Supplier/UpdateSupplier/index.test.jsx > SupplierUpdate > validates form correctly before submitting

TestingLibraryElementError: Unable to find an element with the text: Salvar. This could be because the text is broken up by multiple elements. In this case, you can provide a function for your text matcher to make your matcher more flexible. Ignored nodes: comments, script, style <body> <div> <section class="container-benefits" > <div class="forms-container-supplier" > <h1> Visualização de fornecedor </h1> <h3> Dados pessoais </h3> <div class="MuiFormControl-root MuiTextField-root css-ami1jz-MuiFormControl-root-MuiTextField-root" > <label class="MuiFormLabel-root MuiInputLabel-root MuiInputLabel-formControl MuiInputLabel-animated MuiInputLabel-sizeMedium MuiInputLabel-filled MuiFormLabel-colorPrimary Mui-disabled MuiInputLabel-root MuiInputLabel-formControl MuiInputLabel-animated MuiInputLabel-sizeMedium MuiInputLabel-filled css-e4w4as-MuiFormLabel-root-MuiInputLabel-root" data-shrink="false" for="field-nome/razão-social" id="field-nome/razão-social-label" > Nome/Razão social </label> <div class="MuiInputBase-root MuiFilledInput-root MuiFilledInput-underline MuiInputBase-colorPrimary Mui-disabled MuiInputBase-formControl css-batk84-MuiInputBase-root-MuiFilledInput-root" > <input aria-invalid="false" class="MuiInputBase-input MuiFilledInput-input Mui-disabled css-10botns-MuiInputBase-input-MuiFilledInput-input" disabled="" id="field-nome/razão-social" type="text" value="" /> </div> </div> <div class="db-supplier" > <div class="MuiFormControl-root css-2vnt94-MuiFormControl-root" > <label class="MuiFormLabel-root MuiInputLabel-root MuiInputLabel-formControl MuiInputLabel-animated MuiInputLabel-sizeMedium MuiInputLabel-filled MuiFormLabel-colorPrimary MuiInputLabel-root MuiInputLabel-formControl MuiInputLabel-animated MuiInputLabel-sizeMedium MuiInputLabel-filled css-e4w4as-MuiFormLabel-root-MuiInputLabel-root" data-shrink="false" id="label-Classificação de pessoa" > Classificação de pessoa </label> <div class="MuiInputBase-root MuiFilledInput-root MuiFilledInput-underline MuiInputBase-colorPrimary MuiInputBase-formControl css-mck6no-MuiInputBase-root-MuiFilledInput-root-MuiSelect-root" > <div aria-controls=":rk:" aria-expanded="false" aria-haspopup="listbox" aria-labelledby="label-Classificação de pessoa select-Classificação de pessoa" class="MuiSelect-select MuiSelect-filled MuiInputBase-input MuiFilledInput-input css-d9oaum-MuiSelect-select-MuiInputBase-input-MuiFilledInput-input" id="select-Classificação de pessoa" role="combobox" tabindex="0" > <span class="notranslate" > ​ </span> </div> <input aria-hidden="true" aria-invalid="false" class="MuiSelect-nativeInput css-yf8vq0-MuiSelect-nativeInput" tabindex="-1" value="" /> <svg aria-hidden="true" class="MuiSvgIcon-root MuiSvgIcon-fontSizeMedium MuiSelect-icon MuiSelect-iconFilled css-hfutr2-MuiSvgIcon-root-MuiSelect-icon" data-testid="ArrowDropDownIcon" focusable="false" viewBox="0 0 24 24" > <path d="M7 10l5 5 5-5z" /> </svg> </div> </div> <div class="MuiFormCon

expect(updateSupplierFormById).not.toHaveBeenCalled();

Expand Down Expand Up @@ -176,7 +176,7 @@
</Router>
);

await userEvent.click(screen.getByText("Deletar"));

Check failure on line 179 in src/Pages/Protected/Supplier/UpdateSupplier/index.test.jsx

View workflow job for this annotation

GitHub Actions / test

src/Pages/Protected/Supplier/UpdateSupplier/index.test.jsx > SupplierUpdate > deletes supplier correctly

TestingLibraryElementError: Unable to find an element with the text: Deletar. This could be because the text is broken up by multiple elements. In this case, you can provide a function for your text matcher to make your matcher more flexible. Ignored nodes: comments, script, style <body> <div> <section class="container-benefits" > <div class="forms-container-supplier" > <h1> Visualização de fornecedor </h1> <h3> Dados pessoais </h3> <div class="MuiFormControl-root MuiTextField-root css-ami1jz-MuiFormControl-root-MuiTextField-root" > <label class="MuiFormLabel-root MuiInputLabel-root MuiInputLabel-formControl MuiInputLabel-animated MuiInputLabel-sizeMedium MuiInputLabel-filled MuiFormLabel-colorPrimary Mui-disabled MuiInputLabel-root MuiInputLabel-formControl MuiInputLabel-animated MuiInputLabel-sizeMedium MuiInputLabel-filled css-e4w4as-MuiFormLabel-root-MuiInputLabel-root" data-shrink="false" for="field-nome/razão-social" id="field-nome/razão-social-label" > Nome/Razão social </label> <div class="MuiInputBase-root MuiFilledInput-root MuiFilledInput-underline MuiInputBase-colorPrimary Mui-disabled MuiInputBase-formControl css-batk84-MuiInputBase-root-MuiFilledInput-root" > <input aria-invalid="false" class="MuiInputBase-input MuiFilledInput-input Mui-disabled css-10botns-MuiInputBase-input-MuiFilledInput-input" disabled="" id="field-nome/razão-social" type="text" value="" /> </div> </div> <div class="db-supplier" > <div class="MuiFormControl-root css-2vnt94-MuiFormControl-root" > <label class="MuiFormLabel-root MuiInputLabel-root MuiInputLabel-formControl MuiInputLabel-animated MuiInputLabel-sizeMedium MuiInputLabel-filled MuiFormLabel-colorPrimary MuiInputLabel-root MuiInputLabel-formControl MuiInputLabel-animated MuiInputLabel-sizeMedium MuiInputLabel-filled css-e4w4as-MuiFormLabel-root-MuiInputLabel-root" data-shrink="false" id="label-Classificação de pessoa" > Classificação de pessoa </label> <div class="MuiInputBase-root MuiFilledInput-root MuiFilledInput-underline MuiInputBase-colorPrimary MuiInputBase-formControl css-mck6no-MuiInputBase-root-MuiFilledInput-root-MuiSelect-root" > <div aria-controls=":r17:" aria-expanded="false" aria-haspopup="listbox" aria-labelledby="label-Classificação de pessoa select-Classificação de pessoa" class="MuiSelect-select MuiSelect-filled MuiInputBase-input MuiFilledInput-input css-d9oaum-MuiSelect-select-MuiInputBase-input-MuiFilledInput-input" id="select-Classificação de pessoa" role="combobox" tabindex="0" > <span class="notranslate" > ​ </span> </div> <input aria-hidden="true" aria-invalid="false" class="MuiSelect-nativeInput css-yf8vq0-MuiSelect-nativeInput" tabindex="-1" value="" /> <svg aria-hidden="true" class="MuiSvgIcon-root MuiSvgIcon-fontSizeMedium MuiSelect-icon MuiSelect-iconFilled css-hfutr2-MuiSvgIcon-root-MuiSelect-icon" data-testid="ArrowDropDownIcon" focusable="false" viewBox="0 0 24 24" > <path d="M7 10l5 5 5-5z" /> </svg> </div> </div> <div class="MuiFormC

expect(
screen.getByText("Deseja deletar o fornecedor do sistema?")
Expand Down
2 changes: 1 addition & 1 deletion src/Pages/Protected/Users/userHubPage/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { usePermissions, checkAction } from "../../../../Utils/permission";
export default function UserHubPage() {
const navigate = useNavigate();
const permissions = usePermissions();
const canAprove = checkAction(permissions, "users", "create");
const canAprove = checkAction(permissions, "create");

const handleListaClick = () => {
navigate("/usuarios");
Expand Down
2 changes: 1 addition & 1 deletion src/Pages/Protected/Users/userListPage/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export default function UserListPage() {
return <div>Carregando...</div>;
}

const hasPermission = checkAction(permissions, "users", "create");
const hasPermission = checkAction(permissions, "create");

const handleRegisterClick = () => {
navigate("/usuarios/criar");
Expand Down
4 changes: 2 additions & 2 deletions src/Pages/Protected/Users/userUpdatePage/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ export default function UserUpdatePage() {
const [isEmailValid, setIsEmailValid] = useState(true);
const [isCelularValid, setIsCelularValid] = useState(true);

const canDelete = checkAction(permissions, "users", "delete");
const canUpdate = checkAction(permissions, "users", "update");
const canDelete = checkAction(permissions, "delete");
const canUpdate = checkAction(permissions, "update");

useEffect(() => {
const loadRoles = async () => {
Expand Down
5 changes: 3 additions & 2 deletions src/Routes/permissionProtect.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,11 @@ const PermissionProtect = ({ element, moduleName, actions }) => {
// Exibe um carregando enquanto as permissões estão sendo buscadas
return <div>Loading...</div>;
}

console.log(moduleName, 'chaama')
return element;
// Verifica se o usuário possui pelo menos uma das ações necessárias
const hasPermission = actions.some((action) =>
checkAction(userPermissions, moduleName, action)
checkAction(userPermissions, action)
);

if (hasPermission) {
Expand Down
Loading
Loading