From 5d09fdcff93b65c105289c907cc3c2dbd91fd814 Mon Sep 17 00:00:00 2001 From: Lorenzo Natali Date: Fri, 21 Jul 2017 15:18:53 +0200 Subject: [PATCH 1/5] fixed auth-key with custom parameter name --- web/client/libs/ajax.js | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/web/client/libs/ajax.js b/web/client/libs/ajax.js index 8b17ef3348..c4e1bbaebe 100644 --- a/web/client/libs/ajax.js +++ b/web/client/libs/ajax.js @@ -11,7 +11,7 @@ const ConfigUtils = require('../utils/ConfigUtils'); const SecurityUtils = require('../utils/SecurityUtils'); const assign = require('object-assign'); -const {has, isObject} = require('lodash'); +const {isObject} = require('lodash'); const urlUtil = require('url'); /** @@ -38,17 +38,15 @@ function addAuthenticationToAxios(axiosConfig) { return axiosConfig; } const rule = SecurityUtils.getAuthenticationRule(axiosConfig.url); - const method = rule && (has(rule, "method.method") ? rule.method : assign({}, {method: rule.method})); - const methodType = rule && (has(rule, "method.method") ? rule.method.method : rule.method); - switch (methodType) { + + switch (rule && rule.method) { case 'authkey': - case 'authkey-param': { const token = SecurityUtils.getToken(); if (!token) { return axiosConfig; } - addParameterToAxiosConfig(axiosConfig, method.param || 'authkey', token); + addParameterToAxiosConfig(axiosConfig, rule.authkeyParamName || 'authkey', token); return axiosConfig; } case 'basic': From f022ff5cf736b6bfd200f0dabd3ac19beb36758e Mon Sep 17 00:00:00 2001 From: Lorenzo Natali Date: Fri, 21 Jul 2017 15:19:52 +0200 Subject: [PATCH 2/5] Made export resilient to errors due to natural order issues --- web/client/epics/wfsdownload.js | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/web/client/epics/wfsdownload.js b/web/client/epics/wfsdownload.js index 5c4e7563f6..1866875525 100644 --- a/web/client/epics/wfsdownload.js +++ b/web/client/epics/wfsdownload.js @@ -9,7 +9,7 @@ const FilterUtils = require('../utils/FilterUtils'); const {getByOutputFormat} = require('../utils/FileFormatUtils'); const getWFSFeature = ({url, filterObj = {}, downloadOptions= {}} = {}) => { - const data = FilterUtils.toOGCFilter(filterObj.featureTypeName, filterObj, filterObj.ogcVersion); + const data = FilterUtils.toOGCFilter(filterObj.featureTypeName, filterObj, filterObj.ogcVersion, filterObj.sortOptions); return Rx.Observable.defer( () => axios.post(url + `?service=WFS&outputFormat=${downloadOptions.selectedFormat}`, data, { timeout: 60000, @@ -25,6 +25,12 @@ const getFileName = action => { } return name; }; +const getDefaultSortOptions = (attribute) => { + return attribute ? { sortBy: attribute, sortOrder: 'A'} : {}; +}; +const getFirstAttribute = (state)=> { + return state.query && state.query.featureTypes && state.query.featureTypes[state.query.typeName] && state.query.featureTypes[state.query.typeName].attributes && state.query.featureTypes[state.query.typeName].attributes[0] && state.query.featureTypes[state.query.typeName].attributes[0].attribute || null; +}; /* const str2bytes = (str) => { var bytes = new Uint8Array(str.length); @@ -35,7 +41,7 @@ const str2bytes = (str) => { }; */ module.exports = { - startFeatureExportDownload: action$ => + startFeatureExportDownload: (action$, store) => action$.ofType(DOWNLOAD_FEATURES).switchMap(action => getWFSFeature({ url: action.url, @@ -52,6 +58,26 @@ module.exports = { throw xml; } } + }) + .catch( () => { + return getWFSFeature({ + url: action.url, + downloadOptions: action.downloadOptions, + filterObj: { + ...action.filterObj, + pagination: get(action, "downloadOptions.singlePage") ? action.filterObj.pagination : null, + sortOptions: getDefaultSortOptions(getFirstAttribute(store.getState())) + } + }).do(({data, headers}) => { + if (headers["content-type"] === "application/xml") { // TODO add expected mimetypes in the case you want application/dxf + let xml = String.fromCharCode.apply(null, new Uint8Array(data)); + if (xml.indexOf(" { saveAs(new Blob([data], {type: headers && headers["content-type"]}), getFileName(action)); }) .map( () => onDownloadFinished() ) From 18710eae84329c42162da51e218b6aa7395d4540 Mon Sep 17 00:00:00 2001 From: Lorenzo Natali Date: Fri, 14 Jul 2017 15:39:48 +0200 Subject: [PATCH 3/5] Fix support to Multiple result in serach services --- .../components/mapcontrols/search/SearchResult.jsx | 2 +- web/client/epics/search.js | 2 +- web/client/utils/CoordinatesUtils.js | 9 +++++++++ 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/web/client/components/mapcontrols/search/SearchResult.jsx b/web/client/components/mapcontrols/search/SearchResult.jsx index 7478197009..49ba21b0aa 100644 --- a/web/client/components/mapcontrols/search/SearchResult.jsx +++ b/web/client/components/mapcontrols/search/SearchResult.jsx @@ -47,7 +47,7 @@ class SearchResult extends React.Component { } let item = this.props.item; return ( -
+
{get(item, this.props.displayName) || generateTemplateString(this.props.displayName || "")(item) }
{this.props.subTitle && get(item, this.props.subTitle) || generateTemplateString(this.props.subTitle || "")(item) } diff --git a/web/client/epics/search.js b/web/client/epics/search.js index df8bfca364..62d20d7ec9 100644 --- a/web/client/epics/search.js +++ b/web/client/epics/search.js @@ -93,7 +93,7 @@ const searchItemSelected = action$ => // retrieve geometry from geomService or pass the item directly return Rx.Observable.fromPromise( API.Utils.getService(item.__SERVICE__.geomService.type)("", assign( {}, item.__SERVICE__.geomService.options, { staticFilter } )) - .then(res => assign({}, item, {geometry: res[0].geometry} ) ) + .then(res => assign({}, item, {geometry: CoordinatesUtils.mergeToPolyGeom(res)} ) ) ); } return Rx.Observable.of(action.item); diff --git a/web/client/utils/CoordinatesUtils.js b/web/client/utils/CoordinatesUtils.js index 68b3b5d664..471df4bf2b 100644 --- a/web/client/utils/CoordinatesUtils.js +++ b/web/client/utils/CoordinatesUtils.js @@ -389,6 +389,15 @@ const CoordinatesUtils = { } default: return []; } + }, + mergeToPolyGeom(features) { + if (features.length === 1) { + return features[0].geometry; + } + return { + type: "GeometryCollection", + geometries: features.map( ({geometry}) => geometry) + }; } }; From 0b20ddec402cc2ee866ddf497c16a8adcb847810 Mon Sep 17 00:00:00 2001 From: Lorenzo Natali Date: Wed, 2 Aug 2017 16:30:08 +0200 Subject: [PATCH 4/5] disabled pinch scale --- web/client/index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web/client/index.html b/web/client/index.html index 95510bf482..0d17b0a51d 100644 --- a/web/client/index.html +++ b/web/client/index.html @@ -3,7 +3,7 @@ - + MapStore 2 HomePage From 0a73f51ed9c29fe57446ac47bb033c04179fd64b Mon Sep 17 00:00:00 2001 From: Lorenzo Natali Date: Wed, 2 Aug 2017 17:28:23 +0200 Subject: [PATCH 5/5] updated tests to latest changes in authkey system --- web/client/libs/__tests__/ajax-test.js | 20 ++------------------ 1 file changed, 2 insertions(+), 18 deletions(-) diff --git a/web/client/libs/__tests__/ajax-test.js b/web/client/libs/__tests__/ajax-test.js index b5cb5d5fb0..6d61245249 100644 --- a/web/client/libs/__tests__/ajax-test.js +++ b/web/client/libs/__tests__/ajax-test.js @@ -50,10 +50,8 @@ const authenticationRules = [ }, { "urlPattern": ".*youhavetouseacustomone.*", - "method": { - "method": "authkey-param", - "param": "mario" - } + "authkeyParamName": "mario", + "method": "authkey" }, { "urlPattern": ".*thisismissingtheparam.*", @@ -268,20 +266,6 @@ describe('Tests ajax library', () => { }); }); - it('falls back to standard authkey if the custom one is misconfigured', (done) => { - // mocking the authentication rules and user info - expect.spyOn(SecurityUtils, 'isAuthenticationActivated').andReturn(true); - expect.spyOn(SecurityUtils, 'getAuthenticationRules').andReturn(authenticationRules); - expect.spyOn(SecurityUtils, 'getSecurityInfo').andReturn(securityInfoB); - const theExpectedString = 'authkey%3D' + securityInfoB.token; - axios.get('http://non-existent.mapstore2/thisismissingtheparam?parameter1=value1&par2=v2').then(() => { - done("Axios actually reached the fake url"); - }).catch((exception) => { - expect(exception.config).toExist().toIncludeKey('url'); - expect(exception.config.url.indexOf(theExpectedString)).toBeGreaterThan(-1); - done(); - }); - }); it('does not add autkeys if the configuration is wrong', (done) => { // mocking the authentication rules and user info