Skip to content

Commit

Permalink
Merge pull request #6463 from dasuni-30/fix/24946
Browse files Browse the repository at this point in the history
Fix something went wrong error in admin section
  • Loading branch information
dasuni-30 authored Jun 24, 2024
2 parents 5ef31d5 + 7da7100 commit 40bcfee
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 36 deletions.
5 changes: 5 additions & 0 deletions .changeset/sixty-buttons-enjoy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@wso2is/admin.extensions.v1": patch
---

Fix something went wrong error in admins section
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -261,6 +262,12 @@ const CollaboratorsPage: FunctionComponent<CollaboratorsPageInterface> = (
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
Expand Down Expand Up @@ -295,7 +302,7 @@ const CollaboratorsPage: FunctionComponent<CollaboratorsPageInterface> = (
setInvitationStatusOption(InvitationStatus.ACCEPTED);
setIsInvitationStatusOptionChanged(true);
};
}, []);
}, [ consoleId ]);

useEffect(() => {
setIsEnterpriseLoginEnabled(OrganizationConfig?.isEnterpriseLoginEnabled);
Expand Down Expand Up @@ -745,46 +752,49 @@ const CollaboratorsPage: FunctionComponent<CollaboratorsPageInterface> = (
* 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")
}));
});
}));
});
}
};

/**
Expand Down

0 comments on commit 40bcfee

Please sign in to comment.