-
Notifications
You must be signed in to change notification settings - Fork 201
[Test PR] Implemented API Key For Federated APIs #1338
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
base: main
Are you sure you want to change the base?
Changes from all commits
ff20eb6
0560586
eceff25
47430e6
4ecf5c7
8fb755f
55fdd19
5f49924
b76b9a9
2f087e8
f95e5f0
ff42c63
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -80,6 +80,7 @@ | |
| } from './PlatformGatewayUtils'; | ||
|
|
||
| const PREFIX = 'AddEditGWEnvironment'; | ||
| const FEDERATED_GATEWAY_VALIDATION_ERROR_CODE = 900520; | ||
|
|
||
| const classes = { | ||
| pageContent: `${PREFIX}-pageContent`, | ||
|
|
@@ -365,6 +366,23 @@ | |
| return false; | ||
| }; | ||
|
|
||
| const extractPlanMappingErrors = (responseBody) => { | ||
| const rowErrors = {}; | ||
| if (!responseBody | ||
| || responseBody.code !== FEDERATED_GATEWAY_VALIDATION_ERROR_CODE | ||
|
Check warning on line 372 in portals/admin/src/main/webapp/source/src/app/components/GatewayEnvironments/AddEditGWEnvironment.jsx
|
||
| || !Array.isArray(responseBody.error)) { | ||
| return rowErrors; | ||
| } | ||
|
|
||
| responseBody.error.forEach((errorItem) => { | ||
| const fieldKey = errorItem?.message; | ||
| if (fieldKey && fieldKey.startsWith('plan_mapping.')) { | ||
|
Check warning on line 379 in portals/admin/src/main/webapp/source/src/app/components/GatewayEnvironments/AddEditGWEnvironment.jsx
|
||
| rowErrors[fieldKey] = errorItem.description || 'Invalid external plan assignment'; | ||
|
Comment on lines
+377
to
+380
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Guard Line 380 can throw if Suggested fix responseBody.error.forEach((errorItem) => {
const fieldKey = errorItem?.message;
- if (fieldKey && fieldKey.startsWith(PLAN_MAPPING_PROPERTY_PREFIX)) {
+ if (typeof fieldKey === 'string' && fieldKey.startsWith(PLAN_MAPPING_PROPERTY_PREFIX)) {
rowErrors[fieldKey] = errorItem.description || 'Invalid external plan assignment';
}
});🧰 Tools🪛 GitHub Check: SonarCloud Code Analysis[warning] 380-380: Prefer using an optional chain expression instead, as it's more concise and easier to read. 🤖 Prompt for AI Agents |
||
| } | ||
| }); | ||
| return rowErrors; | ||
| }; | ||
|
|
||
| /** | ||
| * Reducer | ||
| * @param {JSON} state State | ||
|
|
@@ -411,9 +429,11 @@ | |
| const [invalidRoles, setInvalidRoles] = useState([]); | ||
| const [roleValidity, setRoleValidity] = useState(true); | ||
| const [gatewayConfigurations, setGatewayConfiguration] = useState([]); | ||
| const [selectedGatewaySupportedApiTypes, setSelectedGatewaySupportedApiTypes] = useState([]); | ||
| const [supportedModes, setSupportedModes] = useState([]); | ||
| const [validating, setValidating] = useState(false); | ||
| const [saving, setSaving] = useState(false); | ||
| const [planMappingErrors, setPlanMappingErrors] = useState({}); | ||
| const { gatewayTypes } = settings; | ||
| const gatewayVersions = useMemo(() => getPlatformGatewayVersions(settings), [settings]); | ||
| const { | ||
|
|
@@ -638,6 +658,10 @@ | |
| } | ||
| }, [permissions]); | ||
|
|
||
| useEffect(() => { | ||
| setPlanMappingErrors({}); | ||
| }, [gatewayType]); | ||
|
|
||
| useEffect(() => { | ||
| if (!platformHeaderEditMode) { | ||
| setPlatformDisplayNameDraft( | ||
|
|
@@ -657,7 +681,7 @@ | |
| ]); | ||
|
|
||
| useEffect(() => { | ||
| const config = settings.gatewayConfiguration.filter( | ||
| const config = (settings.gatewayConfiguration || []).filter( | ||
|
Check warning on line 684 in portals/admin/src/main/webapp/source/src/app/components/GatewayEnvironments/AddEditGWEnvironment.jsx
|
||
| (t) => t.type === gatewayType, | ||
| )[0]; | ||
| if ( | ||
|
|
@@ -667,11 +691,13 @@ | |
| ) { | ||
| setGatewayConfiguration([]); | ||
| setSupportedModes([]); | ||
| setSelectedGatewaySupportedApiTypes([]); | ||
| } else { | ||
| setGatewayConfiguration(config.configurations || []); | ||
| setSupportedModes(config.supportedModes || []); | ||
| setSelectedGatewaySupportedApiTypes(config.supportedApiTypes || []); | ||
| } | ||
| }, [gatewayType]); | ||
| }, [gatewayType, settings.gatewayConfiguration]); | ||
|
|
||
| let permissionType = ''; | ||
| if (permissions) { | ||
|
|
@@ -881,6 +907,13 @@ | |
| }; | ||
|
|
||
| const setAdditionalProperties = (key, value) => { | ||
| if (key && planMappingErrors[key]) { | ||
| setPlanMappingErrors((prevErrors) => { | ||
| const updatedErrors = { ...prevErrors }; | ||
| delete updatedErrors[key]; | ||
| return updatedErrors; | ||
| }); | ||
| } | ||
| const clonedAdditionalProperties = cloneDeep(additionalProperties); | ||
| if (value === undefined) { | ||
| delete clonedAdditionalProperties[key]; | ||
|
|
@@ -1189,6 +1222,7 @@ | |
|
|
||
| promiseAPICall | ||
| .then((result) => { | ||
| setPlanMappingErrors({}); | ||
| if (id) { | ||
| Alert.success( | ||
| `${name} ${intl.formatMessage({ | ||
|
|
@@ -1226,8 +1260,28 @@ | |
| }) | ||
| .catch((error) => { | ||
| const { response } = error; | ||
| if (response.body) { | ||
| Alert.error(response.body.description); | ||
| if (response?.body) { | ||
| setPlanMappingErrors(extractPlanMappingErrors(response.body)); | ||
| Alert.error( | ||
| response.body.description | ||
| || error?.message | ||
| || intl.formatMessage({ | ||
| id: 'GatewayEnvironments.AddEditGWEnvironment.save.failed', | ||
| defaultMessage: 'Save failed', | ||
| }), | ||
| ); | ||
| } else { | ||
| setPlanMappingErrors({}); | ||
| const statusSuffix = response?.status | ||
| ? ` (${response.status}${response?.statusText ? ` ${response.statusText}` : ''})` | ||
|
Check warning on line 1276 in portals/admin/src/main/webapp/source/src/app/components/GatewayEnvironments/AddEditGWEnvironment.jsx
|
||
| : ''; | ||
| Alert.error( | ||
| error?.message | ||
| || `${intl.formatMessage({ | ||
| id: 'GatewayEnvironments.AddEditGWEnvironment.save.failed', | ||
| defaultMessage: 'Save failed', | ||
| })}${statusSuffix}`, | ||
| ); | ||
| } | ||
| setSaving(false); | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| }); | ||
|
|
@@ -2371,6 +2425,7 @@ | |
| gatewayConfigurations={ | ||
| gatewayConfigurations | ||
| } | ||
| supportedApiTypes={selectedGatewaySupportedApiTypes} | ||
| additionalProperties={cloneDeep( | ||
| additionalProperties, | ||
| )} | ||
|
|
@@ -2383,6 +2438,9 @@ | |
| validating={ | ||
| validating | ||
| } | ||
| planMappingErrors={ | ||
| planMappingErrors | ||
| } | ||
| gatewayId={cloneDeep( | ||
| id, | ||
| )} | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.