diff --git a/CHANGELOG.md b/CHANGELOG.md index 69b2416d..163339c5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,10 +11,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Update dependency on vulnerability for @adobe/css-tools and axios - Fix styles on Save Reports and Upload Ratings - Fix roles that are shown on Table info +- Fix finding for entering country risk if user is not subscribed ### Changed - Updated arc42 documentation to align with the EDC updated Country Risk application. +### Added +- Added Error Page for when user is with right credentials but not subscribed to the App + + ## [1.3.0] - 2023-12-06 ### Added diff --git a/src/App.js b/src/App.js index 20ef54e5..6d303e43 100644 --- a/src/App.js +++ b/src/App.js @@ -31,6 +31,7 @@ import React from "react"; import { BrowserRouter as Router, Routes, Route } from "react-router-dom"; import AboutPage from "./components/dashboard/AboutCard/AboutPage"; import { FooterPortal } from "./components/dashboard/Footer/FooterPortal"; +import ErrorPageCR from "./components/dashboard/ErrorPage/ErrorPageCR"; function App() { return ( @@ -42,18 +43,17 @@ function App() { - -
- -
-
- - } /> - } /> - - -
-
+
+ +
+
+ + } /> + } /> + } /> + + +
diff --git a/src/components/dashboard/AboutCard/AboutPage.js b/src/components/dashboard/AboutCard/AboutPage.js index ddb80feb..4f7f3803 100644 --- a/src/components/dashboard/AboutCard/AboutPage.js +++ b/src/components/dashboard/AboutCard/AboutPage.js @@ -29,7 +29,7 @@ export default function AboutPage() { return (
- +
diff --git a/src/components/dashboard/ErrorPage/ErrorPageCR.js b/src/components/dashboard/ErrorPage/ErrorPageCR.js new file mode 100644 index 00000000..e7b0eb3c --- /dev/null +++ b/src/components/dashboard/ErrorPage/ErrorPageCR.js @@ -0,0 +1,62 @@ +/******************************************************************************** + * Copyright (c) 2022,2024 BMW Group AG + * Copyright (c) 2022,2024 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0 which is available at + * https://www.apache.org/licenses/LICENSE-2.0. + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + * SPDX-License-Identifier: Apache-2.0 + ********************************************************************************/ + +import { AboutCard, PageHeader } from "@catena-x/portal-shared-components"; +import legalJson from "../../../legal-notice.json"; +import { Link } from "@mui/icons-material"; +import { Breadcrumb, Typography } from "@catena-x/portal-shared-components"; +import { PageBreadcrumb } from "../PageBreadCrumb/PageBreadcrumb"; +import "./error.scss"; +import { ErrorPage } from "@catena-x/portal-shared-components"; +import { FooterPortal } from "../Footer/FooterPortal"; +import NavigationBar from "../NavigationBar/NavigationBar"; +import { useNavigate } from "react-router-dom"; +import { getPortalLink } from "../../services/EnvironmentService"; +const ErrorPageCR = () => { + const navigate = useNavigate(); + + return ( +
+ + + + + { + window.location.href = getPortalLink() + "/appmarketplace"; + }} + onReloadClick={() => { + navigate("/"); + }} + reloadButtonTitle="Reload Page" + title="Oops, Something went wrong, subscribe to Country Risk App not found." + /> + +
+ ); +}; + +export default ErrorPageCR; diff --git a/src/components/dashboard/ErrorPage/error.scss b/src/components/dashboard/ErrorPage/error.scss new file mode 100644 index 00000000..52793302 --- /dev/null +++ b/src/components/dashboard/ErrorPage/error.scss @@ -0,0 +1,28 @@ +/******************************************************************************** +* Copyright (c) 2022,2024 BMW Group AG +* Copyright (c) 2022,2024 Contributors to the Eclipse Foundation +* +* See the NOTICE file(s) distributed with this work for additional +* information regarding copyright ownership. +* +* This program and the accompanying materials are made available under the +* terms of the Apache License, Version 2.0 which is available at +* https://www.apache.org/licenses/LICENSE-2.0. +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +* License for the specific language governing permissions and limitations +* under the License. +* +* SPDX-License-Identifier: Apache-2.0 +********************************************************************************/ + +.ErrorPage { + display: flex; + flex-direction: column; + justify-content: center; + align-items: center; + font-weight: 100; + font-size: small; +} diff --git a/src/components/dashboard/PageBreadCrumb/PageBreadcrumb.js b/src/components/dashboard/PageBreadCrumb/PageBreadcrumb.js index f2fcd261..890f5d45 100644 --- a/src/components/dashboard/PageBreadCrumb/PageBreadcrumb.js +++ b/src/components/dashboard/PageBreadCrumb/PageBreadcrumb.js @@ -32,7 +32,7 @@ function isParamsEmpty(params) { return true; } -export const PageBreadcrumb = () => { +export const PageBreadcrumb = ({ title }) => { const navigate = useNavigate(); const params = useParams(); const location = useLocation(); @@ -54,7 +54,7 @@ export const PageBreadcrumb = () => { }, [location, params]); const getCrumbTitle = (crumb) => { - return "About"; + return title; }; const breadcrumbs = () => { diff --git a/src/components/dashboard/RootComponent/RootComponent.js b/src/components/dashboard/RootComponent/RootComponent.js new file mode 100644 index 00000000..5b8dc161 --- /dev/null +++ b/src/components/dashboard/RootComponent/RootComponent.js @@ -0,0 +1,38 @@ +/******************************************************************************** + * Copyright (c) 2022,2024 BMW Group AG + * Copyright (c) 2022,2024 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0 which is available at + * https://www.apache.org/licenses/LICENSE-2.0. + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + * SPDX-License-Identifier: Apache-2.0 + ********************************************************************************/ +import React, { useState, useEffect } from "react"; +import App from "../../../App"; +import ErrorPageCR from "../ErrorPage/ErrorPageCR"; + +const RootComponent = ({ user }) => { + const [shouldShowErrorPage, setShouldShowErrorPage] = useState(false); + + useEffect(() => { + if (user.access) { + setShouldShowErrorPage(false); + } else { + setShouldShowErrorPage(true); + } + }, [user]); + + return shouldShowErrorPage ? : ; +}; + +export default RootComponent; diff --git a/src/components/services/UserService.js b/src/components/services/UserService.js index 00651482..76dedbb5 100644 --- a/src/components/services/UserService.js +++ b/src/components/services/UserService.js @@ -55,6 +55,10 @@ const keycloakConfigBpdm = { const KC = new Keycloak(keycloakConfigCountryRisk); +var hasAcess = false; + +const getHasAcess = () => hasAcess; + const init = (onAuthenticatedCallback) => { KC.init({ onLoad: "login-required", @@ -62,10 +66,28 @@ const init = (onAuthenticatedCallback) => { window.location.origin + "/silent-check-sso.html", pkceMethod: "S256", }).then((authenticated) => { - if (authenticated) { - info(`${getUsername()} authenticated`); + // Extrai resource_access do tokenParsed para simplificar a leitura + const resourceAccess = KC.tokenParsed?.resource_access || {}; + // Verifica se resourceAccess contém a propriedade especificada pelo clientId + const hasClientAccess = resourceAccess.hasOwnProperty( + keycloakConfigCountryRisk.clientId + ); + + if ( + authenticated && + Object.keys(resourceAccess).length > 0 && + hasClientAccess + ) { + info("authenticated with access"); + hasAcess = true; // Assume que hasAcess está definida em algum lugar do seu código + onAuthenticatedCallback(getLoggedUser()); + } else if (authenticated) { + // Isso cobre tanto a falta de clientId quanto resourceAccess vazio + info("authenticated without sufficient access"); + hasAcess = false; onAuthenticatedCallback(getLoggedUser()); } else { + info("User not authenticated, initiating login"); doLogin(); } }); @@ -143,6 +165,7 @@ const getLoggedUser = () => ({ isAdmin: isAdmin(), token: getToken(), parsedToken: getParsedToken(), + access: getHasAcess(), }); const UserService = { diff --git a/src/index.js b/src/index.js index 00e11c19..f7fae170 100644 --- a/src/index.js +++ b/src/index.js @@ -19,8 +19,7 @@ ********************************************************************************/ import React from "react"; import ReactDOM from "react-dom/client"; -import App from "./App"; -import { Provider } from "react-redux"; + import { SharedThemeProvider, SharedCssBaseline, @@ -28,6 +27,8 @@ import { import UserService from "./components/services/UserService"; import { getHostname } from "./components/services/EnvironmentService"; +import RootComponent from "./components/dashboard/RootComponent/RootComponent"; +import { BrowserRouter as Router, Routes, Route } from "react-router-dom"; const hostname = getHostname(); if (hostname.includes("country-risk-dashboard.dev")) import("./index-dev.scss"); if (hostname.includes("country-risk-dashboard.int")) import("./index-int.scss"); @@ -36,26 +37,18 @@ else { } const root = ReactDOM.createRoot(document.getElementById("root")); -if(hostname==="localhost"){ + +UserService.init((user) => { root.render( - + {" "} + {" "} - - + {" "} + + {" "} + + {" "} ); -} else { - UserService.init((user) => { - root.render( - - {" "} - {" "} - - {" "} - {" "} - {" "} - - ); - }); -} +});