-
Notifications
You must be signed in to change notification settings - Fork 40
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: Initialize authorization #7870
Conversation
d0659bf
to
32321a0
Compare
Codecov ReportAttention: Patch coverage is
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.
Additional details and impacted files@@ Coverage Diff @@
## dev #7870 +/- ##
============================================
- Coverage 28.12% 18.35% -9.77%
Complexity 2081 2081
============================================
Files 1289 1020 -269
Lines 157856 128591 -29265
Branches 3131 3138 +7
============================================
- Hits 44390 23606 -20784
+ Misses 111576 103088 -8488
- Partials 1890 1897 +7
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
673cd5d
to
aa62516
Compare
8ae5f30
to
9762b8b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, I think that's a good start!
Should we start introducing types/enums for roles and permissions, instead of strings? Would avoid mixing things up and typos.
Small patch to try out `ProtectedRoute` for testers
diff --git a/front/src/common/authorization/hooks/useCheckUserRole.ts b/front/src/common/authorization/hooks/useCheckUserRole.ts
index 38b3664b3d0e..618066f4883e 100644
--- a/front/src/common/authorization/hooks/useCheckUserRole.ts
+++ b/front/src/common/authorization/hooks/useCheckUserRole.ts
@@ -8,7 +8,7 @@ const useCheckUserRole = (requiredRoles: string[] = []) => {
// - uncomment when user roles are implemented
// const userRoles: string[] = [];
// return requiredRoles.some((role) => userRoles.includes(role))
- return true;
+ return false;
};
export default useCheckUserRole;
diff --git a/front/src/main/app.jsx b/front/src/main/app.jsx
index b9dfe7630a67..1c3586de627c 100644
--- a/front/src/main/app.jsx
+++ b/front/src/main/app.jsx
@@ -29,6 +29,7 @@ import { stdcmConfSlice } from 'reducers/osrdconf/stdcmConf';
import stdcmConfSelectors from 'reducers/osrdconf/stdcmConf/selectors';
import { useAppDispatch } from 'store';
import useAuth from 'utils/hooks/OsrdAuth';
+import ProtectedRoute from 'common/authorization/components/ProtectedRoute.tsx';
import('@sncf/bootstrap-sncf.metier.reseau/dist/css/bootstrap-sncf.min.css');
@@ -68,7 +69,7 @@ const router = createBrowserRouter([
children: [
{
path: '*',
- element: <HomeStdcm />,
+ element: <ProtectedRoute requiredRoles={['nope']}><HomeStdcm /></ProtectedRoute>,
},
],
},
11748a4
to
97322f8
Compare
front/src/common/authorization/components/PermissionBasedContent.tsx
Outdated
Show resolved
Hide resolved
66d197d
to
d5c14c4
Compare
4619893
to
172abcc
Compare
172abcc
to
129cead
Compare
129cead
to
237f6f8
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, tested
e8aaa6d
to
4c7b8d5
Compare
4c7b8d5
to
db5a9e7
Compare
Close #7779
This PR Adds:
1.
ProtectedRoute
Components:2.
RoleBasedContent
andPermissionBasedContent
Components:3. Custom Hooks:
useUserRoleCheck
anduseUserPermissionsCheck
:4. Error 403 listener:
Future Integration:
TODO AUTH
to indicate where we need to complete them later.