Skip to content

Commit

Permalink
Address review comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
Yasasr1 committed Nov 13, 2024
1 parent 9d66740 commit adcb98a
Show file tree
Hide file tree
Showing 8 changed files with 123 additions and 100 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ import { HttpMethods } from "@wso2is/core/models";
import { OrganizationDiscoveryConfigConstants } from "../constants/organization-discovery-config-constants";
import {
OrganizationDiscoveryConfigInterface,
OrganizationDiscoveryConfigPropertyInterface
OrganizationDiscoveryConfigPropertyInterface,
OrganizationDiscoveryResponseInterface
} from "../models/organization-discovery";

/**
Expand All @@ -36,8 +37,7 @@ import {
* @returns SWR response object containing the data, error, isValidating, mutate.
*/
const useGetOrganizationDiscoveryConfig = <
Data = OrganizationDiscoveryConfigInterface & { isOrganizationDiscoveryEnabled: boolean,
isEmailDomainBasedSelfRegistrationEnabled: boolean },
Data = OrganizationDiscoveryResponseInterface,
Error = RequestErrorInterface
>(shouldFetch: boolean = true): RequestResultInterface<Data, Error> => {
const requestConfig: RequestConfigInterface = {
Expand All @@ -59,11 +59,13 @@ const useGetOrganizationDiscoveryConfig = <
if ((data as OrganizationDiscoveryConfigInterface)?.properties) {
(data as OrganizationDiscoveryConfigInterface).properties?.forEach(
(property: OrganizationDiscoveryConfigPropertyInterface) => {
if (property.key === "emailDomain.enable" && property.value === "true") {
if (property.key === OrganizationDiscoveryConfigConstants.EMAIL_DOMAIN_DISCOVERY_PROPERTY_KEY
&& property.value === "true") {
isOrganizationDiscoveryEnabled = true;
}

if (property.key === "emailDomainBasedSelfSignup.enable" && property.value === "true") {
if (property.key === OrganizationDiscoveryConfigConstants.EMAIL_DOMAIN_DISCOVERY_SELF_REG_PROPERTY_KEY
&& property.value === "true") {
isEmailDomainBasedSelfRegistrationEnabled = true;
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
/**
* Copyright (c) 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.
*/

.discoverable-organizations-list-layout {
.top-action-panel {
display: flex;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ export interface DiscoverableOrganizationsListLayoutPropsInterface extends Ident
onListItemLimitChange: (limit: number) => void;
onListOffsetChange: (offset: number) => void;
onSearchQueryChange: (query: string) => void;

}

/**
Expand All @@ -60,21 +59,17 @@ export interface DiscoverableOrganizationsListLayoutPropsInterface extends Ident
* @param props - Props injected to the component.
* @returns Discoverable organization list layout component.
*/
const DiscoverableOrganizationsListLayout: FunctionComponent<DiscoverableOrganizationsListLayoutPropsInterface> = (
props: DiscoverableOrganizationsListLayoutPropsInterface
): ReactElement => {

const {
discoverableOrganizations,
listItemLimit,
isDiscoverableOrganizationsFetchRequestLoading,
featureConfig,
searchQuery,
onListItemLimitChange,
onListOffsetChange,
onSearchQueryChange,
[ "data-componentid" ]: componentId
} = props;
const DiscoverableOrganizationsListLayout: FunctionComponent<DiscoverableOrganizationsListLayoutPropsInterface> = ({
discoverableOrganizations,
listItemLimit,
isDiscoverableOrganizationsFetchRequestLoading,
featureConfig,
searchQuery,
onListItemLimitChange,
onListOffsetChange,
onSearchQueryChange,
["data-componentid"]: componentId = "discoverable-organizations-list-layout"
}: DiscoverableOrganizationsListLayoutPropsInterface): ReactElement => {

const ORGANIZATIONS_LIST_SORTING_OPTIONS: DropdownItemProps[] = [
{
Expand Down Expand Up @@ -246,11 +241,4 @@ const DiscoverableOrganizationsListLayout: FunctionComponent<DiscoverableOrganiz
);
};

/**
* Default props for the component.
*/
DiscoverableOrganizationsListLayout.defaultProps = {
"data-componentid": "discoverable-organizations-list-layout"
};

export default DiscoverableOrganizationsListLayout;
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,8 @@ export class OrganizationDiscoveryConfigConstants {
*/
private constructor() {}

public static readonly EMAIL_DOMAIN_DISCOVERY_PROPERTY_KEY: string = "emailDomain.enable";
public static readonly EMAIL_DOMAIN_DISCOVERY_SELF_REG_PROPERTY_KEY: string = "emailDomainBasedSelfSignup.enable";

public static readonly ORGANIZATION_DISCOVERY_DOMAINS_NOT_CONFIGURED_ERROR_CODE: string = "OCM-60002";
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,19 @@ export class OrganizationDiscoveryConstants {
ORGANIZATION_DOMAIN_ASSIGN_ERROR: IdentityAppsError;
ORGANIZATION_DOMAIN_ASSIGN_INVALID_STATUS_CODE_ERROR: IdentityAppsError;
} = {
ORGANIZATION_DOMAIN_ASSIGN_ERROR: new IdentityAppsError(
OrganizationDiscoveryConstants.ORGANIZATION_DOMAIN_ASSIGN_ERROR_CODE,
"An error occurred while assigning email domains for the organization.",
"Error while assigning domains",
null
),
ORGANIZATION_DOMAIN_ASSIGN_INVALID_STATUS_CODE_ERROR: new IdentityAppsError(
OrganizationDiscoveryConstants.ORGANIZATION_DOMAIN_ASSIGN_INVALID_STATUS_CODE_ERROR_CODE,
"An invalid status code was received while assigning email domains for the organization.",
"Invalid status code while assigning domains",
null
)
};
ORGANIZATION_DOMAIN_ASSIGN_ERROR: new IdentityAppsError(

Check warning on line 41 in features/admin.organization-discovery.v1/constants/organization-discovery-constants.ts

View workflow job for this annotation

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

Expected indentation of 8 spaces but found 12
OrganizationDiscoveryConstants.ORGANIZATION_DOMAIN_ASSIGN_ERROR_CODE,

Check warning on line 42 in features/admin.organization-discovery.v1/constants/organization-discovery-constants.ts

View workflow job for this annotation

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

Expected indentation of 12 spaces but found 16
"An error occurred while assigning email domains for the organization.",

Check warning on line 43 in features/admin.organization-discovery.v1/constants/organization-discovery-constants.ts

View workflow job for this annotation

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

Expected indentation of 12 spaces but found 16
"Error while assigning domains",

Check warning on line 44 in features/admin.organization-discovery.v1/constants/organization-discovery-constants.ts

View workflow job for this annotation

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

Expected indentation of 12 spaces but found 16
null

Check warning on line 45 in features/admin.organization-discovery.v1/constants/organization-discovery-constants.ts

View workflow job for this annotation

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

Expected indentation of 12 spaces but found 16
),

Check warning on line 46 in features/admin.organization-discovery.v1/constants/organization-discovery-constants.ts

View workflow job for this annotation

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

Expected indentation of 8 spaces but found 12
ORGANIZATION_DOMAIN_ASSIGN_INVALID_STATUS_CODE_ERROR: new IdentityAppsError(

Check warning on line 47 in features/admin.organization-discovery.v1/constants/organization-discovery-constants.ts

View workflow job for this annotation

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

Expected indentation of 8 spaces but found 12
OrganizationDiscoveryConstants.ORGANIZATION_DOMAIN_ASSIGN_INVALID_STATUS_CODE_ERROR_CODE,

Check warning on line 48 in features/admin.organization-discovery.v1/constants/organization-discovery-constants.ts

View workflow job for this annotation

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

Expected indentation of 12 spaces but found 16
"An invalid status code was received while assigning email domains for the organization.",

Check warning on line 49 in features/admin.organization-discovery.v1/constants/organization-discovery-constants.ts

View workflow job for this annotation

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

Expected indentation of 12 spaces but found 16
"Invalid status code while assigning domains",

Check warning on line 50 in features/admin.organization-discovery.v1/constants/organization-discovery-constants.ts

View workflow job for this annotation

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

Expected indentation of 12 spaces but found 16
null
)
};

/**
* Set of keys used to enable/disable features.
Expand All @@ -59,5 +59,7 @@ export class OrganizationDiscoveryConstants {
.set("ORGANIZATION_DISCOVERY_CREATE", "organizationDiscovery.create")
.set("ORGANIZATION_DISCOVERY_UPDATE", "organizationDiscovery.update")
.set("ORGANIZATION_DISCOVERY_DELETE", "organizationDiscovery.delete")
.set("ORGANIZATION_DISCOVERY_READ", "organizationDiscovery.read");
.set("ORGANIZATION_DISCOVERY_READ", "organizationDiscovery.read")
.set("ORGANIZATION_DISCOVERY_EMAIL_DOMAIN_FOR_SELF_REG",
"organizationDiscovery.emailDomainDiscoveryForSelfReg");
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ export interface OrganizationDiscoveryAttributeDataInterface {
attributes: OrganizationDiscoveryAttributesInterface[];
}

export interface OrganizationDiscoveryResponseInterface {
isOrganizationDiscoveryEnabled: boolean;
isEmailDomainBasedSelfRegistrationEnabled: boolean;
}

export interface OrganizationLinkInterface {
href: string;
rel: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ import {
UIConstants,
history
} from "@wso2is/admin.core.v1";
import { isFeatureEnabled } from "@wso2is/core/helpers";
import { AlertLevels, IdentifiableComponentInterface } from "@wso2is/core/models";
import { addAlert } from "@wso2is/core/store";
import { Field, Form } from "@wso2is/form";
import { EmphasizedSegment, Link, PageLayout } from "@wso2is/react-components";
import { AxiosError } from "axios";
import React, {
FunctionComponent,
ReactElement,
Expand All @@ -46,16 +46,18 @@ import {
CheckboxProps,
Divider
} from "semantic-ui-react";
import { ConnectorPropertyInterface, GovernanceConnectorInterface } from "../../admin.connections.v1";
import { ConnectorPropertyInterface } from "../../admin.connections.v1";
import {
ServerConfigurationsConstants,
UpdateGovernanceConnectorConfigPropertyInterface,
getConnectorDetails
useGovernanceConnectorDetails
} from "../../admin.server-configurations.v1";
import updateOrganizationDiscoveryConfig from "../api/update-organization-discovery-config";
import useGetOrganizationDiscovery from "../api/use-get-organization-discovery";
import useGetOrganizationDiscoveryConfig from "../api/use-get-organization-discovery-config";
import DiscoverableOrganizationsListLayout from "../components/discoverable-organizations-list-layout";
import { OrganizationDiscoveryConfigConstants } from "../constants/organization-discovery-config-constants";
import { OrganizationDiscoveryConstants } from "../constants/organization-discovery-constants";
import { OrganizationDiscoveryConfigInterface } from "../models/organization-discovery";

/**
Expand All @@ -79,8 +81,9 @@ const OrganizationDiscoveryDomainsPage: FunctionComponent<OrganizationDiscoveryD
const dispatch: Dispatch = useDispatch();

const featureConfig: FeatureConfigInterface = useSelector((state: AppState) => state?.config?.ui?.features);
const isEmailDomainDiscoveryForSelfRegFeatureEnabled: boolean = !featureConfig?.organizationDiscovery?.
disabledFeatures?.includes("organizationDiscovery.emailDomainDiscoveryForSelfReg");
const isEmailDomainDiscoveryForSelfRegFeatureEnabled: boolean = isFeatureEnabled(
featureConfig?.organizationDiscovery,
OrganizationDiscoveryConstants.FEATURE_DICTIONARY.get("ORGANIZATION_DISCOVERY_EMAIL_DOMAIN_FOR_SELF_REG"));
const isReadOnly: boolean = !useRequiredScopes(featureConfig?.organizationDiscovery?.scopes?.update);

const [ searchQuery, setSearchQuery ] = useState<string>("");
Expand All @@ -107,70 +110,36 @@ const OrganizationDiscoveryDomainsPage: FunctionComponent<OrganizationDiscoveryD
isLoading: isDiscoverableOrganizationsFetchRequestLoading
} = useGetOrganizationDiscovery(true, filterQuery, listOffset, listItemLimit);

const {
data: selfRegistrationConnectorDetetails
} = useGovernanceConnectorDetails(ServerConfigurationsConstants.USER_ONBOARDING_CONNECTOR_ID,
ServerConfigurationsConstants.SELF_SIGN_UP_CONNECTOR_ID);

const { isOrganizationDiscoveryEnabled, isEmailDomainBasedSelfRegistrationEnabled } = organizationDiscoveryConfig;
const [ isSelfRegEnabled, setIsSelfRegEnabled ] = useState<boolean>(false);

/**
* Fetch the self-registration configuration.
*/
useEffect(() => {
getConnectorDetails(ServerConfigurationsConstants.USER_ONBOARDING_CONNECTOR_ID,
ServerConfigurationsConstants.SELF_SIGN_UP_CONNECTOR_ID)
.then((response: GovernanceConnectorInterface) => {
const selfRegEnabledProperty: UpdateGovernanceConnectorConfigPropertyInterface =
response?.properties?.find((property: ConnectorPropertyInterface) =>
property.name === ServerConfigurationsConstants.SELF_REGISTRATION_ENABLE
);

setIsSelfRegEnabled(selfRegEnabledProperty?.value === "true");
})
.catch((error: AxiosError) => {
if (error.response && error.response.data && error.response.data.detail) {
dispatch(
addAlert({
description: t(
"governanceConnectors:notifications." +
"getConnector.error.description",
{ description: error.response.data.description }
),
level: AlertLevels.ERROR,
message: t(
"governanceConnectors:notifications." +
"getConnector.error.message"
)
})
);
} else {
dispatch(
addAlert({
description: t(
"governanceConnectors:notifications." +
"getConnector.genericError.description"
),
level: AlertLevels.ERROR,
message: t(
"governanceConnectors:notifications." +
"getConnector.genericError.message"
)
})
);
}
});
}, []);
const selfRegEnabledProperty: UpdateGovernanceConnectorConfigPropertyInterface =
selfRegistrationConnectorDetetails?.properties?.find((property: ConnectorPropertyInterface) =>
property.name === ServerConfigurationsConstants.SELF_REGISTRATION_ENABLE
);

setIsSelfRegEnabled(selfRegEnabledProperty?.value === "true");
}, [ selfRegistrationConnectorDetetails ]);

const handleEmailDomainBasedSelfRegistration = (value: boolean): void => {
const updateData: OrganizationDiscoveryConfigInterface = {
properties: []
};

updateData.properties.push({
key: "emailDomain.enable",
value: isOrganizationDiscoveryEnabled ? "true" : "false"
key: OrganizationDiscoveryConfigConstants.EMAIL_DOMAIN_DISCOVERY_PROPERTY_KEY,
value: isOrganizationDiscoveryEnabled.toString()
});

updateData.properties.push({
key: "emailDomainBasedSelfSignup.enable",
value: value ? "true" : "false"
key: OrganizationDiscoveryConfigConstants.EMAIL_DOMAIN_DISCOVERY_SELF_REG_PROPERTY_KEY,
value: value.toString()
});

updateOrganizationDiscoveryConfig(updateData)
Expand Down Expand Up @@ -283,17 +252,17 @@ const OrganizationDiscoveryDomainsPage: FunctionComponent<OrganizationDiscoveryD

if (data.checked === true) {
updateData.properties.push({
key: "emailDomain.enable",
key: OrganizationDiscoveryConfigConstants.EMAIL_DOMAIN_DISCOVERY_PROPERTY_KEY,
value: "true"
});
} else {
updateData.properties.push({
key: "emailDomain.enable",
key: OrganizationDiscoveryConfigConstants.EMAIL_DOMAIN_DISCOVERY_PROPERTY_KEY,
value: "false"
});

updateData.properties.push({
key: "emailDomainBasedSelfSignup.enable",
key: OrganizationDiscoveryConfigConstants.EMAIL_DOMAIN_DISCOVERY_SELF_REG_PROPERTY_KEY,
value: "false"
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,42 @@ export const useGovernanceConnectors = <
};
};

/**
* Get details of a governance connector.
*
* @param categoryId - ID of the connector category
* @param connectorId - ID of the connector
* @returns the governance connector.
*/
export const useGovernanceConnectorDetails = <
Data = GovernanceConnectorInterface,
Error = RequestErrorInterface
>(
categoryId: string,
connectorId: string,
shouldFetch: boolean = true
): RequestResultInterface<Data, Error> => {
const requestConfig: RequestConfigInterface = {
headers: {
"Accept": "application/json",
"Content-Type": "application/json"
},
method: HttpMethods.GET,
url: store.getState().config.endpoints.governanceConnectorCategories + "/"
+ categoryId + "/connectors/" + connectorId
};

const { data, error, isValidating, mutate } = useRequest<Data, Error>(shouldFetch ? requestConfig: null);

return {
data,
error: error,
isLoading: !error && !data,
isValidating,
mutate: mutate
};
};

export const getData = (url: string): Promise<any> => {
const requestConfig: AxiosRequestConfig = {
headers: {
Expand Down

0 comments on commit adcb98a

Please sign in to comment.