From 9c4a105164dad23a3b051293d4a39299e6368965 Mon Sep 17 00:00:00 2001 From: "D. Gopal Krishna" Date: Mon, 25 Dec 2023 23:15:46 +0530 Subject: [PATCH 1/5] #793 Not Found page --- .../osb-portal/src/pages/NotFoundPage.tsx | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 applications/osb-portal/src/pages/NotFoundPage.tsx diff --git a/applications/osb-portal/src/pages/NotFoundPage.tsx b/applications/osb-portal/src/pages/NotFoundPage.tsx new file mode 100644 index 00000000..7d63d2d5 --- /dev/null +++ b/applications/osb-portal/src/pages/NotFoundPage.tsx @@ -0,0 +1,43 @@ +import React from 'react' +import { Alert, Button, Dialog, DialogActions, DialogContent, DialogTitle } from '@mui/material' +import { getCleanPath } from '../utils' + +const NotFoundPage = () => { + const [message, setMessage] = React.useState("") + const pathParts = getCleanPath(window.location.pathname) + React.useEffect(() => { + setMessage("This path doesn't exist") + }, [pathParts]) + return ( + <> + + + + +
+ {message} +
+
+
+ + + + +
+ + ) + + +} + +export default NotFoundPage \ No newline at end of file From 35cc96a0b0fa983bf3a6ecebb487927891dcba7a Mon Sep 17 00:00:00 2001 From: "D. Gopal Krishna" Date: Mon, 25 Dec 2023 23:17:16 +0530 Subject: [PATCH 2/5] #793 User page error boundary fix --- applications/osb-portal/src/pages/UserPage.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/applications/osb-portal/src/pages/UserPage.tsx b/applications/osb-portal/src/pages/UserPage.tsx index 44b069e2..1f2f57b5 100644 --- a/applications/osb-portal/src/pages/UserPage.tsx +++ b/applications/osb-portal/src/pages/UserPage.tsx @@ -182,7 +182,8 @@ export const UserPage = (props: any) => { React.useEffect(() => { getUser(userName).then((u) => { setUser(u); - + }).catch((e) => { + setError(e); }); }, [userName, props.workspacesCounter]); From 7d3ead3c4296ff55e980974ecb929f88580b07ff Mon Sep 17 00:00:00 2001 From: "D. Gopal Krishna" Date: Mon, 25 Dec 2023 23:17:53 +0530 Subject: [PATCH 3/5] #793 fix OSB Boundary for workspace page with global error --- applications/osb-portal/src/App.tsx | 4 +++- .../components/handlers/OSBErrorBoundary.tsx | 20 +++++++++++++++++-- applications/osb-portal/src/utils.ts | 8 ++++++++ 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/applications/osb-portal/src/App.tsx b/applications/osb-portal/src/App.tsx index 3296855d..8ae7a5c5 100644 --- a/applications/osb-portal/src/App.tsx +++ b/applications/osb-portal/src/App.tsx @@ -32,6 +32,7 @@ import { import Box from "@mui/material/Box"; import { UserInfo } from "./types/user"; import SampleIframePage from "./pages/SampleIframePage"; +import NotFoundPage from "./pages/NotFoundPage"; declare module "@mui/styles/defaultTheme" { // eslint-disable-next-line @typescript-eslint/no-empty-interface @@ -75,7 +76,7 @@ export const App = (props: AppProps) => { return ( - + {!props.error && ( @@ -171,6 +172,7 @@ export const App = (props: AppProps) => { /> } /> + } /> diff --git a/applications/osb-portal/src/components/handlers/OSBErrorBoundary.tsx b/applications/osb-portal/src/components/handlers/OSBErrorBoundary.tsx index f3a41d5f..8717a6a3 100644 --- a/applications/osb-portal/src/components/handlers/OSBErrorBoundary.tsx +++ b/applications/osb-portal/src/components/handlers/OSBErrorBoundary.tsx @@ -7,6 +7,10 @@ import DialogContent from "@mui/material/DialogContent"; import DialogTitle from "@mui/material/DialogTitle"; import Button from "@mui/material/Button"; +interface OSBErrorBoundaryProps { + error?: any; +} + interface OwnState { eventId: string; hasError: string; @@ -23,9 +27,12 @@ const ERROR_MESSAGES: any = { // 404 "NOT FOUND": "Oops. This resource could not be found. Please check the URL you are trying to access and try again.", + // User 404 + "USER_NOT_FOUND": + "Oops. This user could not be found. Please check the URL you are trying to access and try again.", }; -class OSBErrorBoundary extends React.Component<{}, OwnState> { +class OSBErrorBoundary extends React.Component { public state: OwnState = { eventId: null, hasError: null, @@ -46,7 +53,9 @@ class OSBErrorBoundary extends React.Component<{}, OwnState> { let message = "Oops. Something went wrong. Please report this error to us."; - if (error.status && error.status < 500) { + if (window.location.pathname.startsWith("/user/")) { + message = ERROR_MESSAGES["USER_NOT_FOUND"]; + } else if (error.status && error.status < 500) { message = ERROR_MESSAGES[error.statusText] || error.statusText; } else { Sentry.captureException(error); @@ -55,6 +64,13 @@ class OSBErrorBoundary extends React.Component<{}, OwnState> { }); } + static getDerivedStateFromProps(nextProps: any, prevState: any) { + if (nextProps.error) { + return { ...prevState, hasError: 'true', message: nextProps.error }; + } + return null; + } + render() { if (this.state.hasError) { // render fallback UI diff --git a/applications/osb-portal/src/utils.ts b/applications/osb-portal/src/utils.ts index a59aba8c..9b8d9a1f 100644 --- a/applications/osb-portal/src/utils.ts +++ b/applications/osb-portal/src/utils.ts @@ -32,4 +32,12 @@ export function getNotebooksNamedServerLink() { return null; } return `//${OSBAllApplications.jupyter.subdomain}.${getBaseDomain()}/hub/home` +} + +export function getCleanPath(path: string) { + const pathParts = path.split("/") + if (pathParts[pathParts.length - 1] === "") { + pathParts.pop() + } + return pathParts } \ No newline at end of file From 071f56e79497c0c08eee1853dd7b1f7a8a8fa679 Mon Sep 17 00:00:00 2001 From: "D. Gopal Krishna" Date: Tue, 26 Dec 2023 00:07:23 +0530 Subject: [PATCH 4/5] #739 incognito fix - throw 401 unauthorized without token --- .../workspaces/server/workspaces/service/crud_service.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/applications/workspaces/server/workspaces/service/crud_service.py b/applications/workspaces/server/workspaces/service/crud_service.py index a7bcba15..57e84405 100644 --- a/applications/workspaces/server/workspaces/service/crud_service.py +++ b/applications/workspaces/server/workspaces/service/crud_service.py @@ -237,6 +237,8 @@ def clone(self, workspace_id): def is_authorized(self, workspace): current_user_id = keycloak_user_id() + if not current_user_id: + return False return workspace and (workspace.publicable or (workspace.user_id and workspace.user_id == current_user_id) or (get_auth_client().user_has_realm_role(user_id=current_user_id, role="administrator"))) @@ -299,6 +301,8 @@ def to_dao(cls, d: dict) -> TWorkspaceEntity: def get(self, id_): workspace: Workspace = super().get(id_) + if not self.is_authorized(workspace): + raise NotAuthorized() if any(wr.status == ResourceStatus.P for wr in workspace.resources): fake_path = f"Importing resources" From 85a7e0f88cdc5ee7310f352e138bfac138d0fcd2 Mon Sep 17 00:00:00 2001 From: "D. Gopal Krishna" Date: Tue, 26 Dec 2023 00:16:05 +0530 Subject: [PATCH 5/5] #793 fix error boundary prevstate --- .../osb-portal/src/components/handlers/OSBErrorBoundary.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/applications/osb-portal/src/components/handlers/OSBErrorBoundary.tsx b/applications/osb-portal/src/components/handlers/OSBErrorBoundary.tsx index 8717a6a3..21ff4a5a 100644 --- a/applications/osb-portal/src/components/handlers/OSBErrorBoundary.tsx +++ b/applications/osb-portal/src/components/handlers/OSBErrorBoundary.tsx @@ -68,7 +68,7 @@ class OSBErrorBoundary extends React.Component if (nextProps.error) { return { ...prevState, hasError: 'true', message: nextProps.error }; } - return null; + return { ...prevState }; } render() {