diff --git a/.changeset/sixty-buttons-enjoy.md b/.changeset/sixty-buttons-enjoy.md new file mode 100644 index 00000000000..35ec7278a45 --- /dev/null +++ b/.changeset/sixty-buttons-enjoy.md @@ -0,0 +1,5 @@ +--- +"@wso2is/admin.extensions.v1": patch +--- + +Fix something went wrong error in admins section diff --git a/features/admin.extensions.v1/components/administrators/pages/administrators.tsx b/features/admin.extensions.v1/components/administrators/pages/administrators.tsx index 9bf697c1e41..ba81dea4f72 100644 --- a/features/admin.extensions.v1/components/administrators/pages/administrators.tsx +++ b/features/admin.extensions.v1/components/administrators/pages/administrators.tsx @@ -17,6 +17,7 @@ */ import { FeatureStatus, Show, useCheckFeatureStatus } from "@wso2is/access-control"; +import { useApplicationList } from "@wso2is/admin.applications.v1/api"; import useAuthorization from "@wso2is/admin.authorization.v1/hooks/use-authorization"; import { AdvancedSearchWithBasicFilters, @@ -261,6 +262,12 @@ const CollaboratorsPage: FunctionComponent = ( administratorConfig.enableAdminInvite ); + const { data: consoleApplicationFilter } = useApplicationList(null, null, null, "name eq Console"); + + const consoleId: string = useMemo(() => ( + consoleApplicationFilter?.applications[0]?.id + ), [ consoleApplicationFilter ]); + const { data: serverConfigs, error: serverConfigsFetchRequestError @@ -295,7 +302,7 @@ const CollaboratorsPage: FunctionComponent = ( setInvitationStatusOption(InvitationStatus.ACCEPTED); setIsInvitationStatusOptionChanged(true); }; - }, []); + }, [ consoleId ]); useEffect(() => { setIsEnterpriseLoginEnabled(OrganizationConfig?.isEnterpriseLoginEnabled); @@ -745,46 +752,49 @@ const CollaboratorsPage: FunctionComponent = ( * Fetches the admin role id from database. */ const getAdminRoleId = () => { - const searchData:SearchRoleInterface = { - filter: "displayName eq " + administratorConfig.adminRoleName, - schemas: [ "urn:ietf:params:scim:api:messages:2.0:SearchRequest" ], - startIndex: 0 - }; - - searchRoleList(searchData) - .then((response: AxiosResponse) => { - if (response?.data?.Resources.length > 0) { - let adminId: string = response?.data?.Resources[0]?.id; - - if (!legacyAuthzRuntime && response?.data?.Resources?.length > 1) { - const filteredRoleList: RolesV2Interface[] = response?.data?.Resources?.filter( - (role: RolesV2Interface) => role?.audience?.type === RoleAudienceTypes.APPLICATION); - - if (filteredRoleList?.length > 0) { - adminId = filteredRoleList[0]?.id; + if (consoleId) { + const searchData:SearchRoleInterface = { + filter: "displayName eq " + administratorConfig.adminRoleName + + " and audience.value eq " + consoleId, + schemas: [ "urn:ietf:params:scim:api:messages:2.0:SearchRequest" ], + startIndex: 0 + }; + + searchRoleList(searchData) + .then((response: AxiosResponse) => { + if (response?.data?.Resources.length > 0) { + let adminId: string = response?.data?.Resources[0]?.id; + + if (!legacyAuthzRuntime && response?.data?.Resources?.length > 1) { + const filteredRoleList: RolesV2Interface[] = response?.data?.Resources?.filter( + (role: RolesV2Interface) => role?.audience?.type === RoleAudienceTypes.APPLICATION); + + if (filteredRoleList?.length > 0) { + adminId = filteredRoleList[0]?.id; + } } - } - setAdminRoleId(adminId); - } - }).catch((error: IdentityAppsApiException) => { - if (error.response && error.response.data && error.response.data.description) { + setAdminRoleId(adminId); + } + }).catch((error: IdentityAppsApiException) => { + if (error.response && error.response.data && error.response.data.description) { + dispatch(addAlert({ + description: error.response.data.description, + level: AlertLevels.ERROR, + message: t("users:notifications.getAdminRole.error.message") + })); + + return; + } dispatch(addAlert({ - description: error.response.data.description, - level: AlertLevels.ERROR, - message: t("users:notifications.getAdminRole.error.message") - })); - - return; - } - dispatch(addAlert({ - description: t("users:notifications.getAdminRole." + + description: t("users:notifications.getAdminRole." + "genericError.description"), - level: AlertLevels.ERROR, - message: t("users:notifications.getAdminRole.genericError" + + level: AlertLevels.ERROR, + message: t("users:notifications.getAdminRole.genericError" + ".message") - })); - }); + })); + }); + } }; /**