From 7e38ba7a6d6d7c3c90a0966014c347c46a9c747d Mon Sep 17 00:00:00 2001 From: DonOmalVindula Date: Thu, 18 Apr 2024 14:34:14 +0530 Subject: [PATCH 1/3] Remove governance connector provider --- apps/console/src/app.tsx | 403 ++++++++---------- .../governance-connector-context.tsx | 22 - .../governance-connector-provider.tsx | 56 --- .../providers/governance-connector/index.ts | 20 - .../models/governance-connector.ts | 30 -- .../use-governance-connector.tsx | 31 -- .../react-components/src/providers/index.ts | 3 +- 7 files changed, 186 insertions(+), 379 deletions(-) delete mode 100644 modules/react-components/src/providers/governance-connector/governance-connector-context.tsx delete mode 100644 modules/react-components/src/providers/governance-connector/governance-connector-provider.tsx delete mode 100644 modules/react-components/src/providers/governance-connector/index.ts delete mode 100644 modules/react-components/src/providers/governance-connector/models/governance-connector.ts delete mode 100644 modules/react-components/src/providers/governance-connector/use-governance-connector.tsx diff --git a/apps/console/src/app.tsx b/apps/console/src/app.tsx index fb6eb276ae9..96f2ca3fb94 100755 --- a/apps/console/src/app.tsx +++ b/apps/console/src/app.tsx @@ -17,9 +17,7 @@ */ import { BasicUserInfo, DecodedIDTokenPayload, useAuthContext } from "@asgardeo/auth-react"; -import { useRequiredScopes } from "@wso2is/access-control"; import { AppConstants as CommonAppConstants } from "@wso2is/core/constants"; -import { IdentityAppsApiException } from "@wso2is/core/exceptions"; import { CommonHelpers, isPortalAccessGranted } from "@wso2is/core/helpers"; import { RouteInterface, StorageIdentityAppsSettingsInterface, emptyIdentityAppsSettings } from "@wso2is/core/models"; import { setI18nConfigs, setServiceResourceEndpoints } from "@wso2is/core/store"; @@ -39,16 +37,11 @@ import { } from "@wso2is/features/admin.core.v1/models"; import { AppState } from "@wso2is/features/admin.core.v1/store"; import { commonConfig } from "@wso2is/features/admin.extensions.v1"; -import { - GovernanceCategoryForOrgsInterface, - useGovernanceConnectorCategories -} from "@wso2is/features/admin.server-configurations.v1"; import { I18nModuleOptionsInterface } from "@wso2is/i18n"; import { ChunkErrorModal, Code, DocumentationProvider, - GovernanceConnectorProvider, MediaContextProvider, NetworkErrorModal, SessionManagementProvider, @@ -94,25 +87,11 @@ export const App: FunctionComponent> = (): ReactElement => const isFirstLevelOrg: boolean = useSelector( (state: AppState) => state.organization.isFirstLevelOrganization ); - const featureConfig: FeatureConfigInterface = useSelector( - (state: AppState) => state.config.ui.features - ); const allowedScopes: string = useSelector((state: AppState) => state?.auth?.allowedScopes); const [ baseRoutes, setBaseRoutes ] = useState(getBaseRoutes()); const [ sessionTimedOut, setSessionTimedOut ] = useState(false); const [ routesFiltered, setRoutesFiltered ] = useState(false); - const [ governanceConnectors, setGovernanceConnectors ] = useState([]); - - const hasGovernanceConnectorsReadScope: boolean = useRequiredScopes( - featureConfig?.governanceConnectors?.scopes?.read); - - const { - data: originalConnectorCategories, - error: connectorCategoriesFetchRequestError - } = useGovernanceConnectorCategories( - featureConfig?.server?.enabled && isFirstLevelOrg && - hasGovernanceConnectorsReadScope); /** * Set the deployment configs in redux state. @@ -235,17 +214,7 @@ export const App: FunctionComponent> = (): ReactElement => } filterRoutes(() => setRoutesFiltered(true), isFirstLevelOrg); - }, [ filterRoutes, governanceConnectors, state.isAuthenticated, isFirstLevelOrg ]); - - useEffect(() => { - if (!originalConnectorCategories || - originalConnectorCategories instanceof IdentityAppsApiException || - connectorCategoriesFetchRequestError) { - return; - } - - setGovernanceConnectors(originalConnectorCategories); - }, [ originalConnectorCategories ]); + }, [ filterRoutes, state.isAuthenticated, isFirstLevelOrg ]); /** * Set the value of Session Timed Out. @@ -318,200 +287,198 @@ export const App: FunctionComponent> = (): ReactElement => return (
- - links={ DocumentationLinks }> - }> - - links={ DocumentationLinks }> + }> + + + When you click on the Go back button, we + will try to recover the session if it exists. If you + don't have an active session, you will be + redirected to the login page + + ), + headingI18nKey: "console:common.modals.sessionTimeoutModal" + + ".heading", + loginAgainButtonText: ( + + Login again + + ), + primaryButtonText: ( + + Go back + + ), + secondaryButtonText: ( + + Logout + + ), + sessionTimedOutDescription: ( + + Please log in again to continue from where you left off. + + ), + sessionTimedOutHeadingI18nKey: "console:common.modals" + + ".sessionTimeoutModal.sessionTimedOutHeading" + } } + type={ SessionTimeoutModalTypes.DEFAULT } + > + <> + + { appTitle } + { + (window?.themeHash && window?.publicPath && theme) + ? ( + + ) + : null + } + + + Your session has expired + ) + } + description={ + ( + Please try signing in again. + ) + } + primaryActionText={ + ( - When you click on the Go back button, we - will try to recover the session if it exists. If you - don't have an active session, you will be - redirected to the login page - - ), - headingI18nKey: "console:common.modals.sessionTimeoutModal" + - ".heading", - loginAgainButtonText: ( - ) + } + primaryAction={ + signOut + } + /> + - Login again - - ), - primaryButtonText: ( - - Go back - - ), - secondaryButtonText: ( - + Something went wrong + ) + } + description={ + ( - Logout - - ), - sessionTimedOutDescription: ( - + An error occurred when serving the requested + application. Please try reloading the app. + ) + } + primaryActionText={ + ( - Please log in again to continue from where you left off. - - ), - sessionTimedOutHeadingI18nKey: "console:common.modals" + - ".sessionTimeoutModal.sessionTimedOutHeading" - } } - type={ SessionTimeoutModalTypes.DEFAULT } - > - <> - - { appTitle } - { - (window?.themeHash && window?.publicPath && theme) - ? ( - - ) - : null - } - - - Your session has expired - ) - } - description={ - ( - Please try signing in again. - ) - } - primaryActionText={ - ( - Sign In - ) - } - primaryAction={ - signOut - } - /> - - Something went wrong - ) - } - description={ - ( - An error occurred when serving the requested - application. Please try reloading the app. - ) - } - primaryActionText={ - ( - Reload the App - ) - } + "common:chunkLoadErrorMessage.primaryActionText" + } + > + Reload the App + ) + } + /> + + - - - { - baseRoutes.map((route: RouteInterface, index: number) => { - return ( - route.protected ? - ( - - ) - : - ( - ) => { - return (); - } + { + baseRoutes.map((route: RouteInterface, index: number) => { + return ( + route.protected ? + ( + + ) + : + ( + ) => { + return (); } - key={ index } - exact={ route.exact } - /> - ) - ); - }) - } - - - - - - - + } + key={ index } + exact={ route.exact } + /> + ) + ); + }) + } + + + + + +
); diff --git a/modules/react-components/src/providers/governance-connector/governance-connector-context.tsx b/modules/react-components/src/providers/governance-connector/governance-connector-context.tsx deleted file mode 100644 index 9aa18dbba34..00000000000 --- a/modules/react-components/src/providers/governance-connector/governance-connector-context.tsx +++ /dev/null @@ -1,22 +0,0 @@ -/** - * Copyright (c) 2023, WSO2 LLC. (https://www.wso2.com). - * - * WSO2 LLC. licenses this file to you under the Apache License, - * Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. - * You may obtain a copy of the License at - * - * http://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. - */ - -import { Context, createContext } from "react"; -import { GovernanceCategoryForOrgsInterface } from "./models/governance-connector"; - -export const GovernanceConnectorContext: Context = createContext(null); diff --git a/modules/react-components/src/providers/governance-connector/governance-connector-provider.tsx b/modules/react-components/src/providers/governance-connector/governance-connector-provider.tsx deleted file mode 100644 index f5b17090418..00000000000 --- a/modules/react-components/src/providers/governance-connector/governance-connector-provider.tsx +++ /dev/null @@ -1,56 +0,0 @@ -/** - * Copyright (c) 2023, WSO2 LLC. (https://www.wso2.com). - * - * WSO2 LLC. licenses this file to you under the Apache License, - * Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. - * You may obtain a copy of the License at - * - * http://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. - */ - -import React, { PropsWithChildren, ReactElement } from "react"; -import { GovernanceConnectorContext } from "./governance-connector-context"; -import { GovernanceCategoryForOrgsInterface } from "./models/governance-connector"; - -/** - * Documentation provider props interface. - */ -interface GovernanceConnectorProviderPropsInterface { - /** - * Initial reducer state. - */ - connectorCategories?: GovernanceCategoryForOrgsInterface[]; -} - -/** - * GovernanceConnectorContext Provider. - * - * @param props - Wrap content/elements. - * @returns GovernanceConnectorContext Provider. - */ -export const GovernanceConnectorProvider = ( - props: PropsWithChildren -): ReactElement => { - - const { - children, - connectorCategories - } = props; - - /** - * Render state, dispatch and special case actions. - */ - return ( - - { children } - - ); -}; diff --git a/modules/react-components/src/providers/governance-connector/index.ts b/modules/react-components/src/providers/governance-connector/index.ts deleted file mode 100644 index fe18eb07763..00000000000 --- a/modules/react-components/src/providers/governance-connector/index.ts +++ /dev/null @@ -1,20 +0,0 @@ -/** - * Copyright (c) 2023, WSO2 LLC. (https://www.wso2.com). - * - * WSO2 LLC. licenses this file to you under the Apache License, - * Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. - * You may obtain a copy of the License at - * - * http://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. - */ - -export * from "./governance-connector-provider"; -export * from "./use-governance-connector"; diff --git a/modules/react-components/src/providers/governance-connector/models/governance-connector.ts b/modules/react-components/src/providers/governance-connector/models/governance-connector.ts deleted file mode 100644 index ab2cfff25ee..00000000000 --- a/modules/react-components/src/providers/governance-connector/models/governance-connector.ts +++ /dev/null @@ -1,30 +0,0 @@ -/** - * Copyright (c) 2023, WSO2 LLC. (https://www.wso2.com). - * - * WSO2 LLC. licenses this file to you under the Apache License, - * Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. - * You may obtain a copy of the License at - * - * http://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. - */ - -export interface GovernanceCategoryForOrgsInterface { - connectors: GovernanceConnectorForOrgsInterface[], - id: string, - name: string -} - -export interface GovernanceConnectorForOrgsInterface { - friendlyName: string, - id: string, - name: string, - properties: string[] -} diff --git a/modules/react-components/src/providers/governance-connector/use-governance-connector.tsx b/modules/react-components/src/providers/governance-connector/use-governance-connector.tsx deleted file mode 100644 index 7f80ceb6a54..00000000000 --- a/modules/react-components/src/providers/governance-connector/use-governance-connector.tsx +++ /dev/null @@ -1,31 +0,0 @@ -/** - * Copyright (c) 2023, WSO2 LLC. (https://www.wso2.com). - * - * WSO2 LLC. licenses this file to you under the Apache License, - * Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. - * You may obtain a copy of the License at - * - * http://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. - */ - -import { useContext } from "react"; -import { GovernanceConnectorContext } from "./governance-connector-context"; -import { GovernanceCategoryForOrgsInterface } from "./models/governance-connector"; - -/** - * Provides GovernanceConnector links as context - */ -export const useGovernanceConnector = (): GovernanceCategoryForOrgsInterface[] => { - - const categories = useContext(GovernanceConnectorContext); - - return { ...categories }; -}; diff --git a/modules/react-components/src/providers/index.ts b/modules/react-components/src/providers/index.ts index fcf86ed3534..f9c5cc41b7b 100644 --- a/modules/react-components/src/providers/index.ts +++ b/modules/react-components/src/providers/index.ts @@ -1,5 +1,5 @@ /** - * Copyright (c) 2020-2023, WSO2 LLC. (https://www.wso2.com). + * Copyright (c) 2020-2024, WSO2 LLC. (https://www.wso2.com). * * WSO2 LLC. licenses this file to you under the Apache License, * Version 2.0 (the "License"); you may not use this file except @@ -16,5 +16,4 @@ * under the License. */ -export * from "./governance-connector"; export * from "./session-management"; From 9c8e495d627d57a8ed207927d18dec1f8469d0ea Mon Sep 17 00:00:00 2001 From: DonOmalVindula Date: Fri, 19 Apr 2024 12:22:28 +0530 Subject: [PATCH 2/3] Move access control provider to app.tsx --- apps/console/src/app.tsx | 436 ++++++++++++++++------------- apps/console/src/protected-app.tsx | 102 ++----- 2 files changed, 266 insertions(+), 272 deletions(-) diff --git a/apps/console/src/app.tsx b/apps/console/src/app.tsx index 96f2ca3fb94..96582406b64 100755 --- a/apps/console/src/app.tsx +++ b/apps/console/src/app.tsx @@ -1,5 +1,5 @@ /** - * Copyright (c) 2023, WSO2 LLC. (https://www.wso2.com). + * Copyright (c) 2023-2024, WSO2 LLC. (https://www.wso2.com). * * WSO2 LLC. licenses this file to you under the Apache License, * Version 2.0 (the "License"); you may not use this file except @@ -17,26 +17,31 @@ */ import { BasicUserInfo, DecodedIDTokenPayload, useAuthContext } from "@asgardeo/auth-react"; +import { AccessControlProvider, AllFeatureInterface, FeatureGateInterface } from "@wso2is/access-control"; import { AppConstants as CommonAppConstants } from "@wso2is/core/constants"; +import { IdentityAppsApiException } from "@wso2is/core/exceptions"; import { CommonHelpers, isPortalAccessGranted } from "@wso2is/core/helpers"; import { RouteInterface, StorageIdentityAppsSettingsInterface, emptyIdentityAppsSettings } from "@wso2is/core/models"; import { setI18nConfigs, setServiceResourceEndpoints } from "@wso2is/core/store"; import { AuthenticateUtils, LocalStorageUtils } from "@wso2is/core/utils"; +import useAuthorization from "@wso2is/features/admin.authorization.v1/hooks/use-authorization"; import { EventPublisher, PreLoader } from "@wso2is/features/admin.core.v1"; import { ProtectedRoute } from "@wso2is/features/admin.core.v1/components"; import { Config, DocumentationLinks, getBaseRoutes } from "@wso2is/features/admin.core.v1/configs"; import { AppConstants } from "@wso2is/features/admin.core.v1/constants"; import { history } from "@wso2is/features/admin.core.v1/helpers"; import useResourceEndpoints from "@wso2is/features/admin.core.v1/hooks/use-resource-endpoints"; -import useRoutes from "@wso2is/features/admin.core.v1/hooks/use-routes"; import { ConfigReducerStateInterface, DocumentationLinksInterface, FeatureConfigInterface, ServiceResourceEndpointsInterface } from "@wso2is/features/admin.core.v1/models"; -import { AppState } from "@wso2is/features/admin.core.v1/store"; +import { AppState, store } from "@wso2is/features/admin.core.v1/store"; import { commonConfig } from "@wso2is/features/admin.extensions.v1"; +import { useGetAllFeatures } from "@wso2is/features/admin.extensions.v1/components/feature-gate/api/feature-gate"; +import { featureGateConfig } from "@wso2is/features/admin.extensions.v1/configs/feature-gate"; +import { OrganizationUtils } from "@wso2is/features/admin.organizations.v1/utils"; import { I18nModuleOptionsInterface } from "@wso2is/i18n"; import { ChunkErrorModal, @@ -49,6 +54,7 @@ import { } from "@wso2is/react-components"; import has from "lodash-es/has"; import isEmpty from "lodash-es/isEmpty"; +import set from "lodash-es/set"; import * as moment from "moment"; import React, { FunctionComponent, ReactElement, Suspense, useEffect, useState } from "react"; import { Helmet } from "react-helmet"; @@ -66,15 +72,16 @@ import "moment/locale/fr"; * @returns App Root component. */ export const App: FunctionComponent> = (): ReactElement => { + const featureGateConfigUpdated : FeatureGateInterface = { ...featureGateConfig }; const dispatch: Dispatch = useDispatch(); - const { filterRoutes } = useRoutes(); - const eventPublisher: EventPublisher = EventPublisher.getInstance(); const { trySignInSilently, getDecodedIDToken, signOut, state } = useAuthContext(); + const { legacyAuthzRuntime } = useAuthorization(); + const { setResourceEndpoints } = useResourceEndpoints(); const userName: string = useSelector((state: AppState) => state.auth.username); @@ -84,14 +91,19 @@ export const App: FunctionComponent> = (): ReactElement => const appTitle: string = useSelector((state: AppState) => state?.config?.ui?.appTitle); const uuid: string = useSelector((state: AppState) => state.profile.profileInfo.id); const theme: string = useSelector((state: AppState) => state?.config?.ui?.theme?.name); - const isFirstLevelOrg: boolean = useSelector( - (state: AppState) => state.organization.isFirstLevelOrganization - ); const allowedScopes: string = useSelector((state: AppState) => state?.auth?.allowedScopes); + const organizationType: string = useSelector((state: AppState) => state?.organization?.organizationType); const [ baseRoutes, setBaseRoutes ] = useState(getBaseRoutes()); const [ sessionTimedOut, setSessionTimedOut ] = useState(false); - const [ routesFiltered, setRoutesFiltered ] = useState(false); + const [ orgId, setOrgId ] = useState(); + const [ featureGateConfigData, setFeatureGateConfigData ] = + useState(featureGateConfigUpdated); + + const { + data: allFeatures, + error: featureGateAPIException + } = useGetAllFeatures(orgId, state.isAuthenticated); /** * Set the deployment configs in redux state. @@ -209,12 +221,49 @@ export const App: FunctionComponent> = (): ReactElement => }, [ uuid ]); useEffect(() => { - if (!state.isAuthenticated) { + if(state.isAuthenticated) { + if (OrganizationUtils.isSuperOrganization(store.getState().organization.organization) + || store.getState().organization.isFirstLevelOrganization) { + getDecodedIDToken().then((response: DecodedIDTokenPayload)=>{ + const orgName: string = response.org_name; + // Set org_name instead of org_uuid as the API expects org_name + // as it resolves tenant uuid from it. + + setOrgId(orgName); + }); + } else { + // Set the sub org id to the current organization id. + setOrgId(store.getState().organization.organization.id); + } + } + }, [ state ]); + + useEffect(() => { + if (allFeatures instanceof IdentityAppsApiException || featureGateAPIException) { return; } - filterRoutes(() => setRoutesFiltered(true), isFirstLevelOrg); - }, [ filterRoutes, state.isAuthenticated, isFirstLevelOrg ]); + if (!allFeatures) { + return; + } + + if (allFeatures?.length > 0) { + allFeatures.forEach((feature: AllFeatureInterface )=> { + // converting the identifier to path. + const path: string = feature.featureIdentifier.replace(/-/g, "."); + // Obtain the status and set it to the feature gate config. + const featureStatusPath: string = `${ path }.status`; + + set(featureGateConfigUpdated,featureStatusPath, feature.featureStatus); + + const featureTagPath: string = `${ path }.tags`; + + set(featureGateConfigUpdated,featureTagPath, feature.featureTags); + + setFeatureGateConfigData(featureGateConfigUpdated); + }); + } + }, [ allFeatures ]); /** * Set the value of Session Timed Out. @@ -280,7 +329,7 @@ export const App: FunctionComponent> = (): ReactElement => }); }; - if (!routesFiltered || isEmpty(config?.deployment) || isEmpty(config?.endpoints)) { + if (isEmpty(config?.deployment) || isEmpty(config?.endpoints)) { return ; } @@ -290,192 +339,199 @@ export const App: FunctionComponent> = (): ReactElement => links={ DocumentationLinks }> }> - - When you click on the Go back button, we - will try to recover the session if it exists. If you - don't have an active session, you will be - redirected to the login page - - ), - headingI18nKey: "console:common.modals.sessionTimeoutModal" + - ".heading", - loginAgainButtonText: ( - - Login again - - ), - primaryButtonText: ( - - Go back - - ), - secondaryButtonText: ( - - Logout - - ), - sessionTimedOutDescription: ( - - Please log in again to continue from where you left off. - - ), - sessionTimedOutHeadingI18nKey: "console:common.modals" + - ".sessionTimeoutModal.sessionTimedOutHeading" - } } - type={ SessionTimeoutModalTypes.DEFAULT } + - <> - - { appTitle } - { - (window?.themeHash && window?.publicPath && theme) - ? ( - - ) - : null - } - - - Your session has expired - ) - } - description={ - ( - Please try signing in again. - ) - } - primaryActionText={ - ( - Sign In - ) - } - primaryAction={ - signOut - } - /> - Go back button, we + will try to recover the session if it exists. If you + don't have an active session, you will be + redirected to the login page + + ), + headingI18nKey: "console:common.modals.sessionTimeoutModal" + + ".heading", + loginAgainButtonText: ( + - Something went wrong - ) - } - description={ - ( + Login again + + ), + primaryButtonText: ( + - An error occurred when serving the requested - application. Please try reloading the app. - ) - } - primaryActionText={ - ( + Go back + + ), + secondaryButtonText: ( + - Reload the App - ) - } - /> - - + Logout + + ), + sessionTimedOutDescription: ( + + Please log in again to continue from where you left off. + + ), + sessionTimedOutHeadingI18nKey: "console:common.modals" + + ".sessionTimeoutModal.sessionTimedOutHeading" + } } + type={ SessionTimeoutModalTypes.DEFAULT } + > + <> + + { appTitle } + { + (window?.themeHash && window?.publicPath && theme) + ? ( + + ) + : null + } + + + Your session has expired + ) + } + description={ + ( + Please try signing in again. + ) + } + primaryActionText={ + ( + Sign In + ) + } + primaryAction={ + signOut + } /> - { - baseRoutes.map((route: RouteInterface, index: number) => { - return ( - route.protected ? - ( - - ) - : - ( - ) => { - return (); + + Something went wrong + ) + } + description={ + ( + An error occurred when serving the requested + application. Please try reloading the app. + ) + } + primaryActionText={ + ( + Reload the App + ) + } + /> + + + { + baseRoutes.map((route: RouteInterface, index: number) => { + return ( + route.protected ? + ( + + ) + : + ( + ) => { + return (); + } } - } - key={ index } - exact={ route.exact } - /> - ) - ); - }) - } - - - + key={ index } + exact={ route.exact } + /> + ) + ); + }) + } + + + + diff --git a/apps/console/src/protected-app.tsx b/apps/console/src/protected-app.tsx index be9f3b473e7..fb9b5f61a39 100644 --- a/apps/console/src/protected-app.tsx +++ b/apps/console/src/protected-app.tsx @@ -23,14 +23,8 @@ import { SecureApp, useAuthContext } from "@asgardeo/auth-react"; -import { - AccessControlProvider, - AllFeatureInterface, - FeatureGateInterface -} from "@wso2is/access-control"; import { AppConstants as CommonAppConstants } from "@wso2is/core/constants"; -import { IdentityAppsApiException } from "@wso2is/core/exceptions"; import { IdentifiableComponentInterface } from "@wso2is/core/models"; import { setDeploymentConfigs, @@ -43,7 +37,6 @@ import { StringUtils } from "@wso2is/core/utils"; import useSignIn from "@wso2is/features/admin.authentication.v1/hooks/use-sign-in"; -import useAuthorization from "@wso2is/features/admin.authorization.v1/hooks/use-authorization"; import { AppState, AppUtils, @@ -59,16 +52,14 @@ import { } from "@wso2is/features/admin.core.v1"; import { AppConstants } from "@wso2is/features/admin.core.v1/constants"; import { history } from "@wso2is/features/admin.core.v1/helpers"; +import useRoutes from "@wso2is/features/admin.core.v1/hooks/use-routes"; import useUIConfig from "@wso2is/features/admin.core.v1/hooks/use-ui-configs"; import { commonConfig } from "@wso2is/features/admin.extensions.v1"; -import { useGetAllFeatures } from "@wso2is/features/admin.extensions.v1/components/feature-gate/api/feature-gate"; import useTenantTier from "@wso2is/features/admin.extensions.v1/components/subscription/api/subscription"; import { TenantTier } from "@wso2is/features/admin.extensions.v1/components/subscription/models/subscription"; import { SubscriptionProvider } from "@wso2is/features/admin.extensions.v1/components/subscription/providers/subscription-provider"; -import { featureGateConfig } from "@wso2is/features/admin.extensions.v1/configs/feature-gate"; import useOrganizationSwitch from "@wso2is/features/admin.organizations.v1/hooks/use-organization-switch"; -import { OrganizationUtils } from "@wso2is/features/admin.organizations.v1/utils"; import { I18n, I18nInstanceInitException, @@ -78,7 +69,6 @@ import { } from "@wso2is/i18n"; import axios, { AxiosResponse } from "axios"; import has from "lodash-es/has"; -import set from "lodash-es/set"; import React, { FunctionComponent, LazyExoticComponent, @@ -101,12 +91,10 @@ type AppPropsInterface = IdentifiableComponentInterface; * @returns ProtectedApp component (React Element) */ export const ProtectedApp: FunctionComponent = (): ReactElement => { - const featureGateConfigUpdated : FeatureGateInterface = { ...featureGateConfig }; const { on, signIn, - getDecodedIDToken, state } = useAuthContext(); @@ -116,24 +104,18 @@ export const ProtectedApp: FunctionComponent = (): ReactEleme const { switchOrganization } = useOrganizationSwitch(); - const { legacyAuthzRuntime } = useAuthorization(); - const { setUIConfig } = useUIConfig(); const { data: tenantTier } = useTenantTier(); - const organizationType: string = useSelector((state: AppState) => state?.organization?.organizationType); - const allowedScopes: string = useSelector((state: AppState) => state?.auth?.allowedScopes); + const { filterRoutes } = useRoutes(); - const [ featureGateConfigData, setFeatureGateConfigData ] = - useState(featureGateConfigUpdated); - const [ renderApp, setRenderApp ] = useState(false); - const [ orgId, setOrgId ] = useState(); + const isFirstLevelOrg: boolean = useSelector( + (state: AppState) => state.organization.isFirstLevelOrganization + ); - const { - data: allFeatures, - error: featureGateAPIException - } = useGetAllFeatures(orgId, state.isAuthenticated); + const [ renderApp, setRenderApp ] = useState(false); + const [ routesFiltered, setRoutesFiltered ] = useState(false); useEffect(() => { dispatch( @@ -193,51 +175,6 @@ export const ProtectedApp: FunctionComponent = (): ReactEleme }); }, []); - useEffect(() => { - if (allFeatures instanceof IdentityAppsApiException || featureGateAPIException) { - return; - } - - if (!allFeatures) { - return; - } - - if (allFeatures?.length > 0) { - allFeatures.forEach((feature: AllFeatureInterface )=> { - // converting the identifier to path. - const path: string = feature.featureIdentifier.replace(/-/g, "."); - // Obtain the status and set it to the feature gate config. - const featureStatusPath: string = `${ path }.status`; - - set(featureGateConfigUpdated,featureStatusPath, feature.featureStatus); - - const featureTagPath: string = `${ path }.tags`; - - set(featureGateConfigUpdated,featureTagPath, feature.featureTags); - - setFeatureGateConfigData(featureGateConfigUpdated); - }); - } - }, [ allFeatures ]); - - useEffect(() => { - if(state.isAuthenticated) { - if (OrganizationUtils.isSuperOrganization(store.getState().organization.organization) - || store.getState().organization.isFirstLevelOrganization) { - getDecodedIDToken().then((response: DecodedIDTokenPayload)=>{ - const orgName: string = response.org_name; - // Set org_name instead of org_uuid as the API expects org_name - // as it resolves tenant uuid from it. - - setOrgId(orgName); - }); - } else { - // Set the sub org id to the current organization id. - setOrgId(store.getState().organization.organization.id); - } - } - }, [ state ]); - const loginSuccessRedirect = (idToken: DecodedIDTokenPayload): void => { const AuthenticationCallbackUrl: string = CommonAuthenticateUtils.getAuthenticationCallbackUrl( CommonAppConstants.CONSOLE_APP @@ -392,6 +329,14 @@ export const ProtectedApp: FunctionComponent = (): ReactEleme }); }, [ state.isAuthenticated ]); + useEffect(() => { + if (!state.isAuthenticated) { + return; + } + + filterRoutes(() => setRoutesFiltered(true), isFirstLevelOrg); + }, [ filterRoutes, state.isAuthenticated, isFirstLevelOrg ]); + return ( } @@ -405,18 +350,11 @@ export const ProtectedApp: FunctionComponent = (): ReactEleme } } } > - - - - { renderApp ? : } - - - + + + { renderApp && routesFiltered ? : } + + ); }; From 3232ccf4bc21487a97fd6fc7cb8071d9f92bbf6c Mon Sep 17 00:00:00 2001 From: DonOmalVindula Date: Fri, 19 Apr 2024 12:27:46 +0530 Subject: [PATCH 3/3] Add changeset --- .changeset/eight-monkeys-learn.md | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 .changeset/eight-monkeys-learn.md diff --git a/.changeset/eight-monkeys-learn.md b/.changeset/eight-monkeys-learn.md new file mode 100644 index 00000000000..0a4e85e4b3e --- /dev/null +++ b/.changeset/eight-monkeys-learn.md @@ -0,0 +1,6 @@ +--- +"@wso2is/react-components": patch +"@wso2is/console": patch +--- + +Remove governance connector provider