From 24cceafeda7b6ccea232cc003508b36530770887 Mon Sep 17 00:00:00 2001 From: Hafsa Date: Thu, 22 Aug 2024 15:03:55 +0200 Subject: [PATCH 1/3] 70-access-auth: handle accessfor admin & user --- frontend/src/App.tsx | 18 +++++++++++++----- .../EditProduct/EditProductForm.tsx | 1 - frontend/src/components/Layout.tsx | 8 ++++++-- frontend/src/components/Navbar.tsx | 19 +++++++++++++++---- frontend/src/pages/Profile.tsx | 5 +++++ .../src/restrictions/AccessRestriction.tsx | 6 ++---- package-lock.json | 2 +- 7 files changed, 42 insertions(+), 17 deletions(-) create mode 100644 frontend/src/pages/Profile.tsx diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx index ed8a89b..15d2d28 100644 --- a/frontend/src/App.tsx +++ b/frontend/src/App.tsx @@ -9,15 +9,15 @@ import Login from "./pages/Login"; import SearchPage from "./pages/search/[searchKeywords]"; import SearchError from "./pages/search/SearchError"; import AccessRestriction from "./restrictions/AccessRestriction"; - -const user = { - role: "admin", -}; +import Profile from "./pages/Profile"; const App = () => { + + const user = "admin"; + return ( - }> + }> } /> } /> { } /> + + + + } + /> } /> } /> } /> diff --git a/frontend/src/components/EditProduct/EditProductForm.tsx b/frontend/src/components/EditProduct/EditProductForm.tsx index 7923039..9437119 100644 --- a/frontend/src/components/EditProduct/EditProductForm.tsx +++ b/frontend/src/components/EditProduct/EditProductForm.tsx @@ -1,4 +1,3 @@ -import React from 'react'; import { Button, Form, Input, message } from 'antd'; import { Product } from '../../interface/types'; import { GetAllArticlesDocument, GetAllProductsDocument, useEditProductMutation } from '../../generated/graphql-types'; diff --git a/frontend/src/components/Layout.tsx b/frontend/src/components/Layout.tsx index d3d535a..a565ad7 100644 --- a/frontend/src/components/Layout.tsx +++ b/frontend/src/components/Layout.tsx @@ -10,10 +10,14 @@ export const UserContext = createContext({ refetch: () => {}, }); -function Layout() { +interface LayoutType { + user: string; +} + +function Layout({ user }: LayoutType) { return (
- +
diff --git a/frontend/src/components/Navbar.tsx b/frontend/src/components/Navbar.tsx index 558191f..1bd48f6 100644 --- a/frontend/src/components/Navbar.tsx +++ b/frontend/src/components/Navbar.tsx @@ -5,7 +5,11 @@ import { Link } from "react-router-dom"; const { Search } = Input; -function Navbar() { +interface NavbarType { + user: string; +} + +function Navbar({ user }: NavbarType) { const navigate = useNavigate(); const onSearch = (value: string) => { @@ -30,9 +34,16 @@ function Navbar() {
- - - + {user === "admin" ? ( + + + + ) : ( + + + + )} +
diff --git a/frontend/src/pages/Profile.tsx b/frontend/src/pages/Profile.tsx new file mode 100644 index 0000000..d70d0b5 --- /dev/null +++ b/frontend/src/pages/Profile.tsx @@ -0,0 +1,5 @@ +const Profile = () => { + return
test
; +}; + +export default Profile; diff --git a/frontend/src/restrictions/AccessRestriction.tsx b/frontend/src/restrictions/AccessRestriction.tsx index b325648..6c3b103 100644 --- a/frontend/src/restrictions/AccessRestriction.tsx +++ b/frontend/src/restrictions/AccessRestriction.tsx @@ -3,15 +3,13 @@ import { Navigate } from "react-router-dom"; export type AccessRestrictionTypes = { children: ReactNode; - user?: { - role: string; - }; + user: string; }; const AccessRestriction: React.FC = ({ children, user, }) => { - if (!user || user.role !== "admin") { + if (!user || user !== "admin" && user !== "user") { return ; } diff --git a/package-lock.json b/package-lock.json index 805bba2..11195c5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,5 +1,5 @@ { - "name": "2024-02-wns-bleu-wildrent", + "name": "Projet", "lockfileVersion": 3, "requires": true, "packages": {} From 16e7b7a56b38ff4ac3d5456f52fb5ae5ed483032 Mon Sep 17 00:00:00 2001 From: Hafsa Date: Thu, 22 Aug 2024 15:03:55 +0200 Subject: [PATCH 2/3] 70-access-auth: handle accessfor admin & user --- frontend/src/App.tsx | 18 +++++++++++++----- frontend/src/components/Layout.tsx | 16 ++++++++++++++++ frontend/src/components/Navbar.tsx | 17 ++++++++++++++++- frontend/src/pages/Profile.tsx | 5 +++++ .../src/restrictions/AccessRestriction.tsx | 6 ++---- package-lock.json | 2 +- 6 files changed, 53 insertions(+), 11 deletions(-) create mode 100644 frontend/src/pages/Profile.tsx diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx index ed8a89b..15d2d28 100644 --- a/frontend/src/App.tsx +++ b/frontend/src/App.tsx @@ -9,15 +9,15 @@ import Login from "./pages/Login"; import SearchPage from "./pages/search/[searchKeywords]"; import SearchError from "./pages/search/SearchError"; import AccessRestriction from "./restrictions/AccessRestriction"; - -const user = { - role: "admin", -}; +import Profile from "./pages/Profile"; const App = () => { + + const user = "admin"; + return ( - }> + }> } /> } /> { } /> + + + + } + /> } /> } /> } /> diff --git a/frontend/src/components/Layout.tsx b/frontend/src/components/Layout.tsx index da87957..a7e6b3d 100644 --- a/frontend/src/components/Layout.tsx +++ b/frontend/src/components/Layout.tsx @@ -45,6 +45,22 @@ function Layout() { ); +interface LayoutType { + user: string; +} + +function Layout({ user }: LayoutType) { + return ( +
+ +
+ +
+
+
+
+
+ ); } export default Layout; diff --git a/frontend/src/components/Navbar.tsx b/frontend/src/components/Navbar.tsx index 3539aa9..b3f4ff9 100644 --- a/frontend/src/components/Navbar.tsx +++ b/frontend/src/components/Navbar.tsx @@ -13,7 +13,11 @@ import { useLogoutLazyQuery } from "../generated/graphql-types"; const { Search } = Input; -function Navbar() { +interface NavbarType { + user: string; +} + +function Navbar({ user }: NavbarType) { const navigate = useNavigate(); const onSearch = (value: string) => { @@ -78,6 +82,17 @@ function Navbar() { )} + {user === "admin" ? ( + + + + ) : ( + + + + )} + + ); diff --git a/frontend/src/pages/Profile.tsx b/frontend/src/pages/Profile.tsx new file mode 100644 index 0000000..d70d0b5 --- /dev/null +++ b/frontend/src/pages/Profile.tsx @@ -0,0 +1,5 @@ +const Profile = () => { + return
test
; +}; + +export default Profile; diff --git a/frontend/src/restrictions/AccessRestriction.tsx b/frontend/src/restrictions/AccessRestriction.tsx index b325648..6c3b103 100644 --- a/frontend/src/restrictions/AccessRestriction.tsx +++ b/frontend/src/restrictions/AccessRestriction.tsx @@ -3,15 +3,13 @@ import { Navigate } from "react-router-dom"; export type AccessRestrictionTypes = { children: ReactNode; - user?: { - role: string; - }; + user: string; }; const AccessRestriction: React.FC = ({ children, user, }) => { - if (!user || user.role !== "admin") { + if (!user || user !== "admin" && user !== "user") { return ; } diff --git a/package-lock.json b/package-lock.json index 805bba2..11195c5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,5 +1,5 @@ { - "name": "2024-02-wns-bleu-wildrent", + "name": "Projet", "lockfileVersion": 3, "requires": true, "packages": {} From 56f42e544ce3c307bdb22be0b3def24c980e5b3a Mon Sep 17 00:00:00 2001 From: Hafsa Date: Thu, 22 Aug 2024 15:48:22 +0200 Subject: [PATCH 3/3] rebase --- frontend/src/components/Layout.tsx | 24 +++++------------------- frontend/src/components/Navbar.tsx | 26 ++++++++++---------------- 2 files changed, 15 insertions(+), 35 deletions(-) diff --git a/frontend/src/components/Layout.tsx b/frontend/src/components/Layout.tsx index a7e6b3d..1580713 100644 --- a/frontend/src/components/Layout.tsx +++ b/frontend/src/components/Layout.tsx @@ -12,7 +12,10 @@ export const UserContext = createContext({ refetch: () => {}, }); -function Layout() { +interface LayoutType { + user: string; +} +function Layout({ user }: LayoutType) { const { data, refetch, loading, error } = useWhoAmIQuery(); if (loading) { @@ -35,7 +38,7 @@ function Layout() { }} >
- +
@@ -45,22 +48,5 @@ function Layout() {
); -interface LayoutType { - user: string; } - -function Layout({ user }: LayoutType) { - return ( -
- -
- -
-
-
-
-
- ); -} - export default Layout; diff --git a/frontend/src/components/Navbar.tsx b/frontend/src/components/Navbar.tsx index b3f4ff9..a382b43 100644 --- a/frontend/src/components/Navbar.tsx +++ b/frontend/src/components/Navbar.tsx @@ -26,7 +26,7 @@ function Navbar({ user }: NavbarType) { const [logout] = useLogoutLazyQuery(); const userInfo = useContext(UserContext); - + console.log(userInfo, "userinfo"); return (
@@ -48,10 +48,15 @@ function Navbar({ user }: NavbarType) { {userInfo.isLoggedIn && (

Bonjour, {userInfo.firstname}

)} - - - - + {user === "admin" ? ( + + + + ) : ( + + + + )} @@ -82,17 +87,6 @@ function Navbar({ user }: NavbarType) { )} - {user === "admin" ? ( - - - - ) : ( - - - - )} - -
);