From 6f8b0e92b8d7e492e53d44aa8ba31e03776591fd Mon Sep 17 00:00:00 2001 From: Luis Felipe Risch <lfr20@inf.ufpr.br> Date: Fri, 14 May 2021 11:54:18 -0300 Subject: [PATCH] Fix admin bugs of permissions --- src/Admin/Pages/Pages/SubPages/Activity.js | 46 +-- .../Pages/Pages/SubPages/AproveTeacher.js | 27 +- .../Pages/Pages/SubPages/BlockedUsers.js | 1 + .../Pages/SubPages/CommunityQuestions.js | 27 +- src/Admin/Pages/Pages/SubPages/Complaints.js | 29 +- .../Pages/SubPages/EducationalObjects.js | 10 +- .../Pages/Pages/SubPages/Institutions.js | 5 +- src/Admin/Pages/Pages/SubPages/Languages.js | 2 +- .../Pages/Pages/SubPages/NoteVariables.js | 1 + src/Admin/Pages/Pages/SubPages/Permissions.js | 2 +- src/Admin/Pages/Pages/SubPages/Questions.js | 25 +- src/Admin/Pages/Pages/SubPages/Rating.js | 5 +- src/Admin/Pages/Pages/SubPages/SendEmail.js | 51 +-- src/Admin/Pages/Pages/SubPages/Users.js | 5 +- src/App.js | 291 +++++++++++++++--- 15 files changed, 317 insertions(+), 210 deletions(-) diff --git a/src/Admin/Pages/Pages/SubPages/Activity.js b/src/Admin/Pages/Pages/SubPages/Activity.js index bd43798c..6cb62ff1 100644 --- a/src/Admin/Pages/Pages/SubPages/Activity.js +++ b/src/Admin/Pages/Pages/SubPages/Activity.js @@ -16,33 +16,33 @@ GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with Plataforma Integrada MEC. If not, see <http://www.gnu.org/licenses/>.*/ -import React, { useEffect, useState } from "react"; -import moment from 'moment'; +import React, { useEffect, useState } from "react" +import moment from 'moment' //imports from local files -import TableData from "../../../Components/Components/Table"; -import SnackBar from "../../../../Components/SnackbarComponent"; -import { Url } from "../../../Filters"; -import { getRequest } from '../../../../Components/HelperFunctions/getAxiosConfig'; -import LoadingSpinner from '../../../../Components/LoadingSpinner'; +import TableData from "../../../Components/Components/Table" +import SnackBar from "../../../../Components/SnackbarComponent" +import { Url } from "../../../Filters" +import { getRequest } from '../../../../Components/HelperFunctions/getAxiosConfig' +import LoadingSpinner from '../../../../Components/LoadingSpinner' import MobilePageHeader from '../../../Components/Components/MobileComponents/MobilePageHeader' import PageHeader from '../../../Components/Components/PageHeader' //imports from material ui -import { withStyles } from "@material-ui/core/styles"; -import TableBody from "@material-ui/core/TableBody"; -import TableCell from "@material-ui/core/TableCell"; -import MenuItem from "@material-ui/core/MenuItem"; -import TableRow from "@material-ui/core/TableRow"; -import TextField from "@material-ui/core/TextField"; -import IconButton from "@material-ui/core/IconButton"; -import { Button, Paper } from "@material-ui/core"; -import CircularProgress from "@material-ui/core/CircularProgress"; -import AddRoundedIcon from "@material-ui/icons/AddRounded"; -import UpdateRoundedIcon from "@material-ui/icons/UpdateRounded"; -import FilterListRoundedIcon from "@material-ui/icons/FilterListRounded"; -import VisibilityIcon from "@material-ui/icons/Visibility"; -import AllOutIcon from "@material-ui/icons/AllOut"; +import { withStyles } from "@material-ui/core/styles" +import TableBody from "@material-ui/core/TableBody" +import TableCell from "@material-ui/core/TableCell" +import MenuItem from "@material-ui/core/MenuItem" +import TableRow from "@material-ui/core/TableRow" +import TextField from "@material-ui/core/TextField" +import IconButton from "@material-ui/core/IconButton" +import { Button, Paper } from "@material-ui/core" +import CircularProgress from "@material-ui/core/CircularProgress" +import AddRoundedIcon from "@material-ui/icons/AddRounded" +import UpdateRoundedIcon from "@material-ui/icons/UpdateRounded" +import FilterListRoundedIcon from "@material-ui/icons/FilterListRounded" +import VisibilityIcon from "@material-ui/icons/Visibility" +import AllOutIcon from "@material-ui/icons/AllOut" //routers -import { Link } from 'react-router-dom'; +import { Link } from 'react-router-dom' import MobileList from "../../../Components/Components/MobileComponents/SimpleList" import styled from "styled-components" @@ -422,6 +422,8 @@ const Activity = () => { } } }; + + export default Activity; const StyledDivButton = styled(Paper)` diff --git a/src/Admin/Pages/Pages/SubPages/AproveTeacher.js b/src/Admin/Pages/Pages/SubPages/AproveTeacher.js index b6cbc697..c6078dba 100644 --- a/src/Admin/Pages/Pages/SubPages/AproveTeacher.js +++ b/src/Admin/Pages/Pages/SubPages/AproveTeacher.js @@ -16,20 +16,18 @@ GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with Plataforma Integrada MEC. If not, see <http://www.gnu.org/licenses/>.*/ -import React, { useEffect, useState, useContext } from "react"; +import React, { useEffect, useState } from "react"; import moment from "moment"; import styled from "styled-components"; //imports from local files import TableData from "../../../Components/Components/Table"; import SnackBar from "../../../../Components/SnackbarComponent"; import { Url } from "../../../Filters"; -import { Store } from "../../../../Store"; import LoadingSpinner from "../../../../Components/LoadingSpinner"; import { getRequest, postRequest, } from "../../../../Components/HelperFunctions/getAxiosConfig"; -import Unauthorized from "../../../Components/Components/Unauthorized"; import MobileList from "../../../Components/Components/MobileComponents/SimpleList"; import MobilePageHeader from "../../../Components/Components/MobileComponents/MobilePageHeader"; import PageHeader from "../../../Components/Components/PageHeader"; @@ -75,9 +73,7 @@ const StyledTableRow = withStyles((theme) => ({ }))(TableRow); const AproveTeacher = () => { - const { state } = useContext(Store); - const WINDOW_WIDTH = window.innerWidth; - + const WINDOW_WIDTH = window.innerWidth const ADD_ONE_LENGHT = [""]; const TOP_LABELS = [ "ESTADO DO PEDIDO", @@ -126,21 +122,6 @@ const AproveTeacher = () => { }); }; - const CheckUserPermission = () => { - let canUserEdit = false; - - if (state.userIsLoggedIn) { - const roles = [...state.currentUser.roles]; - for (let i = 0; i < roles.length; i++) - if (roles[i].name === "admin" || roles[i].name === "editor") - canUserEdit = true; - } else { - canUserEdit = false; - } - - return canUserEdit; - }; - const handleChange = (e, type) => { const value = e.target.value; setOption(value); @@ -359,7 +340,7 @@ const AproveTeacher = () => { return <div>Error: {error.message}</div>; } else if (!isLoaded) { return <LoadingSpinner text="Carregando..." />; - } else if (CheckUserPermission()) { + } else { if (WINDOW_WIDTH <= 1130) { return ( <> @@ -760,7 +741,7 @@ const AproveTeacher = () => { </> ); } - } else return <Unauthorized />; + } }; export default AproveTeacher; diff --git a/src/Admin/Pages/Pages/SubPages/BlockedUsers.js b/src/Admin/Pages/Pages/SubPages/BlockedUsers.js index 0e2dc4da..ac2f09de 100644 --- a/src/Admin/Pages/Pages/SubPages/BlockedUsers.js +++ b/src/Admin/Pages/Pages/SubPages/BlockedUsers.js @@ -70,6 +70,7 @@ const StyledTableRow = withStyles((theme) => ({ const BlockedUsers = () => { const ADD_ONE_LENGHT = ['']; const WINDOW_WIDTH = window.innerWidth + const [error, setError] = useState(null); //Necessary to consult the API, catch errors const [isLoaded, setIsLoaded] = useState(false); //Necessary to consult the API, wait until complete const [items, setItems] = useState([]); //Necessary to consult the API, data diff --git a/src/Admin/Pages/Pages/SubPages/CommunityQuestions.js b/src/Admin/Pages/Pages/SubPages/CommunityQuestions.js index c3a78462..52bc6b89 100644 --- a/src/Admin/Pages/Pages/SubPages/CommunityQuestions.js +++ b/src/Admin/Pages/Pages/SubPages/CommunityQuestions.js @@ -16,14 +16,12 @@ GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with Plataforma Integrada MEC. If not, see <http://www.gnu.org/licenses/>.*/ -import React, { useEffect, useState, useContext } from "react"; +import React, { useEffect, useState } from "react"; import moment from 'moment'; //imports from local files import TableData from "../../../Components/Components/Table"; import SnackBar from "../../../../Components/SnackbarComponent"; -import Unauthorized from '../../../Components/Components/Unauthorized'; import { Url } from "../../../Filters"; -import { Store } from '../../../../Store'; import LoadingSpinner from '../../../../Components/LoadingSpinner'; import { getRequest } from '../../../../Components/HelperFunctions/getAxiosConfig'; import MobilePageHeader from "../../../Components/Components/MobileComponents/MobilePageHeader" @@ -67,7 +65,6 @@ const StyledTableRow = withStyles((theme) => ({ }))(TableRow); const CommunityQuestion = () => { - const { state } = useContext(Store); const ADD_ONE_LENGHT = [""]; const TOP_LABELS = [ @@ -80,7 +77,6 @@ const CommunityQuestion = () => { ]; //Labels from Table const WINDOW_WIDTH = window.innerWidth - const [error, setError] = useState(null); //Necessary to consult the API, catch errors const [isLoaded, setIsLoaded] = useState(false); //Necessary to consult the API, wait until complete const [items, setItems] = useState([]); //Necessary to consult the API, data @@ -136,22 +132,6 @@ const CommunityQuestion = () => { .toString(); }; - const CheckUserPermission = () => { - let canUserEdit = false; - - if (state.userIsLoggedIn) { - const roles = [...state.currentUser.roles]; - for (let i = 0; i < roles.length; i++) - if (roles[i].name === 'admin' || roles[i].name === 'editor') - canUserEdit = true; - } - else { - canUserEdit = false; - } - - return canUserEdit; - } - const buildUrl = (message, email, name) => { if (message && email && name) return Url("contacts", `"message" : "${message}", "email" : "${email}", "name" : "${name}"`, currPage, "DESC") @@ -221,7 +201,7 @@ const CommunityQuestion = () => { return <div>Error: {error.message}</div>; } else if (!isLoaded) { return <LoadingSpinner text="Carregando..." /> - } else if (CheckUserPermission()) { + } else { if (WINDOW_WIDTH <= 1200) { return ( <> @@ -525,8 +505,7 @@ const CommunityQuestion = () => { </TableData> </> } - - } else return <Unauthorized /> + } } export default CommunityQuestion; diff --git a/src/Admin/Pages/Pages/SubPages/Complaints.js b/src/Admin/Pages/Pages/SubPages/Complaints.js index 0b1cc0a0..d2fb9de2 100644 --- a/src/Admin/Pages/Pages/SubPages/Complaints.js +++ b/src/Admin/Pages/Pages/SubPages/Complaints.js @@ -16,19 +16,17 @@ GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with Plataforma Integrada MEC. If not, see <http://www.gnu.org/licenses/>.*/ -import React, { useEffect, useState, useContext } from "react"; +import React, { useEffect, useState } from "react"; import moment from "moment"; //imports from local files import TableData from "../../../Components/Components/Table"; import SnackBar from "../../../../Components/SnackbarComponent"; import { Url } from "../../../Filters"; -import { Store } from '../../../../Store'; import LoadingSpinner from '../../../../Components/LoadingSpinner'; import { getRequest } from '../../../../Components/HelperFunctions/getAxiosConfig' import MobileList from "../../../Components/Components/MobileComponents/SimpleList" import MobilePageHeader from "../../../Components/Components/MobileComponents/MobilePageHeader" import PageHeader from "../../../Components/Components/PageHeader" -import Unauthorized from "../../../Components/Components/Unauthorized"; //imports from material ui import { withStyles } from "@material-ui/core/styles"; import TableBody from "@material-ui/core/TableBody"; @@ -68,12 +66,9 @@ const StyledTableRow = withStyles((theme) => ({ }))(TableRow); const Complaints = () => { - const { state } = useContext(Store); const WINDOW_WIDTH = window.innerWidth - - const PORTAL_MEC = "https://plataformaintegrada.mec.gov.br/"; - const ADD_ONE_LENGHT = [""]; + const PORTAL_MEC = "https://plataformaintegrada.mec.gov.br/"; const TOP_LABELS = [ "ESTADO DO RECURSO", "ID", @@ -129,22 +124,6 @@ const Complaints = () => { }); }; - const CheckUserPermission = () => { - let canUserEdit = false; - - if (state.userIsLoggedIn) { - const roles = [...state.currentUser.roles]; - for (let i = 0; i < roles.length; i++) - if (roles[i].name === 'admin' || roles[i].name === 'editor') - canUserEdit = true; - } - else { - canUserEdit = false; - } - - return canUserEdit; - } - const handleChangeState = (e, type) => { const value = e.target.value; setStateOption(value); @@ -295,7 +274,7 @@ const Complaints = () => { return <div>Error: {error.message}</div>; } else if (!isLoaded) { return <LoadingSpinner text="Carregando..." /> - } else if (CheckUserPermission()) { + } else { if (WINDOW_WIDTH <= 994) { return ( <> @@ -643,7 +622,7 @@ const Complaints = () => { </> ); } - } else return <Unauthorized /> + } }; export default Complaints; diff --git a/src/Admin/Pages/Pages/SubPages/EducationalObjects.js b/src/Admin/Pages/Pages/SubPages/EducationalObjects.js index a5df3138..837797d4 100644 --- a/src/Admin/Pages/Pages/SubPages/EducationalObjects.js +++ b/src/Admin/Pages/Pages/SubPages/EducationalObjects.js @@ -18,7 +18,7 @@ along with Plataforma Integrada MEC. If not, see <http://www.gnu.org/licenses/> import React, { useState, useEffect } from "react"; import moment from 'moment'; -// Imports from local files +// Imports from local file import TableData from "../../../Components/Components/Table"; import SnackBar from "../../../../Components/SnackbarComponent"; import AlertDialog from "../../../Components/Components/AlertDialog"; @@ -72,7 +72,6 @@ const StyledTableRow = withStyles((theme) => ({ const EducationalObjects = () => { const WINDOW_WIDTH = window.innerWidth - const ADD_ONE_LENGHT = [""]; const [error, setError] = useState(null); //Necessary to consult the API, catch errors @@ -253,11 +252,11 @@ const EducationalObjects = () => { if (error) { return <div>Error: {error.message}</div>; } - if (!isLoaded) { + else if (!isLoaded) { return <LoadingSpinner text="Carregando..." /> } else { //Words that defines that column - const topTable = [ + const TOP_TABLE = [ "CRIADO EM", "NOME", "DESCRIÇÃO", @@ -291,6 +290,7 @@ const EducationalObjects = () => { helperText: "Ao terminar de digitar no campo, retire o foco do campo de texto" }, ]; + if (WINDOW_WIDTH <= 1058) { return ( <div> @@ -507,7 +507,7 @@ const EducationalObjects = () => { <div style={{ height: "2em" }}></div> {/************** Start of display data in table **************/} - <TableData top={topTable}> + <TableData top={TOP_TABLE}> <TableBody> {items.map((row, index) => index === items.length - 1 ? ( diff --git a/src/Admin/Pages/Pages/SubPages/Institutions.js b/src/Admin/Pages/Pages/SubPages/Institutions.js index cf77c1e4..24d099a6 100644 --- a/src/Admin/Pages/Pages/SubPages/Institutions.js +++ b/src/Admin/Pages/Pages/SubPages/Institutions.js @@ -71,9 +71,10 @@ const StyledTableRow = withStyles((theme) => ({ const Institutions = () => { const WINDOW_WIDTH = window.innerWidth - const router = useHistory() const ADD_ONE_LENGHT = [""]; + const router = useHistory() + const [error, setError] = useState(null); //Necessary to consult the API, catch errors const [isLoaded, setIsLoaded] = useState(false); //Necessary to consult the API, wait until complete const [items, setItems] = useState([]); //Necessary to consult the API, data @@ -237,7 +238,7 @@ const Institutions = () => { if (error) { return <div>Error: {error.message}</div>; } - if (!isLoaded) { + else if (!isLoaded) { return <LoadingSpinner text="Carregando..." /> } else { //Words that defines that column diff --git a/src/Admin/Pages/Pages/SubPages/Languages.js b/src/Admin/Pages/Pages/SubPages/Languages.js index deb622b6..3d11c4a4 100644 --- a/src/Admin/Pages/Pages/SubPages/Languages.js +++ b/src/Admin/Pages/Pages/SubPages/Languages.js @@ -157,6 +157,7 @@ const Languages = () => { setIsLoaded(false) else setIsLoadingMoreItems(true) + getRequest( Url("languages", "", currPage, "DESC"), (data, header) => { @@ -186,7 +187,6 @@ const Languages = () => { ) }, [currPage]) - if (error) { return <div>Error: {error.message}</div>; } else if (!isLoaded) { diff --git a/src/Admin/Pages/Pages/SubPages/NoteVariables.js b/src/Admin/Pages/Pages/SubPages/NoteVariables.js index e3b15ae4..5e58e14d 100644 --- a/src/Admin/Pages/Pages/SubPages/NoteVariables.js +++ b/src/Admin/Pages/Pages/SubPages/NoteVariables.js @@ -67,6 +67,7 @@ const StyledTableRow = withStyles((theme) => ({ const NoteVariables = () => { const WINDOW_WIDTH = window.innerWidth const ADD_ONE_LENGHT = [""]; + const [error, setError] = useState(null); //Necessary to consult the API, catch errors const [isLoaded, setIsLoaded] = useState(false); //Necessary to consult the API, wait until complete const [currPage, setCurrPage] = useState(0) diff --git a/src/Admin/Pages/Pages/SubPages/Permissions.js b/src/Admin/Pages/Pages/SubPages/Permissions.js index c4aba3f8..89c3bb55 100644 --- a/src/Admin/Pages/Pages/SubPages/Permissions.js +++ b/src/Admin/Pages/Pages/SubPages/Permissions.js @@ -66,6 +66,7 @@ const UserPermissions = () => { const ADD_ONE_LENGHT = [""]; const TOP_LABELS = ['ID', 'NOME', 'DESCRIÇÃO', 'AÇÕES'] //Labels from Table const WINDOW_WIDTH = window.innerWidth + const router = useHistory() const [error, setError] = useState(null); //Necessary to consult the API, catch errors @@ -183,7 +184,6 @@ const UserPermissions = () => { ) }, [currPage]) - if (error) { return <div>Error: {error.message}</div>; } else if (!isLoaded) { diff --git a/src/Admin/Pages/Pages/SubPages/Questions.js b/src/Admin/Pages/Pages/SubPages/Questions.js index 58b80d4b..aa4532af 100644 --- a/src/Admin/Pages/Pages/SubPages/Questions.js +++ b/src/Admin/Pages/Pages/SubPages/Questions.js @@ -16,14 +16,12 @@ GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with Plataforma Integrada MEC. If not, see <http://www.gnu.org/licenses/>.*/ -import React, { useEffect, useState, useContext } from 'react' +import React, { useEffect, useState } from 'react' import moment from 'moment'; //imports from local files import TableData from '../../../Components/Components/Table'; import SnackBar from '../../../../Components/SnackbarComponent'; -import Unauthorized from '../../../Components/Components/Unauthorized'; import { Url, EditFilter } from '../../../Filters'; -import { Store } from '../../../../Store'; import LoadingSpinner from '../../../../Components/LoadingSpinner'; import { getRequest, putRequest } from '../../../../Components/HelperFunctions/getAxiosConfig' import MobileList from "../../../Components/Components/MobileComponents/SimpleList" @@ -63,7 +61,6 @@ const StyledTableRow = withStyles((theme) => ({ }))(TableRow); const Questions = () => { - const { state } = useContext(Store); const ADD_ONE_LENGHT = [""]; const WINDOW_WIDTH = window.innerWidth @@ -93,22 +90,6 @@ const Questions = () => { }) } - const CheckUserPermission = () => { - let canUserEdit = false; - - if (state.userIsLoggedIn) { - const roles = [...state.currentUser.roles]; - for (let i = 0; i < roles.length; i++) - if (roles[i].name === 'admin') - canUserEdit = true; - } - else { - canUserEdit = false; - } - - return canUserEdit; - } - const changeStateItem = (index, currState) => { const copyItems = [...items] copyItems[index].status = currState @@ -213,7 +194,7 @@ const Questions = () => { return <div>Error: {error.message}</div>; } else if (!isLoaded) { return <LoadingSpinner text="Carregando..." /> - } else if (CheckUserPermission()) { + } else { if (WINDOW_WIDTH <= 800) { return ( <> @@ -424,7 +405,7 @@ const Questions = () => { </> ); } - } else return <Unauthorized /> + } } export default Questions; diff --git a/src/Admin/Pages/Pages/SubPages/Rating.js b/src/Admin/Pages/Pages/SubPages/Rating.js index b6ecfe7e..8f00fd9d 100644 --- a/src/Admin/Pages/Pages/SubPages/Rating.js +++ b/src/Admin/Pages/Pages/SubPages/Rating.js @@ -30,7 +30,7 @@ import CircularProgress from '@material-ui/core/CircularProgress'; import AddRoundedIcon from '@material-ui/icons/AddRounded'; import UpdateRoundedIcon from '@material-ui/icons/UpdateRounded'; import DeleteRoundedIcon from '@material-ui/icons/DeleteRounded'; -//Local files +//Local files' import TableData from '../../../Components/Components/Table'; import SnackBar from '../../../../Components/SnackbarComponent'; import LoadingSpinner from '../../../../Components/LoadingSpinner'; @@ -68,6 +68,7 @@ const StyledTableRow = withStyles((theme) => ({ const Ratings = () => { const WINDOW_WIDTH = window.innerWidth const ADD_ONE_LENGHT = [""]; + const router = useHistory() const [error, setError] = useState(null); //Necessary to consult the API, catch errors @@ -150,7 +151,6 @@ const Ratings = () => { setOpenAlertDialog(!openAlertDialog); }; - useEffect(() => { if (currPage === 0) setIsLoaded(false) @@ -185,7 +185,6 @@ const Ratings = () => { ) }, [currPage]) - if (error) { return <div>Error: {error.message}</div>; } else if (!isLoaded) { diff --git a/src/Admin/Pages/Pages/SubPages/SendEmail.js b/src/Admin/Pages/Pages/SubPages/SendEmail.js index 5e9b05ed..c6e8c4d0 100644 --- a/src/Admin/Pages/Pages/SubPages/SendEmail.js +++ b/src/Admin/Pages/Pages/SubPages/SendEmail.js @@ -18,14 +18,12 @@ You should have received a copy of the GNU Affero General Public License along with Plataforma Integrada MEC. If not, see <http://www.gnu.org/licenses/>.*/ -import React, {useContext} from 'react'; +import React from 'react'; import Card from "@material-ui/core/Card"; import CardContent from "@material-ui/core/CardContent"; import { makeStyles } from "@material-ui/core/styles"; import { Typography } from '@material-ui/core'; import EmailInputs from '../../../Components/Components/Inputs/EmailInputs'; -import { Store } from '../../../../Store'; -import Unauthorized from '../../../Components/Components/Unauthorized'; const useStyles = makeStyles({ root: { @@ -57,41 +55,22 @@ const useStyles = makeStyles({ }); const SendEmail = ({ match }) => { - const { state } = useContext(Store); const classes = useStyles(); - const CheckUserPermission = () => { - let canUserEdit = false; - - if (state.userIsLoggedIn) { - const roles = [...state.currentUser.roles]; - for (let i = 0; i < roles.length; i++) - if (roles[i].name === 'admin' || roles[i].name === 'editor') - canUserEdit = true; - } - else { - canUserEdit = false; - } - - return canUserEdit; - } - - if(CheckUserPermission()){ - return ( - <Card> - <CardContent> - <Typography - className={classes.title} - color="inherit" - gutterBottom - > - Enviar email - </Typography> - <EmailInputs email={`${match.params.email}`} /> - </CardContent> - </Card> - ); - } else return <Unauthorized/> + return ( + <Card> + <CardContent> + <Typography + className={classes.title} + color="inherit" + gutterBottom + > + Enviar email + </Typography> + <EmailInputs email={`${match.params.email}`} /> + </CardContent> + </Card> + ); } export default SendEmail; \ No newline at end of file diff --git a/src/Admin/Pages/Pages/SubPages/Users.js b/src/Admin/Pages/Pages/SubPages/Users.js index 49f091d3..31857677 100644 --- a/src/Admin/Pages/Pages/SubPages/Users.js +++ b/src/Admin/Pages/Pages/SubPages/Users.js @@ -69,8 +69,10 @@ const StyledTableRow = withStyles((theme) => ({ const Users = () => { const ADD_ONE_LENGHT = ['']; - const router = useHistory() const WINDOW_WIDTH = window.innerWidth + + const router = useHistory() + const [error, setError] = useState(null); //Necessary to consult the API, catch errors const [isLoaded, setIsLoaded] = useState(false); //Necessary to consult the API, wait until complete const [items, setItems] = useState([]); //Necessary to consult the API, data @@ -224,7 +226,6 @@ const Users = () => { setEmail("") }, [showFilter]) - if (error) { return <div>Error: {error.message}</div>; } else if (!isLoaded) { diff --git a/src/App.js b/src/App.js index 7c06612f..d687e65a 100644 --- a/src/App.js +++ b/src/App.js @@ -17,6 +17,8 @@ You should have received a copy of the GNU Affero General Public License along with Plataforma Integrada MEC. If not, see <http://www.gnu.org/licenses/>.*/ import React, { useContext, useEffect, useState } from "react"; +import { Store } from './Store' +import Unauthorized from './Admin/Components/Components/Unauthorized' import Home from "./Pages/HomeFunction"; import Search from "./Pages/Search"; import Header from "./Components/Header"; @@ -36,7 +38,6 @@ import PasswordRecoveryPage from "./Pages/PasswordRecoveryPage.js"; import PageProfessor from "./Pages/PageProfessor.js"; import ResourcePage from "./Pages/ResourcePage"; import { BrowserRouter, Switch, Route } from "react-router-dom"; -import { Store } from "./Store"; import TermsPage from "./Pages/TermsPage.js"; import PublicationPermissionsPage from "./Pages/PublicationPermissionsPage.js"; import TabPlataformaMEC from "./Pages/TabsHelp/TabPlataformaMEC"; @@ -95,9 +96,25 @@ import AppBarAdmin from './Admin/Components/Components/AppBar' export default function App() { // eslint-disable-next-line - const { dispatch } = useContext(Store); + const { state, dispatch } = useContext(Store); const [hideFooter, setHideFooter] = useState(false); + const CheckUserPermission = () => { + let canUserEdit = false; + + if (state.userIsLoggedIn) { + const roles = [...state.currentUser.roles]; + for (let i = 0; i < roles.length; i++) + if (roles[i].name === 'admin' || roles[i].name === 'editor') + canUserEdit = true; + } + else { + canUserEdit = false; + } + + return canUserEdit; + } + useEffect(() => { setHideFooter(String(window.location.href).includes("iframe-colecao")); }, [window.location.href]); @@ -180,71 +197,257 @@ export default function App() { <div style={{ backgroundColor: " #D3D3D3" }}> <AppBarAdmin /> <div style={{ padding: "2em" }}> - <Route path="/admin/home" exact={true} component={Inframe} /> - <Route path="/admin/intitutions" component={Institution} /> - <Route path="/admin/institution/:id" component={InstitutionCard} /> + <Route path="/admin/home" exact={true} render={() => { + if (CheckUserPermission()) + return <Inframe /> + else + return <Unauthorized /> + }} /> + <Route path="/admin/intitutions" render={() => { + if (CheckUserPermission()) + return <Institution /> + else + return <Unauthorized /> + }} /> + <Route path="/admin/institution/:id" render={() => { + if (CheckUserPermission()) + return <InstitutionCard /> + else + return <Unauthorized /> + }} /> <Route path="/admin/institutionEdit/:id" - component={InstitutionsInput} + render={() => { + if (CheckUserPermission()) + return <InstitutionsInput /> + else + return <Unauthorized /> + }} /> <Route path="/admin/InstitutionCreate" - component={CreateInstitution} + render={() => { + if (CheckUserPermission()) + return <CreateInstitution /> + else + return <Unauthorized /> + }} /> - <Route path="/admin/noteVars" component={NoteVariables} /> - <Route path="/admin/noteVar/:id" component={NoteVarCard} /> - <Route path="/admin/noteVarEdit/:id" component={NoteVarInputs} /> - <Route path="/admin/languages" component={Languages} /> - <Route path="/admin/languageEdit/:id" component={EditLanguage} /> - <Route path="/admin/languageCreate" component={CreateLanguage} /> + <Route path="/admin/noteVars" render={() => { + if (CheckUserPermission()) + return <NoteVariables /> + else + return <Unauthorized /> + }} /> + <Route path="/admin/noteVar/:id" render={() => { + if (CheckUserPermission()) + return <NoteVarCard /> + else + return <Unauthorized /> + }} /> + <Route path="/admin/noteVarEdit/:id" render={() => { + if (CheckUserPermission()) + return <NoteVarInputs /> + else + return <Unauthorized /> + }} /> + <Route path="/admin/languages" render={() => { + if (CheckUserPermission()) + return <Languages /> + else + return <Unauthorized /> + }} /> + <Route path="/admin/languageEdit/:id" render={() => { + if (CheckUserPermission()) + return <EditLanguage /> + else + return <Unauthorized /> + }} /> + <Route path="/admin/languageCreate" render={() => { + if (CheckUserPermission()) + return <CreateLanguage /> + else + return <Unauthorized /> + }} /> <Route path="/admin/CommunityQuestions" - component={CommunityQuestions} + render={() => { + if (CheckUserPermission()) + return <CommunityQuestions /> + else + return <Unauthorized /> + }} /> <Route path="/admin/CommunityQuestion/:id" - component={CommunityCard} + render={() => { + if (CheckUserPermission()) + return <CommunityCard /> + else + return <Unauthorized /> + }} /> - <Route path="/admin/Collections" component={Collections} /> - <Route path="/admin/Collection/:id" component={CollectionCard} /> + <Route path="/admin/Collections" render={() => { + if (CheckUserPermission()) + return <Collections /> + else + return <Unauthorized /> + }} /> + <Route path="/admin/Collection/:id" render={() => { + if (CheckUserPermission()) + return <CollectionCard /> + else + return <Unauthorized /> + }} /> <Route path="/admin/EditCollection/:id" - component={EditCollection} + render={() => { + if (CheckUserPermission()) + return <EditCollection /> + else + return <Unauthorized /> + }} /> - <Route path="/admin/Ratings" component={Ratings} /> - <Route path="/admin/Rating/:id" component={RatingCard} /> - <Route path="/admin/EditRating/:id" component={EditRating} /> - <Route path="/admin/CreateRating" component={CreateRating} /> - <Route path="/admin/Questions" component={Questions} /> - <Route path="/admin/CreateQuestion" component={CreateQuestions} /> - <Route path="/admin/activities" component={Activity} /> - <Route path="/admin/activity/:id" component={ActivityCard} /> + <Route path="/admin/Ratings" render={() => { + if (CheckUserPermission()) + return <Ratings /> + else + return <Unauthorized /> + }} /> + <Route path="/admin/Rating/:id" render={() => { + if (CheckUserPermission()) + return <RatingCard /> + else + return <Unauthorized /> + }} /> + <Route path="/admin/EditRating/:id" render={() => { + if (CheckUserPermission()) + return <EditRating /> + else + return <Unauthorized /> + }} /> + <Route path="/admin/CreateRating" render={() => { + if (CheckUserPermission()) + return <CreateRating /> + else + return <Unauthorized /> + }} /> + <Route path="/admin/Questions" render={() => { + if (CheckUserPermission()) + return <Questions /> + else + return <Unauthorized /> + }} /> + <Route path="/admin/CreateQuestion" render={() => { + if (CheckUserPermission()) + return <CreateQuestions /> + else + return <Unauthorized /> + }} /> + <Route path="/admin/activities" render={() => { + if (CheckUserPermission()) + return <Activity /> + else + return <Unauthorized /> + }} /> + <Route path="/admin/activity/:id" render={() => { + if (CheckUserPermission()) + return <ActivityCard /> + else + return <Unauthorized /> + }} /> <Route path="/admin/learningObjects" - component={EducationalObject} - /> + render={() => { + if (CheckUserPermission()) + return <EducationalObject /> + else + return <Unauthorized /> + }} /> <Route path="/admin/learningObject/:id" - component={EducationalObjectCard} - /> + render={() => { + if (CheckUserPermission()) + return <EducationalObjectCard /> + else + return <Unauthorized /> + }} /> <Route path="/admin/learningObjectEdit/:id" - component={EducationalObjectEdit} - /> - <Route path="/admin/complaints" component={Complaints} /> - <Route path="/admin/complaint/:id" component={ComplaintCard} /> + render={() => { + if (CheckUserPermission()) + return <EducationalObjectEdit /> + else + return <Unauthorized /> + }} /> + <Route path="/admin/complaints" render={() => { + if (CheckUserPermission()) + return <Complaints /> + else + return <Unauthorized /> + }} /> + <Route path="/admin/complaint/:id" render={() => { + if (CheckUserPermission()) + return <ComplaintCard /> + else + return <Unauthorized /> + }} /> <Route path="/admin/users/teacher_requests" - component={AproveTeacher} - /> - <Route path="/admin/usersList" component={UserList} /> - <Route path="/admin/user/:id" component={UserCard} /> - <Route path="/admin/EditUser/:id" component={EditUser} /> - <Route path="/admin/permissions" component={UserPermissions} /> - <Route path="/admin/EditPermissions/:id" component={EditRole} /> - <Route path="/admin/CreateRole" component={CreateRole} /> - <Route path="/admin/BlockedUsers" component={BlockedUser} /> - <Route path="/admin/sendEmail/:email" component={SendEmail} /> + render={() => { + if (CheckUserPermission()) + return <AproveTeacher /> + else + return <Unauthorized /> + }} /> + <Route path="/admin/usersList" render={() => { + if (CheckUserPermission()) + return <UserList /> + else + return <Unauthorized /> + }} /> + <Route path="/admin/user/:id" render={() => { + if (CheckUserPermission()) + return <UserCard /> + else + return <Unauthorized /> + }} /> + <Route path="/admin/EditUser/:id" render={() => { + if (CheckUserPermission()) + return <EditUser /> + else + return <Unauthorized /> + }} /> + <Route path="/admin/permissions" render={() => { + if (CheckUserPermission()) + return <UserPermissions /> + else + return <Unauthorized /> + }} /> + <Route path="/admin/EditPermissions/:id" render={() => { + if (CheckUserPermission()) + return <EditRole /> + else + return <Unauthorized /> + }} /> + <Route path="/admin/CreateRole" render={() => { + if (CheckUserPermission()) + return <CreateRole /> + else + return <Unauthorized /> + }} /> + <Route path="/admin/BlockedUsers" render={() => { + if (CheckUserPermission()) + return <BlockedUser /> + else + return <Unauthorized /> + }} /> + <Route path="/admin/sendEmail/:email" ender={() => { + if (CheckUserPermission()) + return <SendEmail /> + else + return <Unauthorized /> + }} /> </div> </div> </Switch> -- GitLab