From 83281b7669546f09da60df5a99b4bfbe902f749b Mon Sep 17 00:00:00 2001 From: Pavindu Lakshan Date: Mon, 30 Sep 2024 13:33:15 +0530 Subject: [PATCH 1/2] Fix administrators not being able to edit and delete B2B organizations --- .../components/organization-list.tsx | 41 ++++--------------- 1 file changed, 8 insertions(+), 33 deletions(-) diff --git a/features/admin.organizations.v1/components/organization-list.tsx b/features/admin.organizations.v1/components/organization-list.tsx index 1a35bf5a96c..62c899ef1d6 100644 --- a/features/admin.organizations.v1/components/organization-list.tsx +++ b/features/admin.organizations.v1/components/organization-list.tsx @@ -167,6 +167,8 @@ export const OrganizationList: FunctionComponent const featureConfig: FeatureConfigInterface = useSelector((state: AppState) => state.config.ui.features); const hasOrganizationUpdatePermissions: boolean = useRequiredScopes(featureConfig?.organizations?.scopes?.update); + const hasOrganizationDeletePermissions: boolean = useRequiredScopes(featureConfig?.organizations?.scopes?.delete); + const [ showDeleteConfirmationModal, setShowDeleteConfirmationModal ] = useState(false); const [ deletingOrganization, setDeletingOrganization ] = useState(undefined); @@ -426,33 +428,15 @@ export const OrganizationList: FunctionComponent featureConfig?.organizations, OrganizationManagementConstants.FEATURE_DICTIONARY.get("ORGANIZATION_UPDATE") ), - icon: (organization: OrganizationInterface): SemanticICONS => { - - let isAuthorized: boolean = false; - - authorizedList?.organizations?.map((org: OrganizationInterface) => { - if (org.id === organization.id) { - isAuthorized = true; - } - }); - - return !hasOrganizationUpdatePermissions || !isAuthorized + icon: (_organization: OrganizationInterface): SemanticICONS => { + return !hasOrganizationUpdatePermissions ? "eye" : "pencil alternate"; }, onClick: (e: SyntheticEvent, organization: OrganizationInterface): void => handleOrganizationEdit(organization.id), - popupText: (organization: OrganizationInterface ): string => { - - let isAuthorized: boolean = false; - - authorizedList?.organizations?.map((org: OrganizationInterface) => { - if (org.id === organization.id) { - isAuthorized = true; - } - }); - - return !hasOrganizationUpdatePermissions || !isAuthorized + popupText: (_organization: OrganizationInterface ): string => { + return !hasOrganizationUpdatePermissions ? t("common:view") : t("common:edit"); }, @@ -460,17 +444,8 @@ export const OrganizationList: FunctionComponent }, { "data-componentid": `${ componentId }-item-delete-button`, - hidden: (organization: OrganizationInterface): boolean => { - - let isAuthorized: boolean = false; - - authorizedList?.organizations?.map((org: OrganizationInterface) => { - if (org.id === organization.id) { - isAuthorized = true; - } - }); - - return !hasOrganizationUpdatePermissions || !isAuthorized; + hidden: (_organization: OrganizationInterface): boolean => { + return !hasOrganizationDeletePermissions; }, icon: (): SemanticICONS => "trash alternate", onClick: (e: SyntheticEvent, organization: OrganizationInterface): void => { From 711a03040914f2a76d81cb11a06c6c99d50d2cf7 Mon Sep 17 00:00:00 2001 From: Pavindu Lakshan Date: Mon, 30 Sep 2024 13:34:21 +0530 Subject: [PATCH 2/2] =?UTF-8?q?=F0=9F=A6=8B=20Add=20changeset?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .changeset/pink-pets-worry.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/pink-pets-worry.md diff --git a/.changeset/pink-pets-worry.md b/.changeset/pink-pets-worry.md new file mode 100644 index 00000000000..c023661951b --- /dev/null +++ b/.changeset/pink-pets-worry.md @@ -0,0 +1,5 @@ +--- +"@wso2is/admin.organizations.v1": patch +--- + +Use scopes to determine whether an admin is able to edit/delete suborganization