Criação de nova rule para que somente o administrador acesse as configurações(settings)
							parent
							
								
									723f094e5e
								
							
						
					
					
						commit
						78074b0d09
					
				| 
						 | 
					@ -1,4 +1,4 @@
 | 
				
			||||||
import React, { useState, useEffect, useReducer } from "react";
 | 
					import React, { useState, useEffect, useReducer, useContext} from "react";
 | 
				
			||||||
import { toast } from "react-toastify";
 | 
					import { toast } from "react-toastify";
 | 
				
			||||||
import openSocket from "socket.io-client";
 | 
					import openSocket from "socket.io-client";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -30,6 +30,10 @@ import UserModal from "../../components/UserModal";
 | 
				
			||||||
import ConfirmationModal from "../../components/ConfirmationModal";
 | 
					import ConfirmationModal from "../../components/ConfirmationModal";
 | 
				
			||||||
import toastError from "../../errors/toastError";
 | 
					import toastError from "../../errors/toastError";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					//--------
 | 
				
			||||||
 | 
					import { AuthContext } from "../../context/Auth/AuthContext";
 | 
				
			||||||
 | 
					import { Can } from "../../components/Can";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const reducer = (state, action) => {
 | 
					const reducer = (state, action) => {
 | 
				
			||||||
  if (action.type === "LOAD_USERS") {
 | 
					  if (action.type === "LOAD_USERS") {
 | 
				
			||||||
    const users = action.payload;
 | 
					    const users = action.payload;
 | 
				
			||||||
| 
						 | 
					@ -85,6 +89,9 @@ const useStyles = makeStyles((theme) => ({
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const Users = () => {
 | 
					const Users = () => {
 | 
				
			||||||
  const classes = useStyles();
 | 
					  const classes = useStyles();
 | 
				
			||||||
 | 
					  
 | 
				
			||||||
 | 
					  //--------
 | 
				
			||||||
 | 
						const { user: userA } = useContext(AuthContext); 
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  const [loading, setLoading] = useState(false);
 | 
					  const [loading, setLoading] = useState(false);
 | 
				
			||||||
  const [pageNumber, setPageNumber] = useState(1);
 | 
					  const [pageNumber, setPageNumber] = useState(1);
 | 
				
			||||||
| 
						 | 
					@ -183,112 +190,121 @@ const Users = () => {
 | 
				
			||||||
  };
 | 
					  };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  return (
 | 
					  return (
 | 
				
			||||||
    <MainContainer>
 | 
					 | 
				
			||||||
      <ConfirmationModal
 | 
					 | 
				
			||||||
        title={
 | 
					 | 
				
			||||||
          deletingUser &&
 | 
					 | 
				
			||||||
          `${i18n.t("users.confirmationModal.deleteTitle")} ${
 | 
					 | 
				
			||||||
            deletingUser.name
 | 
					 | 
				
			||||||
          }?`
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        open={confirmModalOpen}
 | 
					 | 
				
			||||||
        onClose={setConfirmModalOpen}
 | 
					 | 
				
			||||||
        onConfirm={() => handleDeleteUser(deletingUser.id)}
 | 
					 | 
				
			||||||
      >
 | 
					 | 
				
			||||||
        {i18n.t("users.confirmationModal.deleteMessage")}
 | 
					 | 
				
			||||||
      </ConfirmationModal>
 | 
					 | 
				
			||||||
      <UserModal
 | 
					 | 
				
			||||||
        open={userModalOpen}
 | 
					 | 
				
			||||||
        onClose={handleCloseUserModal}
 | 
					 | 
				
			||||||
        aria-labelledby="form-dialog-title"
 | 
					 | 
				
			||||||
        userId={selectedUser && selectedUser.id}
 | 
					 | 
				
			||||||
      />
 | 
					 | 
				
			||||||
      <MainHeader>
 | 
					 | 
				
			||||||
        <Title>{i18n.t("users.title")}</Title>
 | 
					 | 
				
			||||||
        <MainHeaderButtonsWrapper>
 | 
					 | 
				
			||||||
          <TextField
 | 
					 | 
				
			||||||
            placeholder={i18n.t("contacts.searchPlaceholder")}
 | 
					 | 
				
			||||||
            type="search"
 | 
					 | 
				
			||||||
            value={searchParam}
 | 
					 | 
				
			||||||
            onChange={handleSearch}
 | 
					 | 
				
			||||||
            InputProps={{
 | 
					 | 
				
			||||||
              startAdornment: (
 | 
					 | 
				
			||||||
                <InputAdornment position="start">
 | 
					 | 
				
			||||||
                  <SearchIcon style={{ color: "gray" }} />
 | 
					 | 
				
			||||||
                </InputAdornment>
 | 
					 | 
				
			||||||
              ),
 | 
					 | 
				
			||||||
            }}
 | 
					 | 
				
			||||||
          />
 | 
					 | 
				
			||||||
          
 | 
					 | 
				
			||||||
           <Button
 | 
					 | 
				
			||||||
            variant="contained"
 | 
					 | 
				
			||||||
            color="primary"
 | 
					 | 
				
			||||||
            onClick={handleOpenUserModal}
 | 
					 | 
				
			||||||
          >
 | 
					 | 
				
			||||||
            {i18n.t("users.buttons.add")}
 | 
					 | 
				
			||||||
          </Button> 
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
        </MainHeaderButtonsWrapper>
 | 
					    <Can
 | 
				
			||||||
      </MainHeader>
 | 
							  role={userA.profile}
 | 
				
			||||||
      <Paper
 | 
							  perform="user-view:show"
 | 
				
			||||||
        className={classes.mainPaper}
 | 
							  yes={() => (
 | 
				
			||||||
        variant="outlined"
 | 
					        <MainContainer>
 | 
				
			||||||
        onScroll={handleScroll}
 | 
					        <ConfirmationModal
 | 
				
			||||||
      >
 | 
					          title={
 | 
				
			||||||
        <Table size="small">
 | 
					            deletingUser &&
 | 
				
			||||||
          <TableHead>
 | 
					            `${i18n.t("users.confirmationModal.deleteTitle")} ${
 | 
				
			||||||
            <TableRow>
 | 
					              deletingUser.name
 | 
				
			||||||
              <TableCell align="center">{i18n.t("users.table.name")}</TableCell>
 | 
					            }?`
 | 
				
			||||||
              <TableCell align="center">
 | 
					          }
 | 
				
			||||||
                {i18n.t("users.table.email")}
 | 
					          open={confirmModalOpen}
 | 
				
			||||||
              </TableCell>
 | 
					          onClose={setConfirmModalOpen}
 | 
				
			||||||
              <TableCell align="center">
 | 
					          onConfirm={() => handleDeleteUser(deletingUser.id)}
 | 
				
			||||||
                {i18n.t("users.table.profile")}
 | 
					        >
 | 
				
			||||||
              </TableCell>
 | 
					          {i18n.t("users.confirmationModal.deleteMessage")}
 | 
				
			||||||
              
 | 
					        </ConfirmationModal>
 | 
				
			||||||
              <TableCell align="center">
 | 
					        <UserModal
 | 
				
			||||||
                {i18n.t("users.table.actions")}
 | 
					          open={userModalOpen}
 | 
				
			||||||
              </TableCell>
 | 
					          onClose={handleCloseUserModal}
 | 
				
			||||||
 | 
					          aria-labelledby="form-dialog-title"
 | 
				
			||||||
            </TableRow>
 | 
					          userId={selectedUser && selectedUser.id}
 | 
				
			||||||
          </TableHead>
 | 
					        />
 | 
				
			||||||
          <TableBody>
 | 
					        <MainHeader>
 | 
				
			||||||
            <>
 | 
					          <Title>{i18n.t("users.title")}</Title>
 | 
				
			||||||
              {users.map((user) => (
 | 
					          <MainHeaderButtonsWrapper>
 | 
				
			||||||
                <TableRow key={user.id}>
 | 
					            <TextField
 | 
				
			||||||
                  <TableCell align="center">{user.name}</TableCell>
 | 
					              placeholder={i18n.t("contacts.searchPlaceholder")}
 | 
				
			||||||
                  <TableCell align="center">{user.email}</TableCell>
 | 
					              type="search"
 | 
				
			||||||
                  <TableCell align="center">{user.profile}</TableCell>
 | 
					              value={searchParam}
 | 
				
			||||||
                  
 | 
					              onChange={handleSearch}
 | 
				
			||||||
                  <TableCell align="center">
 | 
					              InputProps={{
 | 
				
			||||||
 | 
					                startAdornment: (
 | 
				
			||||||
 | 
					                  <InputAdornment position="start">
 | 
				
			||||||
 | 
					                    <SearchIcon style={{ color: "gray" }} />
 | 
				
			||||||
 | 
					                  </InputAdornment>
 | 
				
			||||||
 | 
					                ),
 | 
				
			||||||
 | 
					              }}
 | 
				
			||||||
 | 
					            />
 | 
				
			||||||
 | 
					            
 | 
				
			||||||
 | 
					             <Button
 | 
				
			||||||
 | 
					              variant="contained"
 | 
				
			||||||
 | 
					              color="primary"
 | 
				
			||||||
 | 
					              onClick={handleOpenUserModal}
 | 
				
			||||||
 | 
					            >
 | 
				
			||||||
 | 
					              {i18n.t("users.buttons.add")}
 | 
				
			||||||
 | 
					            </Button> 
 | 
				
			||||||
 | 
					  
 | 
				
			||||||
 | 
					          </MainHeaderButtonsWrapper>
 | 
				
			||||||
 | 
					        </MainHeader>
 | 
				
			||||||
 | 
					        <Paper
 | 
				
			||||||
 | 
					          className={classes.mainPaper}
 | 
				
			||||||
 | 
					          variant="outlined"
 | 
				
			||||||
 | 
					          onScroll={handleScroll}
 | 
				
			||||||
 | 
					        >
 | 
				
			||||||
 | 
					          <Table size="small">
 | 
				
			||||||
 | 
					            <TableHead>
 | 
				
			||||||
 | 
					              <TableRow>
 | 
				
			||||||
 | 
					                <TableCell align="center">{i18n.t("users.table.name")}</TableCell>
 | 
				
			||||||
 | 
					                <TableCell align="center">
 | 
				
			||||||
 | 
					                  {i18n.t("users.table.email")}
 | 
				
			||||||
 | 
					                </TableCell>
 | 
				
			||||||
 | 
					                <TableCell align="center">
 | 
				
			||||||
 | 
					                  {i18n.t("users.table.profile")}
 | 
				
			||||||
 | 
					                </TableCell>
 | 
				
			||||||
 | 
					                
 | 
				
			||||||
 | 
					                <TableCell align="center">
 | 
				
			||||||
 | 
					                  {i18n.t("users.table.actions")}
 | 
				
			||||||
 | 
					                </TableCell>
 | 
				
			||||||
 | 
					  
 | 
				
			||||||
 | 
					              </TableRow>
 | 
				
			||||||
 | 
					            </TableHead>
 | 
				
			||||||
 | 
					            <TableBody>
 | 
				
			||||||
 | 
					              <>
 | 
				
			||||||
 | 
					                {users.map((user) => (
 | 
				
			||||||
 | 
					                  <TableRow key={user.id}>
 | 
				
			||||||
 | 
					                    <TableCell align="center">{user.name}</TableCell>
 | 
				
			||||||
 | 
					                    <TableCell align="center">{user.email}</TableCell>
 | 
				
			||||||
 | 
					                    <TableCell align="center">{user.profile}</TableCell>
 | 
				
			||||||
                    
 | 
					                    
 | 
				
			||||||
                    <IconButton
 | 
					                    <TableCell align="center">
 | 
				
			||||||
                      size="small"
 | 
					                      
 | 
				
			||||||
                      onClick={() => handleEditUser(user)}
 | 
					                      <IconButton
 | 
				
			||||||
                    >
 | 
					                        size="small"
 | 
				
			||||||
                      <EditIcon />
 | 
					                        onClick={() => handleEditUser(user)}
 | 
				
			||||||
                    </IconButton>
 | 
					                      >
 | 
				
			||||||
 | 
					                        <EditIcon />
 | 
				
			||||||
 | 
					                      </IconButton>
 | 
				
			||||||
 | 
					  
 | 
				
			||||||
 | 
					                       <IconButton
 | 
				
			||||||
 | 
					                        size="small"
 | 
				
			||||||
 | 
					                        onClick={(e) => {
 | 
				
			||||||
 | 
					                          setConfirmModalOpen(true);
 | 
				
			||||||
 | 
					                          setDeletingUser(user);
 | 
				
			||||||
 | 
					                        }}
 | 
				
			||||||
 | 
					                      >
 | 
				
			||||||
 | 
					                        <DeleteOutlineIcon />
 | 
				
			||||||
 | 
					                      </IconButton> 
 | 
				
			||||||
 | 
					  
 | 
				
			||||||
 | 
					                    </TableCell>
 | 
				
			||||||
 | 
					  
 | 
				
			||||||
 | 
					                  </TableRow>
 | 
				
			||||||
 | 
					                ))}
 | 
				
			||||||
 | 
					                {loading && <TableRowSkeleton columns={4} />}
 | 
				
			||||||
 | 
					              </>
 | 
				
			||||||
 | 
					            </TableBody>
 | 
				
			||||||
 | 
					          </Table>
 | 
				
			||||||
 | 
					        </Paper>
 | 
				
			||||||
 | 
					      </MainContainer>
 | 
				
			||||||
 | 
							  )}
 | 
				
			||||||
 | 
							/>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                     <IconButton
 | 
					    
 | 
				
			||||||
                      size="small"
 | 
					 | 
				
			||||||
                      onClick={(e) => {
 | 
					 | 
				
			||||||
                        setConfirmModalOpen(true);
 | 
					 | 
				
			||||||
                        setDeletingUser(user);
 | 
					 | 
				
			||||||
                      }}
 | 
					 | 
				
			||||||
                    >
 | 
					 | 
				
			||||||
                      <DeleteOutlineIcon />
 | 
					 | 
				
			||||||
                    </IconButton> 
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                  </TableCell>
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                </TableRow>
 | 
					 | 
				
			||||||
              ))}
 | 
					 | 
				
			||||||
              {loading && <TableRowSkeleton columns={4} />}
 | 
					 | 
				
			||||||
            </>
 | 
					 | 
				
			||||||
          </TableBody>
 | 
					 | 
				
			||||||
        </Table>
 | 
					 | 
				
			||||||
      </Paper>
 | 
					 | 
				
			||||||
    </MainContainer>
 | 
					 | 
				
			||||||
  );
 | 
					  );
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -15,6 +15,7 @@ const rules = {
 | 
				
			||||||
			"connections-view:show",
 | 
								"connections-view:show",
 | 
				
			||||||
			"dashboard-view:show",
 | 
								"dashboard-view:show",
 | 
				
			||||||
			"queues-view:show",
 | 
								"queues-view:show",
 | 
				
			||||||
 | 
								"user-view:show",
 | 
				
			||||||
		],
 | 
							],
 | 
				
			||||||
	},
 | 
						},
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue