-
Notifications
You must be signed in to change notification settings - Fork 131
Add serverless support for UI elements #277
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
Merged
Merged
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
4880660
Add serverless support for UI elements
8622d52
fmt
287ab40
Refactor restricted route handling and improve access denial messages…
9620190
fmt
16de399
Enhance sidebar visibility based on access restrictions and add scrip…
8675969
Update src/components/Sidebar/Sidebar.jsx
n0x29a File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| // add unavailable routes to show message on these pages | ||
| // useful if used bookmarked or shared link | ||
| export const restrictedRoutes = ['/datasets', '/jwt', '/tutorial']; | ||
|
|
||
| export const isPathRestricted = (path) => { | ||
| return restrictedRoutes.some((restrictedPath) => { | ||
| if (restrictedPath.includes('*')) { | ||
| const regexPath = restrictedPath.replace('*', '.*'); | ||
| return new RegExp(`^${regexPath}$`).test(path); | ||
| } | ||
| return path === restrictedPath; | ||
| }); | ||
| }; | ||
|
|
||
| export const isTokenRestricted = (token) => { | ||
| if (!token) { | ||
| return false; | ||
| } | ||
|
|
||
| try { | ||
| const decodedToken = JSON.parse(atob(token.split('.')[1])); | ||
| if (!decodedToken.access || !Array.isArray(decodedToken.access)) { | ||
| return false; | ||
| } | ||
| return decodedToken.access.some(({ access }) => access === 'prw'); | ||
| } catch (e) { | ||
| return false; | ||
| } | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| import { describe, it, expect, vi } from 'vitest'; | ||
| import { renderHook } from '@testing-library/react'; | ||
| import { useClient, ClientProvider } from './client-context'; | ||
| import { bigIntJSON } from '../common/bigIntJSON'; | ||
|
|
||
| // Mock localStorage | ||
| const mockLocalStorage = { | ||
| getItem: vi.fn(), | ||
| setItem: vi.fn(), | ||
| }; | ||
|
|
||
| Object.defineProperty(window, 'localStorage', { | ||
| value: mockLocalStorage, | ||
| }); | ||
|
|
||
| // Mock JWT token | ||
| const mockRestrictedToken = 'eyJhbGciOiJIUzI1NiJ9.eyJhY2Nlc3MiOlt7ImFjY2VzcyI6InBydyJ9XX0.x'; | ||
| const mockUnrestrictedToken = 'eyJhbGciOiJIUzI1NiJ9.eyJhY2Nlc3MiOlt7ImFjY2VzcyI6InIifV19.x'; | ||
|
|
||
| describe('useClient', () => { | ||
| beforeEach(() => { | ||
| mockLocalStorage.getItem.mockReset(); | ||
| mockLocalStorage.setItem.mockReset(); | ||
| }); | ||
|
|
||
| it('should return isRestricted=true for restricted token', () => { | ||
| mockLocalStorage.getItem.mockReturnValue(bigIntJSON.stringify({ apiKey: mockRestrictedToken })); | ||
|
|
||
| const { result } = renderHook(() => useClient(), { wrapper: ClientProvider }); | ||
|
|
||
| expect(result.current.isRestricted).toBe(true); | ||
| }); | ||
|
|
||
| it('should return isRestricted=false for unrestricted token', () => { | ||
| mockLocalStorage.getItem.mockReturnValue(bigIntJSON.stringify({ apiKey: mockUnrestrictedToken })); | ||
|
|
||
| const { result } = renderHook(() => useClient(), { wrapper: ClientProvider }); | ||
|
|
||
| expect(result.current.isRestricted).toBe(false); | ||
| }); | ||
|
|
||
| it('should return isRestricted=false for no token', () => { | ||
| mockLocalStorage.getItem.mockReturnValue(null); | ||
|
|
||
| const { result } = renderHook(() => useClient(), { wrapper: ClientProvider }); | ||
|
|
||
| expect(result.current.isRestricted).toBe(false); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| import { useLocation } from 'react-router-dom'; | ||
| import { useClient } from '../context/client-context'; | ||
| import { isPathRestricted } from '../config/restricted-routes'; | ||
|
|
||
| export const useRouteAccess = () => { | ||
| const location = useLocation(); | ||
| const { isRestricted } = useClient(); | ||
|
|
||
| // Extract path from hash route | ||
| const path = location.pathname; | ||
|
|
||
| return { | ||
| // use this to show restricted message on unavailable routes | ||
| isAccessDenied: isRestricted && isPathRestricted(path), | ||
| }; | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.