Skip to content

Commit

Permalink
Merge pull request #6941 from pavinduLakshan/fix_admins_org_modify
Browse files Browse the repository at this point in the history
  • Loading branch information
pavinduLakshan authored Sep 30, 2024
2 parents 3401eb8 + 711a030 commit d78ad1e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 33 deletions.
5 changes: 5 additions & 0 deletions .changeset/pink-pets-worry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@wso2is/admin.organizations.v1": patch
---

Use scopes to determine whether an admin is able to edit/delete suborganization
41 changes: 8 additions & 33 deletions features/admin.organizations.v1/components/organization-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,8 @@ export const OrganizationList: FunctionComponent<OrganizationListPropsInterface>
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<boolean>(false);
const [ deletingOrganization, setDeletingOrganization ] = useState<OrganizationInterface>(undefined);

Expand Down Expand Up @@ -426,51 +428,24 @@ export const OrganizationList: FunctionComponent<OrganizationListPropsInterface>
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");
},
renderer: "semantic-icon"
},
{
"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 => {
Expand Down

0 comments on commit d78ad1e

Please sign in to comment.