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 diff --git a/apps/console/src/app.tsx b/apps/console/src/app.tsx index fb6eb276ae9..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,38 +17,36 @@ */ import { BasicUserInfo, DecodedIDTokenPayload, useAuthContext } from "@asgardeo/auth-react"; -import { useRequiredScopes } from "@wso2is/access-control"; +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 { - GovernanceCategoryForOrgsInterface, - useGovernanceConnectorCategories -} from "@wso2is/features/admin.server-configurations.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, Code, DocumentationProvider, - GovernanceConnectorProvider, MediaContextProvider, NetworkErrorModal, SessionManagementProvider, @@ -56,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"; @@ -73,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); @@ -91,28 +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 featureConfig: FeatureConfigInterface = useSelector( - (state: AppState) => state.config.ui.features - ); 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 [ governanceConnectors, setGovernanceConnectors ] = useState([]); - - const hasGovernanceConnectorsReadScope: boolean = useRequiredScopes( - featureConfig?.governanceConnectors?.scopes?.read); + const [ orgId, setOrgId ] = useState(); + const [ featureGateConfigData, setFeatureGateConfigData ] = + useState(featureGateConfigUpdated); const { - data: originalConnectorCategories, - error: connectorCategoriesFetchRequestError - } = useGovernanceConnectorCategories( - featureConfig?.server?.enabled && isFirstLevelOrg && - hasGovernanceConnectorsReadScope); + data: allFeatures, + error: featureGateAPIException + } = useGetAllFeatures(orgId, state.isAuthenticated); /** * Set the deployment configs in redux state. @@ -230,22 +221,49 @@ export const App: FunctionComponent> = (): ReactElement => }, [ uuid ]); useEffect(() => { - if (!state.isAuthenticated) { - return; + 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); + } } - - filterRoutes(() => setRoutesFiltered(true), isFirstLevelOrg); - }, [ filterRoutes, governanceConnectors, state.isAuthenticated, isFirstLevelOrg ]); + }, [ state ]); useEffect(() => { - if (!originalConnectorCategories || - originalConnectorCategories instanceof IdentityAppsApiException || - connectorCategoriesFetchRequestError) { + if (allFeatures instanceof IdentityAppsApiException || featureGateAPIException) { return; } - setGovernanceConnectors(originalConnectorCategories); - }, [ originalConnectorCategories ]); + 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. @@ -311,17 +329,22 @@ export const App: FunctionComponent> = (): ReactElement => }); }; - if (!routesFiltered || isEmpty(config?.deployment) || isEmpty(config?.endpoints)) { + if (isEmpty(config?.deployment) || isEmpty(config?.endpoints)) { return ; } return (
- - links={ DocumentationLinks }> - }> - + links={ DocumentationLinks }> + }> + + > = (): ReactElement => - - - - + + + +
); 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 ? : } + + ); }; 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";