From b07dfe43d2a9cec11d274fa75299da17f9e5b7c9 Mon Sep 17 00:00:00 2001 From: Brion Date: Tue, 27 Aug 2024 14:49:32 +0530 Subject: [PATCH 1/2] Remove `extensions/components/groups` stale folder --- .../api/application-roles.ts | 21 + .../components/application-roles-list.tsx | 2 +- .../components/roles-list.tsx | 2 +- .../models/application-roles.ts | 24 + .../pages/application-roles.tsx | 4 +- .../groups/api/application-roles.ts | 96 -- .../components/groups/api/index.ts | 19 - .../groups/constants/groups-constants.ts | 46 - .../components/groups/data/group.md | 9 - .../groups/edit-group/edit-group-basic.tsx | 441 ------- .../groups/edit-group/edit-group-roles.tsx | 1014 ----------------- .../groups/edit-group/edit-group-users.tsx | 866 -------------- .../groups/edit-group/edit-group.tsx | 251 ---- .../components/groups/edit-group/index.ts | 20 - .../components/groups/groups-list.tsx | 438 ------- .../components/groups/index.ts | 20 - .../groups/models/application-roles.ts | 41 - .../components/groups/models/index.ts | 19 - .../components/groups/pages/groups-edit.tsx | 133 --- .../components/groups/pages/groups.tsx | 555 --------- .../components/groups/pages/index.ts | 19 - .../components/groups/utils/group-utils.ts | 27 - .../groups/wizard/create-group-wizard.tsx | 585 ---------- .../groups/wizard/group-assign-users.tsx | 348 ------ .../components/groups/wizard/group-basics.tsx | 179 --- .../components/groups/wizard/index.ts | 20 - 26 files changed, 49 insertions(+), 5150 deletions(-) delete mode 100755 features/admin.extensions.v1/components/groups/api/application-roles.ts delete mode 100755 features/admin.extensions.v1/components/groups/api/index.ts delete mode 100644 features/admin.extensions.v1/components/groups/constants/groups-constants.ts delete mode 100644 features/admin.extensions.v1/components/groups/data/group.md delete mode 100644 features/admin.extensions.v1/components/groups/edit-group/edit-group-basic.tsx delete mode 100755 features/admin.extensions.v1/components/groups/edit-group/edit-group-roles.tsx delete mode 100644 features/admin.extensions.v1/components/groups/edit-group/edit-group-users.tsx delete mode 100644 features/admin.extensions.v1/components/groups/edit-group/edit-group.tsx delete mode 100644 features/admin.extensions.v1/components/groups/edit-group/index.ts delete mode 100644 features/admin.extensions.v1/components/groups/groups-list.tsx delete mode 100644 features/admin.extensions.v1/components/groups/index.ts delete mode 100755 features/admin.extensions.v1/components/groups/models/application-roles.ts delete mode 100755 features/admin.extensions.v1/components/groups/models/index.ts delete mode 100644 features/admin.extensions.v1/components/groups/pages/groups-edit.tsx delete mode 100644 features/admin.extensions.v1/components/groups/pages/groups.tsx delete mode 100644 features/admin.extensions.v1/components/groups/pages/index.ts delete mode 100644 features/admin.extensions.v1/components/groups/utils/group-utils.ts delete mode 100644 features/admin.extensions.v1/components/groups/wizard/create-group-wizard.tsx delete mode 100644 features/admin.extensions.v1/components/groups/wizard/group-assign-users.tsx delete mode 100644 features/admin.extensions.v1/components/groups/wizard/group-basics.tsx delete mode 100644 features/admin.extensions.v1/components/groups/wizard/index.ts diff --git a/features/admin.application-roles.v1/api/application-roles.ts b/features/admin.application-roles.v1/api/application-roles.ts index aad93b49234..fbabca075a0 100755 --- a/features/admin.application-roles.v1/api/application-roles.ts +++ b/features/admin.application-roles.v1/api/application-roles.ts @@ -28,6 +28,7 @@ import { AxiosError, AxiosRequestConfig, AxiosResponse } from "axios"; import { ApplicationRoleGroupsAPIResponseInterface, ApplicationRoleGroupsUpdatePayloadInterface, + ApplicationRoleInterface, ApplicationRolesResponseInterface, AuthorizedAPIListItemInterface, CreateRolePayloadInterface, @@ -443,3 +444,23 @@ export const useDescendantsOfSubOrg = => { + const requestConfig: AxiosRequestConfig = { + method: HttpMethods.GET, + url: `${ store.getState().config.endpoints.authzEndpoint }/roles` + }; + + return httpClient(requestConfig) + .then((response: AxiosResponse) => { + return Promise.resolve(response.data.app_roles as ApplicationRoleInterface[]); + }) + .catch((error: AxiosError) => { + return Promise.reject(error); + }); +}; diff --git a/features/admin.application-roles.v1/components/application-roles-list.tsx b/features/admin.application-roles.v1/components/application-roles-list.tsx index dc6954ed410..80467a576c8 100644 --- a/features/admin.application-roles.v1/components/application-roles-list.tsx +++ b/features/admin.application-roles.v1/components/application-roles-list.tsx @@ -17,7 +17,6 @@ */ import { AppConstants, getEmptyPlaceholderIllustrations, history } from "@wso2is/admin.core.v1"; -import { ApplicationRoleInterface } from "@wso2is/admin.extensions.v1/components/groups/models"; import { IdentifiableComponentInterface, LoadableComponentInterface @@ -33,6 +32,7 @@ import React, { Fragment, ReactElement, useState } from "react"; import { useTranslation } from "react-i18next"; import { Accordion, Grid } from "semantic-ui-react"; import RolesList from "./roles-list"; +import { ApplicationRoleInterface } from "../models/application-roles"; interface ApplicationRolesListProps extends LoadableComponentInterface, IdentifiableComponentInterface { /** diff --git a/features/admin.application-roles.v1/components/roles-list.tsx b/features/admin.application-roles.v1/components/roles-list.tsx index 9a10f76c02f..2d1cee29edc 100644 --- a/features/admin.application-roles.v1/components/roles-list.tsx +++ b/features/admin.application-roles.v1/components/roles-list.tsx @@ -18,7 +18,6 @@ import { history } from "@wso2is/admin.core.v1"; import { AppConstants, UIConstants } from "@wso2is/admin.core.v1/constants"; -import { RoleBasicInterface } from "@wso2is/admin.extensions.v1/components/groups/models"; import { IdentifiableComponentInterface } from "@wso2is/core/models"; import { DataTable, @@ -30,6 +29,7 @@ import { import React, { ChangeEvent, ReactElement, ReactNode, SyntheticEvent, useState } from "react"; import { useTranslation } from "react-i18next"; import { Grid, Header, Icon, Input, SemanticICONS } from "semantic-ui-react"; +import { RoleBasicInterface } from "../models/application-roles"; interface RolesListProps extends IdentifiableComponentInterface { rolesList: RoleBasicInterface[]; diff --git a/features/admin.application-roles.v1/models/application-roles.ts b/features/admin.application-roles.v1/models/application-roles.ts index 86be456216a..3139e3116a8 100644 --- a/features/admin.application-roles.v1/models/application-roles.ts +++ b/features/admin.application-roles.v1/models/application-roles.ts @@ -158,3 +158,27 @@ export interface DescendantDataInterface { id: string; name: string; } + +/** + * Interface to store basic role data. + */ +export interface RoleBasicInterface { + name: string; +} + +/** + * Interface to store application role data grouped by application. + */ +export interface ApplicationRoleInterface { + app: string; + appName?: string; + roles: RoleBasicInterface[]; +} + +/** + * Interface for group role assignment payload. + */ +export interface GroupRoleAssignPayloadInterface { + added_roles: ApplicationRoleInterface[]; + removed_roles: ApplicationRoleInterface[]; +} diff --git a/features/admin.application-roles.v1/pages/application-roles.tsx b/features/admin.application-roles.v1/pages/application-roles.tsx index 67bc75dc23d..3cfb86b1864 100644 --- a/features/admin.application-roles.v1/pages/application-roles.tsx +++ b/features/admin.application-roles.v1/pages/application-roles.tsx @@ -19,8 +19,6 @@ import { getApplicationList } from "@wso2is/admin.applications.v1/api"; import { ApplicationListInterface, ApplicationListItemInterface } from "@wso2is/admin.applications.v1/models"; import { AppConstants, UIConstants, getEmptyPlaceholderIllustrations, history } from "@wso2is/admin.core.v1"; -import { getAllApplicationRolesList } from "@wso2is/admin.extensions.v1/components/groups/api"; -import { ApplicationRoleInterface } from "@wso2is/admin.extensions.v1/components/groups/models"; import { AlertLevels, IdentifiableComponentInterface } from "@wso2is/core/models"; import { addAlert } from "@wso2is/core/store"; import { @@ -36,7 +34,9 @@ import { useTranslation } from "react-i18next"; import { useDispatch } from "react-redux"; import { Dispatch } from "redux"; import { Icon, Input } from "semantic-ui-react"; +import { getAllApplicationRolesList } from "../api/application-roles"; import { ApplicationRolesList } from "../components"; +import { ApplicationRoleInterface } from "../models/application-roles"; type ApplicationRolesPageInterface = IdentifiableComponentInterface; diff --git a/features/admin.extensions.v1/components/groups/api/application-roles.ts b/features/admin.extensions.v1/components/groups/api/application-roles.ts deleted file mode 100755 index fa5ba15feb7..00000000000 --- a/features/admin.extensions.v1/components/groups/api/application-roles.ts +++ /dev/null @@ -1,96 +0,0 @@ -/** - * Copyright (c) 2023, WSO2 LLC. (https://www.wso2.com). - * - * WSO2 LLC. licenses this file to you under the Apache License, - * Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import { AsgardeoSPAClient, HttpClientInstance } from "@asgardeo/auth-react"; -import { store } from "@wso2is/admin.core.v1"; -import { HttpMethods } from "@wso2is/core/models"; -import { AxiosError, AxiosRequestConfig, AxiosResponse } from "axios"; -import { ApplicationRoleInterface, GroupRoleAssignPayloadInterface } from "../models/application-roles"; - -/** - * Initialize an axios Http client. - */ -const httpClient: HttpClientInstance = AsgardeoSPAClient.getInstance() - .httpRequest.bind(AsgardeoSPAClient.getInstance()) - .bind(AsgardeoSPAClient.getInstance()); - -/** - * Get the application roles assigned to the group. - * - * @param group - Group name. - * - * @returns A promise containing the response. - */ -export const getAssignedApplicationRolesList = (group: string):Promise => { - const requestConfig: AxiosRequestConfig = { - method: HttpMethods.GET, - url: `${ store.getState().config.endpoints.authzEndpoint }/groups/${ group }/role-mapping` - }; - - return httpClient(requestConfig) - .then((response: AxiosResponse) => { - return Promise.resolve(response.data.app_roles as ApplicationRoleInterface[]); - }) - .catch((error: AxiosError) => { - return Promise.reject(error); - }); -}; - -/** - * Get all the application roles in the organization. - * - * @returns A promise containing the response. - */ -export const getAllApplicationRolesList = ():Promise => { - const requestConfig: AxiosRequestConfig = { - method: HttpMethods.GET, - url: `${ store.getState().config.endpoints.authzEndpoint }/roles` - }; - - return httpClient(requestConfig) - .then((response: AxiosResponse) => { - return Promise.resolve(response.data.app_roles as ApplicationRoleInterface[]); - }) - .catch((error: AxiosError) => { - return Promise.reject(error); - }); -}; - -/** - * Update the application roles assigned to the group. - * - * @param group - Group name. - * @param payload - Group role assign payload. - * - * @returns A promise containing the response. - */ -export const updateGroupRoleMapping = (group: string, payload: GroupRoleAssignPayloadInterface):Promise => { - const requestConfig: AxiosRequestConfig = { - data: payload, - method: HttpMethods.PATCH, - url: `${ store.getState().config.endpoints.authzEndpoint }/groups/${ group }/role-mapping` - }; - - return httpClient(requestConfig) - .then((response: AxiosResponse) => { - return Promise.resolve(response); - }) - .catch((error: AxiosError) => { - return Promise.reject(error); - }); -}; diff --git a/features/admin.extensions.v1/components/groups/api/index.ts b/features/admin.extensions.v1/components/groups/api/index.ts deleted file mode 100755 index 7fdfff2ab71..00000000000 --- a/features/admin.extensions.v1/components/groups/api/index.ts +++ /dev/null @@ -1,19 +0,0 @@ -/** - * Copyright (c) 2023, WSO2 LLC. (https://www.wso2.com). All Rights Reserved. - * - * WSO2 LLC. licenses this file to you under the Apache License, - * Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -export * from "./application-roles"; diff --git a/features/admin.extensions.v1/components/groups/constants/groups-constants.ts b/features/admin.extensions.v1/components/groups/constants/groups-constants.ts deleted file mode 100644 index f5c51653eb3..00000000000 --- a/features/admin.extensions.v1/components/groups/constants/groups-constants.ts +++ /dev/null @@ -1,46 +0,0 @@ -/** - * Copyright (c) 2023, WSO2 LLC. (https://www.wso2.com). - * - * WSO2 LLC. licenses this file to you under the Apache License, - * Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import { AppConstants } from "@wso2is/admin.core.v1"; - -/** - * Class containing Groups constants. - */ -export class GroupsConstants { - - /** - * Private constructor to avoid object instantiation from outside - * the class. - */ - private constructor() { } - - public static readonly APPLICATION_RESOURCE_DIR: string = "applications"; - - public static readonly DEBOUNCE_TIMEOUT: number = 1000; - - /** - * Get the paths necessary for the groups page. - * - * @returns `Map` - */ - public static getPaths(): Map { - - return new Map() - .set("APPLICATIONS", `${ AppConstants.getDeveloperViewBasePath() }/` + `${this.APPLICATION_RESOURCE_DIR}`); - } -} diff --git a/features/admin.extensions.v1/components/groups/data/group.md b/features/admin.extensions.v1/components/groups/data/group.md deleted file mode 100644 index 87f90e5d023..00000000000 --- a/features/admin.extensions.v1/components/groups/data/group.md +++ /dev/null @@ -1,9 +0,0 @@ -## Groups -A collection of users who are granted the same privileges in the system. By grouping users, developers can use this group attribute information to write logic in their business applications. - -**Note:** Only users can be assigned to a group. - -### Source -Where the groups' details are being managed. By default, there can be following sources. - -**Local/Consumer**: Default userstore where groups' details are being managed. diff --git a/features/admin.extensions.v1/components/groups/edit-group/edit-group-basic.tsx b/features/admin.extensions.v1/components/groups/edit-group/edit-group-basic.tsx deleted file mode 100644 index 42cb364c007..00000000000 --- a/features/admin.extensions.v1/components/groups/edit-group/edit-group-basic.tsx +++ /dev/null @@ -1,441 +0,0 @@ -/** - * Copyright (c) 2021-2024, WSO2 LLC. (https://www.wso2.com). - * - * WSO2 LLC. licenses this file to you under the Apache License, - * Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import { AppConstants, SharedUserStoreConstants, SharedUserStoreUtils, history } from "@wso2is/admin.core.v1"; -import { - GroupsInterface, - PatchGroupDataInterface, - SearchGroupInterface, - deleteGroupById, - searchGroupList, - updateGroupDetails -} from "@wso2is/admin.groups.v1"; -import { CONSUMER_USERSTORE } from "@wso2is/admin.userstores.v1/constants"; -import { - AlertInterface, - AlertLevels, - TestableComponentInterface -} from "@wso2is/core/models"; -import { addAlert } from "@wso2is/core/store"; -import { Field, FormValue, Forms, Validation } from "@wso2is/forms"; -import { - Code, - ConfirmationModal, - ContentLoader, - DangerZone, - DangerZoneGroup, - EmphasizedSegment, - Hint -} from "@wso2is/react-components"; -import React, { FunctionComponent, ReactElement, useEffect, useState } from "react"; -import { useTranslation } from "react-i18next"; -import { useDispatch } from "react-redux"; -import { Dispatch } from "redux"; -import { Button, Divider, Form, Grid } from "semantic-ui-react"; - -/** - * Interface to contain props needed for component - */ -interface BasicGroupProps extends TestableComponentInterface { - /** - * Group id. - */ - groupId: string; - /** - * Group details - */ - groupObject: GroupsInterface; - /** - * Show if it is group. - */ - isGroup: boolean; - /** - * Handle group update callback. - */ - onGroupUpdate: () => void; - /** - * Show if the user is read only. - */ - isReadOnly?: boolean; - /** - * Show if the userstore is a remote userstore. - */ - isUserstoreRemote?: boolean; - /** - * Enable group and groups separation. - */ - isGroupAndRoleSeparationEnabled?: boolean; - /** - * Show if the read only prop is loaded - */ - isReadOnlyLoading: boolean; -} - -/** - * Component to edit basic group details. - * - * @param props - Group object containing details which needs to be edited. - */ -export const BasicGroupDetails: FunctionComponent = (props: BasicGroupProps): ReactElement => { - const { t } = useTranslation(); - const dispatch: Dispatch = useDispatch(); - - const { - groupId, - groupObject, - onGroupUpdate, - isGroup, - isReadOnly, - isUserstoreRemote, - isReadOnlyLoading, - [ "data-testid" ]: testId - } = props; - - const [ showGroupDeleteConfirmation, setShowDeleteConfirmationModal ] = useState(false); - const [ labelText, setLableText ] = useState(""); - const [ nameValue, setNameValue ] = useState(""); - const [ isRegExLoading, setRegExLoading ] = useState(false); - const [ isSubmitting, setIsSubmitting ] = useState(false); - - useEffect(() => { - if (groupObject && groupObject.displayName.indexOf("/") !== -1) { - setNameValue(groupObject.displayName.split("/")[1]); - setLableText(groupObject.displayName.split("/")[0]); - } else if (groupObject) { - setNameValue(groupObject.displayName); - } - }, [ groupObject ]); - - /** - * Dispatches the alert object to the redux store. - * - * @param alert - Alert object. - */ - const handleAlerts = (alert: AlertInterface): void => { - dispatch(addAlert(alert)); - }; - - /** - * Function which will handle group deletion action. - * - * @param id - Group ID which needs to be deleted - */ - const handleOnDelete = (id: string): void => { - deleteGroupById(id).then(() => { - handleAlerts({ - description: t("console:manage.features.groups.notifications.deleteGroup.success.description"), - level: AlertLevels.SUCCESS, - message: t("console:manage.features.groups.notifications.deleteGroup.success.message") - }); - if (isGroup) { - history.push(AppConstants.getPaths().get("GROUPS")); - } else { - history.push(AppConstants.getPaths().get("ROLES")); - } - }); - }; - - /** - * The following function validates role name against the user store regEx. - * - */ - const validateGroupNamePattern = async (): Promise => { - let userStoreRegEx: string = ""; - - await SharedUserStoreUtils.getUserStoreRegEx(CONSUMER_USERSTORE, - SharedUserStoreConstants.USERSTORE_REGEX_PROPERTIES.RolenameRegEx) - .then((response: string) => { - setRegExLoading(true); - userStoreRegEx = response; - }); - - setRegExLoading(false); - - return new Promise((resolve: (value: string | PromiseLike) => void, - reject: (reason?: string) => void) => { - if (userStoreRegEx !== "") { - resolve(userStoreRegEx); - } else { - reject(""); - } - }); - - }; - - /** - * Method to update group name for the selected group. - * - */ - const updateGroupName = (values: Map): void => { - const newName: string = values?.get("groupName")?.toString(); - - const groupData: PatchGroupDataInterface = { - Operations: [ { - "op": "replace", - "path": "displayName", - "value": labelText ? labelText + "/" + newName : newName - } ], - schemas: [ "urn:ietf:params:scim:api:messages:2.0:PatchOp" ] - }; - - setIsSubmitting(true); - - updateGroupDetails(groupObject.id, groupData) - .then(() => { - onGroupUpdate(); - handleAlerts({ - description: t("console:manage.features.groups.notifications.updateGroup.success.description"), - level: AlertLevels.SUCCESS, - message: t("console:manage.features.groups.notifications.updateGroup.success.message") - }); - }).catch(() => { - handleAlerts({ - description: t("console:manage.features.groups.notifications.updateGroup.error.description"), - level: AlertLevels.ERROR, - message: t("console:manage.features.groups.notifications.updateGroup.error.message") - }); - }) - .finally(() => { - setIsSubmitting(false); - }); - }; - - return ( - <> - { !isReadOnlyLoading - ? ( - - ) => { - updateGroupName(values); - } } - > - - - - - - { - let isGroupNameValid: boolean = true; - - await validateGroupNamePattern().then((regex: string) => { - isGroupNameValid = - SharedUserStoreUtils.validateInputAgainstRegEx(value - , regex); - }); - - if (!isGroupNameValid) { - validation.isValid = false; - validation.errorMessages.push(t("console:manage.features." + - "businessGroups.fields.groupName." + - "validations.invalid", { type: "group" })); - } - - const searchData: SearchGroupInterface = { - filter: `displayName eq ${ CONSUMER_USERSTORE }/${ value }`, - schemas: [ - "urn:ietf:params:scim:api:messages:2.0:SearchRequest" - ], - startIndex: 1 - }; - - await searchGroupList(searchData).then((response: any) => { - if (response?.data?.totalResults !== 0) { - if (response.data.Resources[0]?.id !== groupId) { - validation.isValid = false; - validation.errorMessages.push( - t("roles:addRoleWizard." + - "forms.roleBasicDetails.roleName.validations." + - "duplicate", { type: "group" })); - } - } - }).catch(() => { - dispatch(addAlert({ - description: t("console:manage.features.groups." + - "notifications.fetchGroups.genericError.description"), - level: AlertLevels.ERROR, - message: t("console:manage.features.groups." + - "notifications.fetchGroups.genericError.message") - })); - }); - - } } - /> - - { !isReadOnly && ( - - A name for the group. - { " " } - Can contain between 3 to 30 alphanumeric characters, dashes - (-),{ " " } - and underscores (_). - ) - } - - - - - { - !isReadOnly && ( - - ) - } - - - - - - ) : ( - - - - ) - } -