Skip to content

Commit 26e3333

Browse files
committed
Merge branch 'master' into map_widget
2 parents b04ab28 + ebb2dd1 commit 26e3333

11 files changed

Lines changed: 179 additions & 34 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@
122122
"leaflet.locatecontrol": "0.62.0",
123123
"leaflet.nontiledlayer": "1.0.7",
124124
"lodash": "4.16.6",
125-
"moment": "2.13.0",
125+
"moment": "2.21.0",
126126
"node-geo-distance": "1.2.0",
127127
"object-assign": "4.1.1",
128128
"ogc-schemas": "2.6.1",

project/custom/templates/web/src/main/resources/sample_categories.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,7 @@
66
<Category>
77
<name>THUMBNAIL</name>
88
</Category>
9+
<Category>
10+
<name>DETAILS</name>
11+
</Category>
912
</CategoryList>

project/standard/templates/web/src/main/resources/sample_categories.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,7 @@
66
<Category>
77
<name>THUMBNAIL</name>
88
</Category>
9+
<Category>
10+
<name>DETAILS</name>
11+
</Category>
912
</CategoryList>

web/client/api/GeoStoreDAO.js

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -162,28 +162,31 @@ const Api = {
162162
}
163163
}, options)));
164164
},
165-
updateResourcePermissions: function(resourceId, securityRules) {
166-
let payload = "<SecurityRuleList>";
167-
for (let rule of securityRules.SecurityRuleList.SecurityRule) {
165+
writeSecurityRules: function(SecurityRuleList = {}) {
166+
return "<SecurityRuleList>" +
167+
(_.castArray(SecurityRuleList.SecurityRule) || []).map( rule => {
168168
if (rule.canRead || rule.canWrite) {
169169
if (rule.user) {
170-
payload = payload + "<SecurityRule>";
171-
payload = payload + "<canRead>" + boolToString(rule.canRead || rule.canWrite) + "</canRead>";
172-
payload = payload + "<canWrite>" + boolToString(rule.canWrite) + "</canWrite>";
173-
payload = payload + "<user><id>" + (rule.user.id || "") + "</id><name>" + (rule.user.name || "") + "</name></user>";
174-
payload = payload + "</SecurityRule>";
170+
return "<SecurityRule>"
171+
+ "<canRead>" + boolToString(rule.canRead || rule.canWrite) + "</canRead>"
172+
+ "<canWrite>" + boolToString(rule.canWrite) + "</canWrite>"
173+
+ "<user><id>" + (rule.user.id || "") + "</id><name>" + (rule.user.name || "") + "</name></user>"
174+
+ "</SecurityRule>";
175175
} else if (rule.group) {
176-
payload = payload + "<SecurityRule>";
177-
payload = payload + "<canRead>" + boolToString(rule.canRead || rule.canWrite) + "</canRead>";
178-
payload = payload + "<canWrite>" + boolToString(rule.canWrite) + "</canWrite>";
179-
payload = payload + "<group><id>" + (rule.group.id || "") + "</id><groupName>" + (rule.group.groupName || "") + "</groupName></group>";
180-
payload = payload + "</SecurityRule>";
176+
return "<SecurityRule>"
177+
+ "<canRead>" + boolToString(rule.canRead || rule.canWrite) + "</canRead>"
178+
+ "<canWrite>" + boolToString(rule.canWrite) + "</canWrite>"
179+
+ "<group><id>" + (rule.group.id || "") + "</id><groupName>" + (rule.group.groupName || "") + "</groupName></group>"
180+
+ "</SecurityRule>";
181181
}
182+
return "";
182183
// NOTE: if rule has no group or user, it is skipped
183184
// NOTE: if rule is "no read and no write", it is skipped
184185
}
185-
}
186-
payload = payload + "</SecurityRuleList>";
186+
}).join('') + "</SecurityRuleList>";
187+
},
188+
updateResourcePermissions: function(resourceId, securityRules) {
189+
const payload = Api.writeSecurityRules(securityRules.SecurityRuleList);
187190
return axios.post(
188191
"resources/resource/" + resourceId + "/permissions",
189192
payload,

web/client/api/__tests__/GeoStoreDAO-test.jsx

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,62 @@
88

99
const expect = require('expect');
1010
const API = require('../GeoStoreDAO');
11+
const SAMPLE_RULES = {
12+
"SecurityRuleList": {
13+
"SecurityRule": [
14+
{
15+
"canRead": true,
16+
"canWrite": true,
17+
"user": {
18+
"id": 3,
19+
"name": "admin"
20+
}
21+
},
22+
{
23+
"canRead": true,
24+
"canWrite": true,
25+
"group": {
26+
"groupName": "geosolutions",
27+
"id": 524
28+
}
29+
},
30+
{
31+
"canRead": true,
32+
"canWrite": false,
33+
"group": {
34+
"groupName": "testers",
35+
"id": 3956
36+
}
37+
}
38+
]
39+
}
40+
};
41+
const SAMPLE_XML_RULES = "<SecurityRuleList>"
42+
+ "<SecurityRule>"
43+
+ "<canRead>true</canRead>"
44+
+ "<canWrite>true</canWrite>"
45+
+ "<user>"
46+
+ "<id>3</id>"
47+
+ "<name>admin</name>"
48+
+ "</user>"
49+
+ "</SecurityRule>"
50+
+ "<SecurityRule>"
51+
+ "<canRead>true</canRead>"
52+
+ "<canWrite>true</canWrite>"
53+
+ "<group>"
54+
+ "<id>524</id>"
55+
+ "<groupName>geosolutions</groupName>"
56+
+ "</group>"
57+
+ "</SecurityRule>"
58+
+ "<SecurityRule>"
59+
+ "<canRead>true</canRead>"
60+
+ "<canWrite>false</canWrite>"
61+
+ "<group>"
62+
+ "<id>3956</id>"
63+
+ "<groupName>testers</groupName>"
64+
+ "</group>"
65+
+ "</SecurityRule>"
66+
+ "</SecurityRuleList>";
1167

1268
describe('Test correctness of the GeoStore APIs', () => {
1369

@@ -34,7 +90,6 @@ describe('Test correctness of the GeoStore APIs', () => {
3490
const user2 = API.utils.initUser(originalUser2);
3591
expect(user2.attribute.length).toBe(2);
3692
});
37-
3893
it('test error parser', () => {
3994
expect(API.errorParser.mapsError({status: 409})).toEqual({
4095
title: 'map.mapError.errorTitle',
@@ -45,4 +100,8 @@ describe('Test correctness of the GeoStore APIs', () => {
45100
message: 'map.mapError.errorDefault'
46101
});
47102
});
103+
it('test security rules utils (writeSecurityRules)', () => {
104+
const payload = API.writeSecurityRules(SAMPLE_RULES.SecurityRuleList);
105+
expect(payload).toBe(SAMPLE_XML_RULES);
106+
});
48107
});

web/client/components/map/leaflet/Map.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ class LeafletMap extends React.Component {
231231

232232
componentWillUnmount() {
233233
const attributionContainer = this.props.mapOptions.attribution && this.props.mapOptions.attribution.container && document.querySelector(this.props.mapOptions.attribution.container);
234-
if (attributionContainer && attributionContainer.querySelector('.leaflet-control-attribution')) {
234+
if (attributionContainer && this.attribution.getContainer() && attributionContainer.querySelector('.leaflet-control-attribution')) {
235235
attributionContainer.removeChild(this.attribution.getContainer());
236236
}
237237
this.map.remove();

web/client/components/map/leaflet/__tests__/Map-test.jsx

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,20 @@ require('../plugins/OSMLayer');
2020

2121
describe('LeafletMap', () => {
2222

23-
beforeEach((done) => {
23+
beforeEach(() => {
2424
document.body.innerHTML = '<div id="container"></div>';
25-
setTimeout(done);
2625
});
27-
afterEach((done) => {
28-
ReactDOM.unmountComponentAtNode(document.getElementById("container"));
29-
document.body.innerHTML = '';
30-
setTimeout(done);
26+
afterEach(() => {
27+
try {
28+
ReactDOM.unmountComponentAtNode(document.getElementById("container"));
29+
const attributions = document.body.getElementsByClassName('leaflet-control-attribution');
30+
if (attributions.length > 0) {
31+
document.body.removeChild(attributions[0]);
32+
}
33+
document.body.innerHTML = '';
34+
} catch(e) {
35+
// ignore
36+
}
3137
});
3238

3339
it('creates a div for leaflet map with given id', () => {
@@ -325,6 +331,7 @@ describe('LeafletMap', () => {
325331
let attributions = domMap.getElementsByClassName('leaflet-control-attribution');
326332
expect(attributions.length).toBe(0);
327333
attributions = document.body.getElementsByClassName('leaflet-control-attribution');
334+
expect(attributions.length).toBe(1);
328335
document.body.removeChild(attributions[0]);
329336
attributions = document.body.getElementsByClassName('leaflet-control-attribution');
330337
expect(attributions.length).toBe(0);

web/client/components/map/openlayers/DrawSupport.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ class DrawSupport extends React.Component {
152152

153153
replaceFeatures = (newProps) => {
154154
if (!this.drawLayer) {
155-
this.addLayer(newProps, true);
155+
this.addLayer(newProps, newProps.options && newProps.options.drawEnabled || false);
156156
} else {
157157
this.drawSource.clear();
158158
this.addFeatures(newProps);

web/client/components/map/openlayers/__tests__/DrawSupport-test.jsx

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -593,6 +593,80 @@ describe('Test DrawSupport', () => {
593593
expect(spyAddFeature.calls.length).toBe(1);
594594
});
595595

596+
it('replace features no draw interaction', () => {
597+
const fakeMap = {
598+
addLayer: () => {},
599+
disableEventListener: () => {},
600+
enableEventListener: () => {},
601+
addInteraction: () => {},
602+
removeInteraction: () => {},
603+
getInteractions: () => ({
604+
getLength: () => 0
605+
}),
606+
getView: () => ({
607+
getProjection: () => ({
608+
getCode: () => 'EPSG:4326'
609+
})
610+
})
611+
};
612+
const feature = {
613+
type: 'Feature',
614+
geometry: {
615+
type: 'LineString',
616+
coordinates: [[13, 43], [14, 44]]
617+
},
618+
properties: {
619+
'name': "some name"
620+
}
621+
};
622+
623+
const support = ReactDOM.render(
624+
<DrawSupport features={[]} map={fakeMap}/>, document.getElementById("container"));
625+
expect(support).toExist();
626+
const spyAddInteraction = expect.spyOn(support, "addInteractions");
627+
ReactDOM.render(
628+
<DrawSupport features={[feature]} map={fakeMap} drawStatus="replace" drawMethod="MultiLineString" options={{drawEnabled: false}}
629+
/>, document.getElementById("container"));
630+
expect(spyAddInteraction.calls.length).toBe(0);
631+
});
632+
633+
it('replace features with draw interaction', () => {
634+
const fakeMap = {
635+
addLayer: () => {},
636+
disableEventListener: () => {},
637+
enableEventListener: () => {},
638+
addInteraction: () => {},
639+
removeInteraction: () => {},
640+
getInteractions: () => ({
641+
getLength: () => 0
642+
}),
643+
getView: () => ({
644+
getProjection: () => ({
645+
getCode: () => 'EPSG:4326'
646+
})
647+
})
648+
};
649+
const feature = {
650+
type: 'Feature',
651+
geometry: {
652+
type: 'LineString',
653+
coordinates: [[13, 43], [14, 44]]
654+
},
655+
properties: {
656+
'name': "some name"
657+
}
658+
};
659+
660+
const support = ReactDOM.render(
661+
<DrawSupport features={[]} map={fakeMap}/>, document.getElementById("container"));
662+
expect(support).toExist();
663+
const spyAddInteraction = expect.spyOn(support, "addInteractions");
664+
ReactDOM.render(
665+
<DrawSupport features={[feature]} map={fakeMap} drawStatus="replace" drawMethod="MultiLineString" options={{drawEnabled: true}}
666+
/>, document.getElementById("container"));
667+
expect(spyAddInteraction.calls.length).toBe(1);
668+
});
669+
596670
it('replace features circle', () => {
597671
const fakeMap = {
598672
addLayer: () => {},

web/client/components/map/openlayers/plugins/TileProviderLayer.js

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,11 @@ function template(str, data) {
2929
});
3030
}
3131
function getUrls(opt) {
32-
let urls = [];
3332
let url = opt.url;
3433
if (opt.subdomains) {
35-
for (let c of opt.subdomains) {
36-
urls.push(template(url.replace("{s}", c), opt));
37-
}
38-
} else {
39-
for (let c of 'abc') {
40-
urls.push(template(url.replace("{s}", c), opt));
41-
}
34+
return opt.subdomains.map( c => template(url.replace("{s}", c), opt));
4235
}
43-
return urls;
36+
return ['a', 'b', 'c'].map( c => template(url.replace("{s}", c), opt));
4437
}
4538
/*eslint-disable */
4639
function lBoundsToOlExtent(bounds, destPrj){

0 commit comments

Comments
 (0)