Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable the role basics update and role permissions update for sub organization roles #7415

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/wet-mice-attend.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@wso2is/admin.roles.v2": patch
---

enable role basic update and role permission update in sub org roles
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ import { useAPIResources } from "@wso2is/admin.api-resources.v2/api";
import { useGetAuthorizedAPIList } from "@wso2is/admin.api-resources.v2/api/useGetAuthorizedAPIList";
import { APIResourceCategories, APIResourcesConstants } from "@wso2is/admin.api-resources.v2/constants";
import { APIResourceUtils } from "@wso2is/admin.api-resources.v2/utils/api-resource-utils";
import { useGetCurrentOrganizationType } from "@wso2is/admin.organizations.v1/hooks/use-get-organization-type";
import {
AlertInterface,
AlertLevels,
IdentifiableComponentInterface,
LinkInterface,
RolePermissionInterface,
RolePropertyInterface,
RolesInterface
} from "@wso2is/core/models";
import { addAlert } from "@wso2is/core/store";
Expand All @@ -44,6 +44,7 @@ import React, {
ReactNode,
SyntheticEvent,
useEffect,
useMemo,
useState
} from "react";
import { useTranslation } from "react-i18next";
Expand All @@ -53,7 +54,7 @@ import { DropdownItemProps, DropdownProps } from "semantic-ui-react";
import { RenderChip } from "./edit-role-common/render-chip";
import { RoleAPIResourcesListItem } from "./edit-role-common/role-api-resources-list-item";
import { getAPIResourceDetailsBulk, updateRoleDetails, useAPIResourceDetails } from "../../api";
import { RoleAudienceTypes } from "../../constants/role-constants";
import { RoleAudienceTypes, RoleConstants } from "../../constants/role-constants";
import { APIResourceInterface, AuthorizedAPIListItemInterface, ScopeInterface } from "../../models/apiResources";
import { PatchRoleDataInterface, PermissionUpdateInterface, SelectedPermissionsInterface } from "../../models/roles";

Expand Down Expand Up @@ -95,7 +96,6 @@ export const UpdatedRolePermissionDetails: FunctionComponent<RolePermissionDetai

const { t } = useTranslation();
const dispatch: Dispatch = useDispatch();
const { isSubOrganization } = useGetCurrentOrganizationType();

const [ isSubmitting, setIsSubmitting ] = useState<boolean>(false);
const [ selectedAPIResourceId, setSelectedAPIResourceId ] = useState<string>(undefined);
Expand All @@ -108,8 +108,11 @@ export const UpdatedRolePermissionDetails: FunctionComponent<RolePermissionDetai
const [ allAPIResourcesListData, setAllAPIResourcesListData ] = useState<APIResourceInterface[]>([]);
const [ apiCallNextAfterValue, setAPICallNextAfterValue ] = useState<string>(null);

const isSharedRole: boolean = useMemo(() => role?.properties?.some(
(property: RolePropertyInterface) =>
property?.name === RoleConstants.IS_SHARED_ROLE && property?.value === "true"), [ role ]);
const shouldFetchAPIResources: boolean = role?.audience?.type?.
toUpperCase() === RoleAudienceTypes.ORGANIZATION && !isSubOrganization();
toUpperCase() === RoleAudienceTypes.ORGANIZATION && !isSharedRole;

const {
data: currentAPIResourcesListData,
Expand Down
19 changes: 11 additions & 8 deletions features/admin.roles.v2/components/edit-role/edit-role.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,17 @@
* under the License.
*/

import { OrganizationType } from "@wso2is/admin.core.v1/constants/organization-constants";
import { FeatureConfigInterface } from "@wso2is/admin.core.v1/models/config";
import { AppState } from "@wso2is/admin.core.v1/store";
import { useGetCurrentOrganizationType } from "@wso2is/admin.organizations.v1/hooks/use-get-organization-type";
import { UserManagementConstants } from "@wso2is/admin.users.v1/constants";
import { RoleConstants } from "@wso2is/core/constants";
import { hasRequiredScopes, isFeatureEnabled } from "@wso2is/core/helpers";

Check failure on line 23 in features/admin.roles.v2/components/edit-role/edit-role.tsx

View workflow job for this annotation

GitHub Actions / ⬣ ESLint (STATIC ANALYSIS) (lts/*, 8.7.4)

'hasRequiredScopes' import from '@wso2is/core/helpers' is restricted. Please use "import { useRequiredScopes } from '@wso2is/access-control'" instead. Refer documentation: https://github.com/wso2/identity-apps/blob/master/docs/write-code/PERFORMANCE.md#use-userequiredscopes-hook-instead-of-hasrequiredscopes-function
import { FeatureAccessConfigInterface, RolesInterface, SBACInterface } from "@wso2is/core/models";
import {
FeatureAccessConfigInterface,
RolePropertyInterface,
RolesInterface,
SBACInterface
} from "@wso2is/core/models";
import { ResourceTab, ResourceTabPaneInterface } from "@wso2is/react-components";
import React, { FunctionComponent, ReactElement, useEffect, useMemo, useState } from "react";
import { useTranslation } from "react-i18next";
Expand Down Expand Up @@ -71,7 +74,6 @@
} = props;

const { t } = useTranslation();
const { organizationType } = useGetCurrentOrganizationType();

const featureConfig: FeatureAccessConfigInterface = useSelector(
(state: AppState) => state?.config?.ui?.features?.userRoles);
Expand All @@ -83,6 +85,9 @@
const userRolesDisabledFeatures: string[] = useSelector((state: AppState) => {
return state.config.ui.features?.userRoles?.disabledFeatures;
});
const isSharedRole: boolean = useMemo(() => roleObject?.properties?.some(
(property: RolePropertyInterface) =>
property?.name === LocalRoleConstants.IS_SHARED_ROLE && property?.value === "true"), [ roleObject ]);

const isReadOnly: boolean = useMemo(() => {
return !isFeatureEnabled(featureConfig,
Expand All @@ -102,8 +107,6 @@
const [ isAdminRole, setIsAdminRole ] = useState<boolean>(false);
const [ isEveryoneRole, setIsEveryoneRole ] = useState<boolean>(false);

const isSubOrg: boolean = organizationType === OrganizationType.SUBORGANIZATION;

/**
* Set the if the role is `Internal/admin`.
*/
Expand All @@ -124,7 +127,7 @@
render: () => (
<ResourceTab.Pane controlledSegmentation attached={ false }>
<BasicRoleDetails
isReadOnly={ isSubOrg || isAdminRole || isEveryoneRole || isReadOnly }
isReadOnly={ isAdminRole || isEveryoneRole || isReadOnly || isSharedRole }
role={ roleObject }
onRoleUpdate={ onRoleUpdate }
tabIndex={ 0 }
Expand All @@ -137,7 +140,7 @@
render: () => (
<ResourceTab.Pane controlledSegmentation attached={ false }>
<UpdatedRolePermissionDetails
isReadOnly={ isSubOrg || isAdminRole || isReadOnly }
isReadOnly={ isAdminRole || isReadOnly || isSharedRole }
role={ roleObject }
onRoleUpdate={ onRoleUpdate }
tabIndex={ 1 }
Expand Down
Loading