Skip to content

Commit e1a63bb

Browse files
committed
exposed fields to public
1 parent 0642b3b commit e1a63bb

File tree

9 files changed

+92
-23
lines changed

9 files changed

+92
-23
lines changed

backend/app/views.py

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ def get(self, request):
108108

109109
class ItemView(APIView):
110110
authentication_classes = (CsrfExemptSessionAuthentication,)
111-
def get(self, request):
111+
""" def get(self, request):
112112
auth_header = request.META.get('HTTP_AUTHORIZATION')
113113
if auth_header and auth_header.startswith('Token '):
114114
token_key = auth_header[6:]
@@ -140,7 +140,29 @@ def get(self, request):
140140
except AuthToken.DoesNotExist:
141141
raise AuthenticationFailed('Invalid token')
142142
else:
143-
raise AuthenticationFailed('Authentication credentials were not provided')
143+
raise AuthenticationFailed('Authentication credentials were not provided')"""
144+
145+
def get(self, request):
146+
output = [
147+
{
148+
"id": item.id,
149+
"name": item.name,
150+
"brand": item.brand,
151+
"price": item.price,
152+
"power": item.power,
153+
"type": item.type,
154+
"state": item.state,
155+
"quantity": item.quantity,
156+
"description" : item.description,
157+
"modification_reason": item.modification_reason,
158+
"creation": item.creation,
159+
"removed": item.removed,
160+
"modification_date": item.modification_date,
161+
}
162+
for item in Item.objects.all()
163+
]
164+
return Response(output)
165+
144166

145167
def post(self, request):
146168
authentication_classes = (CsrfExemptSessionAuthentication,)

src/App.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ function App() {
2020
<Route path="/" element={<Site />} />
2121
<Route path="legals" element={<MentionLegals />} />
2222
<Route path="login" element={<Login />} />
23-
<Route path="/inventory" element={<ProtectedRoute element={<Inventory/>}/>}/>
23+
<Route path="/inventory" element={<Inventory/>}/>
24+
{/*<Route path="/inventory" element={<ProtectedRoute element={<Inventory/>}/>}/>*/}
2425
<Route path="*" element={<NoSite />} />
2526
</Routes>
2627
</BrowserRouter>

src/components/LoginButton.jsx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { useHref } from 'react-router-dom';
2+
import { Button } from 'semantic-ui-react';
3+
4+
function LoginButton() {
5+
6+
function handleClick(){
7+
window.location.href = '/login';
8+
}
9+
10+
return (
11+
<Button onClick={handleClick} color='green'>
12+
Login
13+
</Button>
14+
);
15+
}
16+
17+
export default LoginButton;

src/components/LogoutButton.jsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
import { Button } from 'semantic-ui-react';
22
import { useContext } from "react";
33
import { AuthContext } from "../context/AuthContext";
4+
import { UserContext } from "../context/UserContext";
5+
46

57
function LogoutButton() {
68
const { setIsAuthenticated } = useContext(AuthContext);
9+
const {setUserId} = useContext(UserContext);
710

811
const handleLogout = async () => {
912
try {
@@ -23,8 +26,10 @@ function LogoutButton() {
2326
}
2427
// Supprimer le token du local storage
2528
localStorage.removeItem('token');
29+
localStorage.removeItem('user_id');
30+
setUserId(-1);
2631
setIsAuthenticated(false);
27-
window.location.href = '/login';
32+
// window.location.href = '/login';
2833
} catch (error) {
2934
console.error('Erreur lors de la déconnexion:', error);
3035
}

src/components/Matos.jsx

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,19 @@ import { motion } from "framer-motion"
22
import TableData from "./TableData";
33
import '../style/Matos.css'
44
import LogoutButton from "./LogoutButton";
5+
import LoginButton from "./LoginButton";
56
import {MenuItem, Menu, MenuMenu} from "semantic-ui-react";
6-
import {useEffect, useState} from "react";
7+
import {useEffect, useState, useContext} from "react";
78
import HistoryTable from "./History";
9+
import {AuthContext} from "../context/AuthContext";
810

911

1012

1113
function Matos(){
14+
15+
const {isAuthenticated} = useContext(AuthContext);
16+
17+
1218
const [activeItem, setActiveItem] = useState(() => {
1319
const savedActiveItem = localStorage.getItem('activeItem');
1420
return savedActiveItem || 'inventaire';
@@ -28,6 +34,9 @@ function Matos(){
2834
<h1>Gestion du matériel</h1>
2935
{/* menu*/}
3036
<Menu secondary>
37+
38+
{isAuthenticated?
39+
<>
3140
<MenuItem
3241
name='inventaire'
3342
active={activeItem === 'inventaire'}
@@ -38,9 +47,12 @@ function Matos(){
3847
active={activeItem === 'historique'}
3948
onClick={handleItemClick}
4049
/>
50+
</>
51+
:null}
4152
</Menu>
4253
<div>
43-
<LogoutButton/>
54+
{isAuthenticated?<LogoutButton/>:<LoginButton/>
55+
}
4456
</div>
4557

4658
</div>

src/components/ModalAdd.jsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ function ModalAdd(props) {
5353
/>
5454
</div>
5555
</ModalContent>
56-
5756
</Modal>
5857
</>
5958
);

src/components/Stats.jsx

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
1-
import React from 'react';
1+
import {React,useContext} from 'react';
22
import {
33
StatisticValue,
44
StatisticLabel,
55
StatisticGroup,
66
Statistic,
77
} from 'semantic-ui-react';
8+
import {AuthContext} from "../context/AuthContext";
89

910
function Stats(props) {
11+
const {isAuthenticated} = useContext(AuthContext);
12+
13+
1014
return (
1115
<div>
1216

@@ -18,14 +22,19 @@ function Stats(props) {
1822
<StatisticValue>{props.qte === null ? 0 : props.qte}</StatisticValue>
1923
<StatisticLabel>Quantité totale</StatisticLabel>
2024
</Statistic>
21-
<Statistic>
25+
{isAuthenticated?
26+
<>
27+
<Statistic>
2228
<StatisticValue>{props.total_price === null ? 0 : props.total_price}</StatisticValue>
2329
<StatisticLabel>Prix total</StatisticLabel>
2430
</Statistic>
2531
<Statistic>
2632
<StatisticValue>{props.power === null ? 0 : props.total_power}</StatisticValue>
2733
<StatisticLabel>Puissance totale</StatisticLabel>
2834
</Statistic>
35+
</>
36+
: null}
37+
2938

3039
</div>
3140
);

src/components/TableData.jsx

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React, {useCallback, useEffect, useRef, useState, useContext} from 'react';
22
import {UserContext} from "../context/UserContext";
3+
import {AuthContext} from "../context/AuthContext";
34
import * as XLSX from 'xlsx';
45
import {
56
Search,
@@ -21,8 +22,11 @@ import ModalSuccess from "./ModalSuccess";
2122
import ModalFailed from "./ModalFailed";
2223
import TableSelectedItems from "./TableSelectedItems";
2324

25+
26+
2427
function TableData() {
2528
const {userId} = useContext(UserContext);
29+
const {isAuthenticated} = useContext(AuthContext);
2630
const [state, setState] = useState({ isLoading: false, results: [], value: '' });
2731
const [tableData, setTableData] = useState([]);
2832
const [filteredData, setFilteredData] = useState([]);
@@ -49,6 +53,10 @@ function TableData() {
4953
const [supp, setSuppr] = useState('Date de suppression');
5054

5155

56+
console.log(isAuthenticated)
57+
console.log(userId)
58+
59+
5260

5361
useEffect(() => {
5462
if (isLargeScreen) {
@@ -560,10 +568,10 @@ const handleDeselectButton = () => {
560568
/>
561569
<Button icon={"delete"} onClick={() => handleResetFilterState()} />
562570
</div>
563-
{showDeleted || userId === 2 ? null:
571+
{!showDeleted && userId !== 2 && isAuthenticated?
564572
<div className={""}>
565573
<ModalAdd submission={handleSubmission} />
566-
</div>}
574+
</div>:null}
567575
</div>
568576
<Button content='Export' onClick={exportToExcel} />
569577
</div>
@@ -573,7 +581,7 @@ const handleDeselectButton = () => {
573581
<Table striped sortable fixed unstackable>
574582
<TableHeader>
575583
<TableRow>
576-
{showDeleted ? null : <TableHeaderCell>{selection}</TableHeaderCell> }
584+
{!showDeleted && isAuthenticated ? <TableHeaderCell>{selection}</TableHeaderCell> : null}
577585

578586
<TableHeaderCell sorted={column === 'name' ? direction : null} onClick={() => dispatch({ type: 'CHANGE_SORT', column: 'name' })}>{ref}</TableHeaderCell>
579587
{isLargeScreen &&
@@ -592,17 +600,17 @@ const handleDeselectButton = () => {
592600

593601
null
594602
}
595-
{!showDeleted && userId!==2 &&isLargeScreen ? <>
603+
{!showDeleted && userId !== 2 && isLargeScreen ? <>
596604
<TableHeaderCell sorted={column === 'modification_date' ? direction : null} onClick={() => dispatch({ type: 'CHANGE_SORT', column: 'modification_date' })}>Date de modification</TableHeaderCell>
597605
</> :
598606
null
599607
}
600-
{!showDeleted && userId!==2 ? <>
608+
{ (!showDeleted && userId !== 2 && isAuthenticated) ? <>
601609
<TableHeaderCell>{action}</TableHeaderCell>
602610
</> :
603611
null
604612
}
605-
{!showDeleted && userId===2 &&isLargeScreen ? <>
613+
{!showDeleted && userId === 2 && isLargeScreen ? <>
606614
<TableHeaderCell sorted={column === 'modification_date' ? direction : null} onClick={() => dispatch({ type: 'CHANGE_SORT', column: 'modification_date' })}>Date de modification</TableHeaderCell>
607615

608616
</> :
@@ -614,9 +622,9 @@ const handleDeselectButton = () => {
614622
<TableBody>
615623
{sort_state.data.map((item, index) => (
616624
<TableRow key={index}>
617-
{showDeleted ? null : <TableCell><Checkbox
625+
{!showDeleted && isAuthenticated ? <TableCell><Checkbox
618626
checked={!!checkedItems[item.id]}
619-
onChange={() => handleCheckboxChange(item.id)} /></TableCell> }
627+
onChange={() => handleCheckboxChange(item.id)} /></TableCell> : null}
620628
<TableCell>{item.name}</TableCell>
621629
{isLargeScreen && <>
622630
<TableCell>{item.brand}</TableCell>
@@ -637,15 +645,15 @@ const handleDeselectButton = () => {
637645
<TableCell>{convertDateFormat(item.modification_date)}</TableCell>
638646
</> : null
639647
}
640-
{!showDeleted && userId !==2 ?
648+
{!showDeleted && userId !==2 && isAuthenticated ?
641649
<>
642650
<TableCell>
643651
<ModalEdit submission={handleSubmissionEdit} item_id={item.id} reason={item.modification_reason} state={item.state} power={item.power} name={item.name} brand={item.brand} type={item.type} description={item.description} price={item.price} quantity={item.quantity} date={item.creation} />
644652
<ModalDelete submission={handleSubmission} item_id={item.id} reason={item.modification_reason} state={item.state} power={item.power} name={item.name} brand={item.brand} type={item.type} description={item.description} price={item.price} quantity={item.quantity} date={item.creation} />
645653
</TableCell>
646654
</> : null
647655
}
648-
{!showDeleted && userId ===2 &&isLargeScreen ? <>
656+
{!showDeleted && userId ===2 && isLargeScreen ? <>
649657
<TableCell>{convertDateFormat(item.modification_date)}</TableCell>
650658
</> : null
651659
}

src/pages/Inventory.jsx

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,7 @@ function Inventory(){
88
<Matos/>
99
</div>
1010
</body>
11-
12-
13-
1411
<Footer/>
15-
1612
</>
1713
);
1814
}

0 commit comments

Comments
 (0)