Skip to content

Commit

Permalink
Merge pull request #7597 from DonOmalVindula/fix/is/19769
Browse files Browse the repository at this point in the history
Remove the temp fix to hide `ReadOnly` property in `UniqueIDReadOnlyLDAPUserStoreManager`
  • Loading branch information
DonOmalVindula authored Feb 11, 2025
2 parents c53099d + 7f08837 commit 371fd2e
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 59 deletions.
5 changes: 5 additions & 0 deletions .changeset/wet-melons-wave.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@wso2is/admin.userstores.v1": patch
---

Remove the temp fix to hide ReadOnly property in UniqueIDReadOnlyLDAPUserStoreManager
46 changes: 25 additions & 21 deletions features/admin.userstores.v1/components/add-user-store.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2020, WSO2 LLC. (https://www.wso2.com).
* Copyright (c) 2020-2025, 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
Expand All @@ -18,13 +18,16 @@

import { AppConstants } from "@wso2is/admin.core.v1/constants/app-constants";
import { history } from "@wso2is/admin.core.v1/helpers/history";
import { IdentityAppsError } from "@wso2is/core/errors";
import { AlertLevels, TestableComponentInterface } from "@wso2is/core/models";
import { addAlert } from "@wso2is/core/store";
import { FormValue, useTrigger } from "@wso2is/forms";
import { LinkButton, PrimaryButton, Steps, useWizardAlert } from "@wso2is/react-components";
import { AxiosError } from "axios";
import React, { FunctionComponent, ReactElement, useEffect, useState } from "react";
import { useTranslation } from "react-i18next";
import { useDispatch } from "react-redux";
import { Dispatch } from "redux";
import { Grid, Icon, Modal } from "semantic-ui-react";
import { GeneralDetailsUserstore, GroupDetails, SummaryUserStores, UserDetails } from "./wizards";
import { addUserStore } from "../api";
Expand All @@ -35,7 +38,8 @@ import {
TypeProperty,
UserStorePostData,
UserStoreProperty,
UserstoreType
UserstoreType,
WizardStepInterface
} from "../models";
import { reOrganizeProperties } from "../utils";

Expand All @@ -60,9 +64,9 @@ interface AddUserStoreProps extends TestableComponentInterface {
/**
* This component renders the Add Userstore Wizard.
*
* @param {AddUserStoreProps} props - Props injected to the component.
* @param props - Props injected to the component.
*
* @return {ReactElement}
* @returns add userstore wizard component.
*/
export const AddUserStore: FunctionComponent<AddUserStoreProps> = (props: AddUserStoreProps): ReactElement => {

Expand All @@ -85,7 +89,7 @@ export const AddUserStore: FunctionComponent<AddUserStoreProps> = (props: AddUse
const [ secondStep, setSecondStep ] = useTrigger();
const [ thirdStep, setThirdStep ] = useTrigger();

const dispatch = useDispatch();
const dispatch: Dispatch = useDispatch();

const { t } = useTranslation();

Expand Down Expand Up @@ -124,7 +128,7 @@ export const AddUserStore: FunctionComponent<AddUserStoreProps> = (props: AddUse
onClose();

history.push(AppConstants.getPaths().get("USERSTORES"));
}).catch(error => {
}).catch((error: AxiosError & IdentityAppsError) => {

if (error.response?.status === 403 &&
error.response.data?.code === UserStoreManagementConstants.ERROR_CREATE_LIMIT_REACHED.getErrorCode()) {
Expand Down Expand Up @@ -152,7 +156,7 @@ export const AddUserStore: FunctionComponent<AddUserStoreProps> = (props: AddUse

/**
* This saves the General Details values along with the Type
* @param {Map<string, FormValue>} values Connection Details Values
* @param values - Connection Details Values
*/
const onSubmitGeneralDetails = (values: Map<string, FormValue>): void => {
setGeneralDetailsData(values);
Expand Down Expand Up @@ -180,28 +184,29 @@ export const AddUserStore: FunctionComponent<AddUserStoreProps> = (props: AddUse
};

const serializeProperties = (): UserStoreProperty[] => {
const connectionProperties: UserStoreProperty[] = properties.connection.required.map(property => {
return {
name: property.name,
value: generalDetailsData.get(property.name)?.toString()
};
});
const connectionProperties: UserStoreProperty[] = properties.connection.required.map(
(property: TypeProperty) => {
return {
name: property.name,
value: generalDetailsData.get(property.name)?.toString()
};
});

const userProperties: UserStoreProperty[] = properties.user.required.map(property => {
const userProperties: UserStoreProperty[] = properties.user.required.map((property: TypeProperty) => {
return {
name: property.name,
value: userDetailsData.get(property.name)?.toString()
};
});

const groupProperties: UserStoreProperty[] = properties.group.required.map(property => {
const groupProperties: UserStoreProperty[] = properties.group.required.map((property: TypeProperty) => {
return {
name: property.name,
value: groupDetailsData.get(property.name)?.toString()
};
});

const basicProperties: UserStoreProperty[] = properties.basic.required.map(property => {
const basicProperties: UserStoreProperty[] = properties.basic.required.map((property: TypeProperty) => {
return {
name: property.name,
value: generalDetailsData.get(property.name)?.toString()
Expand Down Expand Up @@ -230,15 +235,15 @@ export const AddUserStore: FunctionComponent<AddUserStoreProps> = (props: AddUse
})
);

const updatedProperties = [
const updatedProperties: UserStoreProperty[] = [
...connectionProperties,
...userProperties,
...groupProperties,
...basicProperties
];

return allProperties.map((property: UserStoreProperty) => {
const updatedProperty = updatedProperties
const updatedProperty: UserStoreProperty = updatedProperties
.find((updatedProperty: UserStoreProperty) => updatedProperty.name === property.name);

if (updatedProperty) {
Expand All @@ -252,7 +257,7 @@ export const AddUserStore: FunctionComponent<AddUserStoreProps> = (props: AddUse
/**
* This contains the wizard steps
*/
const STEPS = [
const STEPS: WizardStepInterface[] = [
{
content: (
<GeneralDetailsUserstore
Expand All @@ -275,7 +280,6 @@ export const AddUserStore: FunctionComponent<AddUserStoreProps> = (props: AddUse
onSubmit={ onSubmitUserDetails }
values={ userDetailsData }
properties={ properties?.user?.required }
type={ type?.typeName }
data-testid={ `${ testId }-user-details` }
/>
),
Expand Down Expand Up @@ -369,7 +373,7 @@ export const AddUserStore: FunctionComponent<AddUserStoreProps> = (props: AddUse
<Steps.Group
current={ currentWizardStep }
>
{ STEPS.map((step, index) => (
{ STEPS.map((step: WizardStepInterface, index: number) => (
<Steps.Step
key={ index }
icon={ step.icon }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2020-2023, WSO2 LLC. (https://www.wso2.com).
* Copyright (c) 2020-2025, 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
Expand Down Expand Up @@ -30,7 +30,7 @@ import { Grid, Icon } from "semantic-ui-react";
import { SqlEditor } from "..";
import { patchUserStore } from "../../api";
import { CONSUMER_USERSTORE_ID } from "../../constants";
import { PatchData, PropertyAttribute, RequiredBinary, TypeProperty, UserstoreType } from "../../models";
import { PatchData, PropertyAttribute, RequiredBinary, TypeProperty } from "../../models";

/**
* Prop types of `EditUserDetails` component
Expand All @@ -44,10 +44,6 @@ interface EditUserDetailsPropsInterface extends TestableComponentInterface {
* userstore id
*/
id: string;
/**
* The type meta data
*/
type: UserstoreType;
/**
* The connection properties.
*/
Expand All @@ -74,7 +70,6 @@ export const EditUserDetails: FunctionComponent<EditUserDetailsPropsInterface> =
properties,
readOnly,
update,
type,
[ "data-testid" ]: testId
} = props;

Expand Down Expand Up @@ -255,12 +250,6 @@ export const EditUserDetails: FunctionComponent<EditUserDetailsPropsInterface> =
(attribute: PropertyAttribute) => attribute?.name === "type"
)?.value === "boolean";

// FIXME: Temp fix to hide the `ReadOnly` property from ReadOnly Userstores.
// This should be handled in the backend and reverted from the UI.
// Tracker: https://github.com/wso2/product-is/issues/19769#issuecomment-1957415262
const isHidden: boolean = type.typeName === "UniqueIDReadOnlyLDAPUserStoreManager"
&& property.name === "ReadOnly";

return (
isPassword
? (
Expand Down Expand Up @@ -291,7 +280,6 @@ export const EditUserDetails: FunctionComponent<EditUserDetailsPropsInterface> =
}
)
}
hidden={ isHidden }
data-testid={ `${ testId }-form-password-input-${ property.name }` }
/>
)
Expand Down Expand Up @@ -324,7 +312,6 @@ export const EditUserDetails: FunctionComponent<EditUserDetailsPropsInterface> =
}
)
}
hidden={ isHidden }
data-testid={ `${ testId }-form-toggle-${ property.name }` }
/>
) :
Expand Down Expand Up @@ -358,7 +345,6 @@ export const EditUserDetails: FunctionComponent<EditUserDetailsPropsInterface> =
}
)
}
hidden={ isHidden }
data-testid={
`${ testId }-form-text-input-${ property.name }`
}
Expand Down Expand Up @@ -392,7 +378,6 @@ export const EditUserDetails: FunctionComponent<EditUserDetailsPropsInterface> =
}
)
}
hidden={ isHidden }
data-testid={
`${ testId }-form-text-input-${ property?.name }`
}
Expand Down
15 changes: 1 addition & 14 deletions features/admin.userstores.v1/components/wizards/user-details.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2020-2024, WSO2 LLC. (https://www.wso2.com).
* Copyright (c) 2020-2025, 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
Expand Down Expand Up @@ -44,10 +44,6 @@ interface UserDetailsPropsInterface extends TestableComponentInterface {
* The properties to be shown in this component.
*/
properties: TypeProperty[];
/**
* The type of the userstore.
*/
type: string;
}

/**
Expand All @@ -64,7 +60,6 @@ export const UserDetails: FunctionComponent<UserDetailsPropsInterface> = (
onSubmit,
values,
properties,
type,
[ "data-testid" ]: testId
} = props;

Expand All @@ -89,12 +84,6 @@ export const UserDetails: FunctionComponent<UserDetailsPropsInterface> = (
})?.value === "boolean";
const isRequired: boolean = !isEmpty(selectedTypeDetail?.defaultValue);

// FIXME: Temp fix to hide the `ReadOnly` property from ReadOnly Userstores.
// This should be handled in the backend and reverted from the UI.
// Tracker: https://github.com/wso2/product-is/issues/19769#issuecomment-1957415262
const isHidden: boolean = type === "UniqueIDReadOnlyLDAPUserStoreManager"
&& selectedTypeDetail.name === "ReadOnly";

if (toggle) {
return (
<Field
Expand Down Expand Up @@ -122,7 +111,6 @@ export const UserDetails: FunctionComponent<UserDetailsPropsInterface> = (
?? selectedTypeDetail.defaultValue
}
toggle
hidden={ isHidden }
data-testid={ `${ testId }-form-toggle-${
selectedTypeDetail.name }` }
/>
Expand Down Expand Up @@ -154,7 +142,6 @@ export const UserDetails: FunctionComponent<UserDetailsPropsInterface> = (
values?.get(selectedTypeDetail?.name)?.toString()
?? selectedTypeDetail.defaultValue
}
hidden={ isHidden }
data-testid={ `${ testId }-form-text-input-${
selectedTypeDetail.name }` }
/>
Expand Down
14 changes: 13 additions & 1 deletion features/admin.userstores.v1/models/user-stores.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2020-2024, WSO2 LLC. (https://www.wso2.com).
* Copyright (c) 2020-2025, 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
Expand All @@ -16,6 +16,8 @@
* under the License.
*/

import { FunctionComponent, ReactElement, SVGProps } from "react";

/**
* Type of user store type.
*/
Expand Down Expand Up @@ -261,3 +263,13 @@ export interface UserStoreItem {
value: string;
disabled?: boolean;
}

/**
* Interface for the wizard step.
*/
export interface WizardStepInterface {
content: ReactElement;
icon: FunctionComponent<SVGProps<SVGSVGElement>>;
title: string;
name?: string;
}
11 changes: 5 additions & 6 deletions features/admin.userstores.v1/pages/user-stores-edit.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2020-2024, WSO2 LLC. (https://www.wso2.com).
* Copyright (c) 2020-2025, 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
Expand All @@ -16,13 +16,13 @@
* under the License.
*/

import { useRequiredScopes } from "@wso2is/access-control";
import { AppConstants } from "@wso2is/admin.core.v1/constants/app-constants";
import { history } from "@wso2is/admin.core.v1/helpers/history";
import { FeatureConfigInterface } from "@wso2is/admin.core.v1/models/config";
import { AppState } from "@wso2is/admin.core.v1/store";
import { UserstoreConstants } from "@wso2is/core/constants";
import { IdentityAppsError } from "@wso2is/core/errors";
import { hasRequiredScopes } from "@wso2is/core/helpers";
import { AlertLevels, TestableComponentInterface } from "@wso2is/core/models";
import { addAlert } from "@wso2is/core/store";
import { GenericIcon, ResourceTab, ResourceTabPaneInterface, TabPageLayout } from "@wso2is/react-components";
Expand Down Expand Up @@ -83,7 +83,8 @@ const UserStoresEditPage: FunctionComponent<UserStoresEditPageInterface> = (
const { t } = useTranslation();

const featureConfig: FeatureConfigInterface = useSelector((state: AppState) => state.config.ui.features);
const allowedScopes: string = useSelector((state: AppState) => state?.auth?.allowedScopes);

const hasUserStoresUpdatePermission: boolean = useRequiredScopes(featureConfig?.userStores?.scopes?.update);

/**
* Fetches the userstore by its id
Expand Down Expand Up @@ -143,8 +144,7 @@ const UserStoresEditPage: FunctionComponent<UserStoresEditPageInterface> = (
* @returns If an userstore is Read Only or not.
*/
const resolveReadOnlyState = (): boolean => {
return !hasRequiredScopes(featureConfig?.userStores, featureConfig?.userStores?.scopes?.update,
allowedScopes);
return !hasUserStoresUpdatePermission;
};

/**
Expand Down Expand Up @@ -189,7 +189,6 @@ const UserStoresEditPage: FunctionComponent<UserStoresEditPageInterface> = (
<EditUserDetails
readOnly={ resolveReadOnlyState() }
update={ getUserStore }
type={ type }
id={ userStoreId }
properties={ properties?.user }
data-testid={ `${ testId }-userstore-user-details-edit` }
Expand Down

0 comments on commit 371fd2e

Please sign in to comment.