Skip to content

Commit c682d05

Browse files
authored
#1986: Restrict dataset API calls to layers from GeoNode’s catalog (#1991)
1 parent e090ff1 commit c682d05

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

geonode_mapstore_client/client/js/epics/__tests__/gnsave-test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ describe('gnsave epics', () => {
126126
mockAxios.onGet().reply(() => [200,
127127
{datasets: [{perms: ['change_dataset_style', 'change_dataset_data'], alternate: "testLayer"}]}]);
128128
const NUM_ACTIONS = 1;
129-
testEpic(gnSetDatasetsPermissions, NUM_ACTIONS, configureMap({map: {layers: [{name: "testLayer", id: "test_id"}]}}), (actions) => {
129+
testEpic(gnSetDatasetsPermissions, NUM_ACTIONS, configureMap({map: {layers: [{name: "testLayer", id: "test_id", extendedParams: {pk: "1"}}]}}), (actions) => {
130130
try {
131131
expect(actions.map(({type}) => type)).toEqual(["UPDATE_NODE"]);
132132
done();
@@ -141,7 +141,7 @@ describe('gnsave epics', () => {
141141
mockAxios.onGet().reply(() => [200,
142142
{datasets: [{perms: ['change_dataset_style', 'change_dataset_data'], alternate: "testLayer"}]}]);
143143
const NUM_ACTIONS = 1;
144-
testEpic(gnSetDatasetsPermissions, NUM_ACTIONS, addLayer({name: "testLayer"}), (actions) => {
144+
testEpic(gnSetDatasetsPermissions, NUM_ACTIONS, addLayer({name: "testLayer", pk: "1", extendedParams: {pk: "1"}}), (actions) => {
145145
try {
146146
expect(actions.map(({type}) => type)).toEqual(["UPDATE_NODE"]);
147147
done();

geonode_mapstore_client/client/js/epics/index.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,9 @@ export const gnSetDatasetsPermissions = (actions$, { getState = () => {}} = {})
9696
actions$.ofType(MAP_CONFIG_LOADED, ADD_LAYER)
9797
.switchMap((action) => {
9898
if (action.type === MAP_CONFIG_LOADED) {
99-
const layerNames = action.config?.map?.layers?.filter((l) => l?.group !== "background")?.map((l) => l.name) ?? [];
99+
let layerNames = action.config?.map?.layers?.filter((l) =>
100+
l?.group !== "background" && !!l?.extendedParams?.pk // skip layers of non-geonode origin
101+
)?.map((l) => l.name) ?? [];
100102
if (layerNames.length === 0) {
101103
return Rx.Observable.empty();
102104
}
@@ -109,6 +111,10 @@ export const gnSetDatasetsPermissions = (actions$, { getState = () => {}} = {})
109111
return Rx.Observable.of(...stateLayers.map((l) => updateNode(l.id, 'layer', {perms: l.perms || []}) ));
110112
});
111113
}
114+
115+
// skip layers of non-geonode origin
116+
if (!action.layer?.extendedParams?.pk) return Rx.Observable.empty();
117+
112118
return Rx.Observable.defer(() => getDatasetByName(action.layer?.name))
113119
.switchMap((layer = {}) => {
114120
const layerId = layersSelector(getState())?.find((la) => la.name === layer.alternate)?.id;

0 commit comments

Comments
 (0)