Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
kappu72 committed May 7, 2019
1 parent d3a2a2a commit 43252ad
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 6 deletions.
17 changes: 16 additions & 1 deletion web/client/epics/__tests__/map-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ const {
zoomToExtent
} = require('../../actions/map');

const {MAP_INFO_LOAD_START} = require('../../actions/config');
const {LOGIN_SUCCESS} = require('../../actions/security');

const {zoomToExtentEpic} = require('../map');
const {zoomToExtentEpic, checkMapPermissions} = require('../map');
const LAYOUT_STATE = {
layout: {
left: 200,
Expand All @@ -35,6 +37,7 @@ const LAYOUT_STATE = {
};
const MAP_STATE = {
projection: "EPSG:4326",
mapId: 10112,
size: { width: 400, height: 400 },
bbox: {
bounds: {
Expand Down Expand Up @@ -174,4 +177,16 @@ describe('map epics', () => {
done();
}, STATE_NORMAL);
});
it('checkMapPermissions after login', (done) => {
const dispatch = (a) => {
expect(a).toExist();
expect(a.type).toBe(MAP_INFO_LOAD_START);
done();
};
testEpic(checkMapPermissions, 1, {type: LOGIN_SUCCESS}, ([a0]) => {
expect(a0).toExist();
expect(a0).toBeA('function');
a0(dispatch);
}, STATE_NORMAL);
});
});
20 changes: 19 additions & 1 deletion web/client/epics/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ const {
ZOOM_TO_EXTENT,
changeMapView
} = require('../actions/map');
const {mapSelector} = require('../selectors/map');
const {mapSelector, mapIdSelector} = require('../selectors/map');

const { loadMapInfo} = require('../actions/config');
const {LOGIN_SUCCESS} = require('../actions/security');

const {currentBackgroundLayerSelector, allBackgroundLayerSelector, getLayerFromId} = require('../selectors/layers');
const {mapTypeSelector} = require('../selectors/maptype');
Expand All @@ -31,6 +34,8 @@ const {clearLayers} = require('../actions/layers');
const {removeAllAdditionalLayers} = require('../actions/additionallayers');
const { head, isArray, isObject, mapValues } = require('lodash');

const ConfigUtils = require('../utils/ConfigUtils');

const handleCreationBackgroundError = (action$, store) =>
action$.ofType(CREATION_ERROR_LAYER)
// added delay because the CREATION_ERROR_LAYER needs to be initialized after MAP_CONFIG_LOADED
Expand Down Expand Up @@ -178,7 +183,20 @@ const zoomToExtentEpic = (action$, {getState = () => {} }) =>
}
return legacyZoomToExtent({...action, extent}, mapSelector(getState()) );
});
/**
* It checks user's permissions on current map on LOGIN_SUCCESS event
* @memberof epics.map
* @param {object} action$
*/
const checkMapPermissions = (action$, {getState = () => {} }) =>
action$.ofType(LOGIN_SUCCESS)
.map(() => {
const mapId = mapIdSelector(getState());
return loadMapInfo(ConfigUtils.getConfigProp("geoStoreUrl") + "extjs/resource/" + mapId, mapId);
});

module.exports = {
checkMapPermissions,
handleCreationLayerError,
handleCreationBackgroundError,
resetMapOnInit,
Expand Down
4 changes: 0 additions & 4 deletions web/client/plugins/SaveAs.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ const {createSelector, createStructuredSelector} = require('reselect');
const assign = require('object-assign');
const {Glyphicon} = require('react-bootstrap');
const Message = require('../components/I18N/Message');
const {loadMapInfo} = require('../actions/config');
const MetadataModal = require('../components/maps/modals/MetadataModal');
const {saveMapResource, createThumbnail, onDisplayMetadataEdit, metadataChanged} = require('../actions/maps');
const {editMap, updateCurrentMap, errorCurrentMap, resetCurrentMap} = require('../actions/currentMap');
Expand Down Expand Up @@ -74,7 +73,6 @@ class SaveAs extends React.Component {
resetCurrentMap: PropTypes.func,
metadataChanged: PropTypes.func,
onMapSave: PropTypes.func,
loadMapInfo: PropTypes.func,
textSearchConfig: PropTypes.object
};

Expand All @@ -86,7 +84,6 @@ class SaveAs extends React.Component {
additionalOptions: {},
onMapSave: () => {},
onDisplayMetadataEdit: () => {},
loadMapInfo: () => {},
show: false
};

Expand Down Expand Up @@ -173,7 +170,6 @@ module.exports = {
onUpdateCurrentMap: updateCurrentMap,
onErrorCurrentMap: errorCurrentMap,
onMapSave: saveMapResource,
loadMapInfo,
metadataChanged,
editMap,
resetCurrentMap,
Expand Down

0 comments on commit 43252ad

Please sign in to comment.