-
Notifications
You must be signed in to change notification settings - Fork 173
Refactor permission check redirect #2109
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
base: main
Are you sure you want to change the base?
Changes from all commits
b4c9c92
b640a07
fc8f274
e643efe
1115a4b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| import React from 'react'; | ||
| import React, { useEffect } from 'react'; | ||
| import { useNavigate } from 'react-router-dom'; | ||
|
|
||
| import { authenticationSession } from '@/app/lib/authentication-session'; | ||
| import { Permission } from '@openops/shared'; | ||
|
|
@@ -12,3 +13,17 @@ export const useAuthorization = () => { | |
|
|
||
| return { checkAccess, role }; | ||
| }; | ||
|
|
||
| export const useCheckAccessAndRedirect = (permission: Permission) => { | ||
| const { checkAccess } = useAuthorization(); | ||
| const navigate = useNavigate(); | ||
| const hasAccess = checkAccess(permission); | ||
|
|
||
| useEffect(() => { | ||
| if (!hasAccess) { | ||
| navigate('/', { replace: true }); | ||
| } | ||
| }, [hasAccess, navigate]); | ||
|
|
||
| return hasAccess; | ||
| }; | ||
|
Comment on lines
+17
to
+29
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| import { useAuthorization } from '@/app/common/hooks/authorization-hooks'; | ||
| import { useCheckAccessAndRedirect } from '@/app/common/hooks/authorization-hooks'; | ||
| import { useTheme } from '@/app/common/providers/theme-provider'; | ||
| import { OPENOPS_CONNECT_TEMPLATES_URL } from '@/app/constants/cloud'; | ||
| import { ExpandedTemplate } from '@/app/features/templates/components/expanded-template'; | ||
|
|
@@ -97,8 +97,9 @@ const SelectFlowTemplateDialogContent = ({ | |
| const ownerLogoUrl = useOwnerLogoUrl(); | ||
| const { createPollingInterval } = useUserInfoPolling(); | ||
| const { isCloudUser } = useShowTemplatesBanner(); | ||
| const { checkAccess } = useAuthorization(); | ||
| const hasWriteFlowPermission = checkAccess(Permission.WRITE_FLOW); | ||
| const hasWriteFlowPermission = useCheckAccessAndRedirect( | ||
| Permission.WRITE_FLOW, | ||
| ); | ||
|
Comment on lines
+100
to
+102
|
||
| const isFullCatalog = !isTemplatePreselected && isCloudUser; | ||
|
|
||
| const onExploreMoreClick = () => { | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
| @@ -1,9 +1,10 @@ | ||||||||
| import { PopulatedFlow } from '@openops/shared'; | ||||||||
| import { Permission, PopulatedFlow } from '@openops/shared'; | ||||||||
| import { useQuery } from '@tanstack/react-query'; | ||||||||
| import { useEffect } from 'react'; | ||||||||
| import { Navigate, useParams, useSearchParams } from 'react-router-dom'; | ||||||||
|
|
||||||||
| import { FullPageSpinner } from '@/app/common/components/full-page-spinner'; | ||||||||
| import { useCheckAccessAndRedirect } from '@/app/common/hooks/authorization-hooks'; | ||||||||
| import { QueryKeys } from '@/app/constants/query-keys'; | ||||||||
| import { SEARCH_PARAMS } from '@/app/constants/search-params'; | ||||||||
| import { BuilderPage } from '@/app/features/builder'; | ||||||||
|
|
@@ -15,6 +16,7 @@ import { flowsApi } from '@/app/features/flows/lib/flows-api'; | |||||||
| import { AxiosError } from 'axios'; | ||||||||
|
|
||||||||
| const FlowBuilderPage = () => { | ||||||||
| const hasAccess = useCheckAccessAndRedirect(Permission.READ_FLOW); | ||||||||
| const { flowId } = useParams(); | ||||||||
| const [searchParams, setSearchParams] = useSearchParams(); | ||||||||
|
|
||||||||
|
|
@@ -51,6 +53,10 @@ const FlowBuilderPage = () => { | |||||||
| refetchOnWindowFocus: 'always', | ||||||||
|
||||||||
| refetchOnWindowFocus: 'always', | |
| refetchOnWindowFocus: 'always', | |
| enabled: Boolean(hasAccess && flowId), |
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.
useCheckAccessAndRedirectrelies oncheckAccess(permission), butcheckAccesscurrently always returnstrue, so the redirect andhasAccessgating will never trigger. If this PR is meant to enforce permissions,checkAccessneeds to implement real permission evaluation (e.g., based on the user/project role/permissions) or the new hook won’t have any effect.