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

backport 2024.02.xx - Fix #10530 fix catalog editor for array scenario (#10531) #10535

Merged
merged 1 commit into from
Sep 6, 2024
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
14 changes: 7 additions & 7 deletions web/client/components/catalog/editor/MainForm.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import InfoPopover from '../../widgets/widget/InfoPopover';
import { FormControl as FC, Form, Col, FormGroup, ControlLabel, Alert } from "react-bootstrap";

import localizedProps from '../../misc/enhancers/localizedProps';
import {defaultPlaceholder, isValidURL} from "./MainFormUtils";
import {defaultPlaceholder, checkUrl} from "./MainFormUtils";

const FormControl = localizedProps('placeholder')(FC);

Expand Down Expand Up @@ -153,13 +153,13 @@ export default ({
onChangeType,
setValid = () => {}
}) => {
const [invalidProtocol, setInvalidProtocol] = useState(false);
const [error, setError] = useState(null);
function handleProtocolValidity(url) {
onChangeUrl(url);
if (url) {
const isInvalidProtocol = !isValidURL(url, null, service?.allowUnsecureLayers);
setInvalidProtocol(isInvalidProtocol);
setValid(!isInvalidProtocol);
const {valid, errorMsgId} = checkUrl(url, null, service?.allowUnsecureLayers);
setError(valid ? null : errorMsgId);
setValid(valid);
}
}
useEffect(() => {
Expand Down Expand Up @@ -192,8 +192,8 @@ export default ({
</FormGroup>
<URLEditor key="url-row" serviceTypes={serviceTypes} service={service} onChangeUrl={handleProtocolValidity} onChangeTitle={onChangeTitle} onChangeServiceProperty={onChangeServiceProperty} />

{invalidProtocol ? <Alert bsStyle="danger">
<Message msgId="catalog.invalidUrlHttpProtocol" />
{error ? <Alert bsStyle="danger">
<Message msgId={error} />
</Alert> : null}

</Form>);
Expand Down
19 changes: 12 additions & 7 deletions web/client/components/catalog/editor/MainFormUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,18 @@ export const defaultPlaceholder = (service) => {
* @param {string} catalogUrl The URL of the catalog
* @param {string} currentLocation The current location, by default `window.location.href`
* @param {boolean} allowUnsecureLayers flag to allow unsecure url
* @returns {boolean} true if the URL is valid
* @returns {object} {valid: boolean, errorMsgId: string}
*/
export const isValidURL = (catalogUrl = '', currentLocation, allowUnsecureLayers) => {
const { protocol: mapStoreProtocol } = url.parse(currentLocation ?? window.location.href);
const { protocol: catalogProtocol } = url.parse(catalogUrl);
if (mapStoreProtocol === 'https:' && !!catalogProtocol) {
return (mapStoreProtocol === catalogProtocol || allowUnsecureLayers);
export const checkUrl = (catalogUrl = '', currentLocation, allowUnsecureLayers) => {
try {
const { protocol: mapStoreProtocol } = url.parse(currentLocation ?? window.location.href);
const { protocol: catalogProtocol } = url.parse(catalogUrl);
if (mapStoreProtocol === 'https:' && !!catalogProtocol) {
const isProtocolValid = (mapStoreProtocol === catalogProtocol || allowUnsecureLayers);
return isProtocolValid ? {valid: true} : {valid: false, errorMsgId: "catalog.invalidUrlHttpProtocol"};
}
return {valid: true};
} catch (e) {
return {valid: false, errorMsgId: "catalog.invalidArrayUsageForUrl"};
}
return true;
};
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import expect from "expect";

import { isValidURL } from '../MainFormUtils';
import { checkUrl } from '../MainFormUtils';

describe('Catalog Main Form Editor Utils', () => {
it('isValidURL', () => {
it('checkUrl', () => {
const URLS = [
// http
['http://myDomain.com/geoserver/wms', 'https://myMapStore.com/geoserver/wms', false],
['http://myDomain.com/geoserver/wms', 'https://myMapStore.com/geoserver/wms', false, "catalog.invalidUrlHttpProtocol"],
['http://myDomain.com/geoserver/wms', 'http://myMapStore.com/geoserver/wms', true],
// https
['https://myDomain.com/geoserver/wms', 'http://myMapStore.com/geoserver/wms', true],
Expand All @@ -19,16 +19,17 @@ describe('Catalog Main Form Editor Utils', () => {
['/geoserver/wms', 'https://myMapStore.com/geoserver/wms', true],
// relative path
["geoserver/wms", "http://myMapStore.com/geoserver/wms", true],
["geoserver/wms", "https://myMapStore.com/geoserver/wms", true]


["geoserver/wms", "https://myMapStore.com/geoserver/wms", true],
[["geoserver/wms", "geoserver/wms"], "https://myMapStore.com/geoserver/wms", false, "catalog.invalidArrayUsageForUrl"], // array
["http://com/geoserver/wms", "https://myMapStore.com/geoserver/wms", false, "catalog.invalidUrlHttpProtocol"]
];
URLS.forEach(([catalogURL, locationURL, valid]) => {
const result = isValidURL(catalogURL, locationURL);
expect(!!result).toEqual(!!valid, `${catalogURL} - added when location is ${locationURL} should be ${valid}, but it is ${result}`);
URLS.forEach(([catalogURL, locationURL, valid, messageId]) => {
const {valid: isValid, errorMsgId} = checkUrl(catalogURL, locationURL);
expect(!!isValid).toEqual(!!valid, `${catalogURL} - added when location is ${locationURL} should be ${valid}, but it is ${isValid}`);
expect(messageId).toEqual(errorMsgId);
});
});
it('isValidURL with allowUnsecureLayers', () => {
it('checkUrl with allowUnsecureLayers', () => {
const URLS = [
// http
['http://myDomain.com/geoserver/wms', 'https://myMapStore.com/geoserver/wms', true, true],
Expand All @@ -44,13 +45,14 @@ describe('Catalog Main Form Editor Utils', () => {
['/geoserver/wms', 'https://myMapStore.com/geoserver/wms', true, false],
// relative path
["geoserver/wms", "http://myMapStore.com/geoserver/wms", true, false],
["geoserver/wms", "https://myMapStore.com/geoserver/wms", true, true]


["geoserver/wms", "https://myMapStore.com/geoserver/wms", true, true],
[["geoserver/wms", "geoserver/wms"], "https://myMapStore.com/geoserver/wms", false, false, "catalog.invalidArrayUsageForUrl"] // array
];
URLS.forEach(([catalogURL, locationURL, valid, allowUnsecureLayers]) => {
const result = isValidURL(catalogURL, locationURL, allowUnsecureLayers);
expect(!!result).toEqual(!!valid, `${catalogURL} - added when location is ${locationURL} should be ${valid}, but it is ${result}`);
URLS.forEach(([catalogURL, locationURL, valid, allowUnsecureLayers, messageId]) => {
const {valid: isValid, errorMsgId} = checkUrl(catalogURL, locationURL, allowUnsecureLayers);
expect(!!isValid).toEqual(!!valid, `${catalogURL} - added when location is ${locationURL} should be ${valid}, but it is ${isValid}`);
expect(messageId).toEqual(errorMsgId);
expect(!!isValid).toEqual(!!valid, `${catalogURL} - added when location is ${locationURL} should be ${valid}, but it is ${isValid}`);
});
});
});
5 changes: 3 additions & 2 deletions web/client/translations/data.de-DE.json
Original file line number Diff line number Diff line change
Expand Up @@ -1669,6 +1669,7 @@
"advancedSettings": "Erweiterte Einstellungen",
"templateMetadataAvailable": "Metadaten im Dublin Core-Format verfügbar: abstract, boundingBox, contributor, creator, description, format, identifier, references, rights, source, subject, temporal, title, type, uri",
"invalidUrlHttpProtocol": "Dieser Katalog kann nicht zu den verfügbaren hinzugefügt werden, da er ein http-Protokoll verwendet. Bitte geben Sie eine Katalog-URL an, die das https-Protokoll verwendet.",
"invalidArrayUsageForUrl": "Die Katalog-URL konnte nicht korrekt gelesen werden",
"notification": {
"errorTitle": "Error",
"errorSearchingRecords": "Einige Datensätze wurden nicht gefunden: {records} . Bitte überprüfen Sie die URL des Abfrageparameters",
Expand Down Expand Up @@ -2730,13 +2731,13 @@
"msExtrudedHeight": "Extrudierte Höhe",
"msExtrusionColor": "Extrusionsfarbe",
"msExtrusionType": "Extrusionstyp",
"wall": "Wand",
"wall": "Wand",
"enableBanding": "Band styling",
"selectChannel": "Wählen Sie eine Band aus",
"minLabel": "Min",
"maxLabel": "Max",
"minSourceValue": "Mindestwert der Quelldaten",
"maxSourceValue": "Maximaler Quelldatenwert",
"maxSourceValue": "Maximaler Quelldatenwert",
"customParams": "Benutzerdefinierte Parameter",
"wrongFormatMsg": "Die eingegebene Konfiguration ist in falschem Format !!"
},
Expand Down
1 change: 1 addition & 0 deletions web/client/translations/data.en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -1630,6 +1630,7 @@
"advancedSettings": "Advanced settings",
"templateMetadataAvailable": "Metadata available from Dublin Core format: abstract, boundingBox, contributor, creator, description, format, identifier, references, rights, source, subject, temporal, title, type, uri",
"invalidUrlHttpProtocol": "This catalog cannot be added to the available ones because it uses an http protocol. Please provide a catalog url that uses https protocol",
"invalidArrayUsageForUrl": "The catalog URL could not be parsed correctly",
"notification": {
"errorTitle": "Error",
"errorSearchingRecords": "Some records have not been found: {records} Please check the query URL and its parameters.",
Expand Down
1 change: 1 addition & 0 deletions web/client/translations/data.es-ES.json
Original file line number Diff line number Diff line change
Expand Up @@ -1631,6 +1631,7 @@
"advancedSettings": "Ajustes avanzados",
"templateMetadataAvailable": "Metadatos disponibles en formato Dublin Core: abstract, boundingBox, contributor, creator, description, format, identifier, references, rights, source, subject, temporal, title, type, uri",
"invalidUrlHttpProtocol": "Este catálogo no se puede agregar a los disponibles porque usa un protocolo http. Proporcione una URL del catálogo que utilice el protocolo https",
"invalidArrayUsageForUrl": "La URL del catálogo no se pudo leer correctamente.",
"notification": {
"errorTitle": "Error",
"errorSearchingRecords": "No se han encontrado algunos registros: {records} . Por favor revise la consulta param url",
Expand Down
1 change: 1 addition & 0 deletions web/client/translations/data.fr-FR.json
Original file line number Diff line number Diff line change
Expand Up @@ -1631,6 +1631,7 @@
"advancedSettings": "Réglages avancés",
"templateMetadataAvailable": "Métadonnées disponibles pour le format Dublin Core : abstract, boundingBox, contributor, creator, description, format, identifier, references, rights, source, subject, temporal, title, type, uri",
"invalidUrlHttpProtocol": "Ce catalogue ne peut pas être ajouté à ceux disponibles car il utilise un protocole http. Veuillez fournir une URL de catalogue qui utilise le protocole https.",
"invalidArrayUsageForUrl": "L'URL du catalogue n'a pas pu être lue correctement",
"notification": {
"errorTitle": "Erreur",
"errorSearchingRecords": "Certains enregistrements n'ont pas été trouvés: {records} . Veuillez vérifier l'URL de la requête et ses paramètres.",
Expand Down
1 change: 1 addition & 0 deletions web/client/translations/data.it-IT.json
Original file line number Diff line number Diff line change
Expand Up @@ -1630,6 +1630,7 @@
"advancedSettings": "Impostazioni avanzate",
"templateMetadataAvailable": "Metadati disponibili del formato Dublin Core: abstract, boundingBox, contributor, creator, description, format, identifier, references, rights, source, subject, temporal, title, type, uri",
"invalidUrlHttpProtocol": "Questo catalogo non può essere aggiunto a quelli disponibili perché utilizza un protocollo http. Fornisci un URL di catalogo che utilizzi il protocollo https",
"invalidArrayUsageForUrl": "Non è stato possibile leggere correttamente l'URL del catalogo",
"notification": {
"errorTitle": "Errore",
"errorSearchingRecords": "Alcuni record non sono stati trovati: {records} . Controlla la lista dei parametri nella barra degli indirizzi",
Expand Down
Loading