Skip to content

Commit

Permalink
Fix #2685. Removed for of statements (#2714)
Browse files Browse the repository at this point in the history
  • Loading branch information
offtherailz authored Mar 7, 2018
1 parent dece305 commit 956845f
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 25 deletions.
33 changes: 18 additions & 15 deletions web/client/api/GeoStoreDAO.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,28 +162,31 @@ const Api = {
}
}, options)));
},
updateResourcePermissions: function(resourceId, securityRules) {
let payload = "<SecurityRuleList>";
for (let rule of securityRules.SecurityRuleList.SecurityRule) {
writeSecurityRules: function(SecurityRuleList = {}) {
return "<SecurityRuleList>" +
(_.castArray(SecurityRuleList.SecurityRule) || []).map( rule => {
if (rule.canRead || rule.canWrite) {
if (rule.user) {
payload = payload + "<SecurityRule>";
payload = payload + "<canRead>" + boolToString(rule.canRead || rule.canWrite) + "</canRead>";
payload = payload + "<canWrite>" + boolToString(rule.canWrite) + "</canWrite>";
payload = payload + "<user><id>" + (rule.user.id || "") + "</id><name>" + (rule.user.name || "") + "</name></user>";
payload = payload + "</SecurityRule>";
return "<SecurityRule>"
+ "<canRead>" + boolToString(rule.canRead || rule.canWrite) + "</canRead>"
+ "<canWrite>" + boolToString(rule.canWrite) + "</canWrite>"
+ "<user><id>" + (rule.user.id || "") + "</id><name>" + (rule.user.name || "") + "</name></user>"
+ "</SecurityRule>";
} else if (rule.group) {
payload = payload + "<SecurityRule>";
payload = payload + "<canRead>" + boolToString(rule.canRead || rule.canWrite) + "</canRead>";
payload = payload + "<canWrite>" + boolToString(rule.canWrite) + "</canWrite>";
payload = payload + "<group><id>" + (rule.group.id || "") + "</id><groupName>" + (rule.group.groupName || "") + "</groupName></group>";
payload = payload + "</SecurityRule>";
return "<SecurityRule>"
+ "<canRead>" + boolToString(rule.canRead || rule.canWrite) + "</canRead>"
+ "<canWrite>" + boolToString(rule.canWrite) + "</canWrite>"
+ "<group><id>" + (rule.group.id || "") + "</id><groupName>" + (rule.group.groupName || "") + "</groupName></group>"
+ "</SecurityRule>";
}
return "";
// NOTE: if rule has no group or user, it is skipped
// NOTE: if rule is "no read and no write", it is skipped
}
}
payload = payload + "</SecurityRuleList>";
}).join('') + "</SecurityRuleList>";
},
updateResourcePermissions: function(resourceId, securityRules) {
const payload = Api.writeSecurityRules(securityRules.SecurityRuleList);
return axios.post(
"resources/resource/" + resourceId + "/permissions",
payload,
Expand Down
61 changes: 60 additions & 1 deletion web/client/api/__tests__/GeoStoreDAO-test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,62 @@

const expect = require('expect');
const API = require('../GeoStoreDAO');
const SAMPLE_RULES = {
"SecurityRuleList": {
"SecurityRule": [
{
"canRead": true,
"canWrite": true,
"user": {
"id": 3,
"name": "admin"
}
},
{
"canRead": true,
"canWrite": true,
"group": {
"groupName": "geosolutions",
"id": 524
}
},
{
"canRead": true,
"canWrite": false,
"group": {
"groupName": "testers",
"id": 3956
}
}
]
}
};
const SAMPLE_XML_RULES = "<SecurityRuleList>"
+ "<SecurityRule>"
+ "<canRead>true</canRead>"
+ "<canWrite>true</canWrite>"
+ "<user>"
+ "<id>3</id>"
+ "<name>admin</name>"
+ "</user>"
+ "</SecurityRule>"
+ "<SecurityRule>"
+ "<canRead>true</canRead>"
+ "<canWrite>true</canWrite>"
+ "<group>"
+ "<id>524</id>"
+ "<groupName>geosolutions</groupName>"
+ "</group>"
+ "</SecurityRule>"
+ "<SecurityRule>"
+ "<canRead>true</canRead>"
+ "<canWrite>false</canWrite>"
+ "<group>"
+ "<id>3956</id>"
+ "<groupName>testers</groupName>"
+ "</group>"
+ "</SecurityRule>"
+ "</SecurityRuleList>";

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

Expand All @@ -34,7 +90,6 @@ describe('Test correctness of the GeoStore APIs', () => {
const user2 = API.utils.initUser(originalUser2);
expect(user2.attribute.length).toBe(2);
});

it('test error parser', () => {
expect(API.errorParser.mapsError({status: 409})).toEqual({
title: 'map.mapError.errorTitle',
Expand All @@ -45,4 +100,8 @@ describe('Test correctness of the GeoStore APIs', () => {
message: 'map.mapError.errorDefault'
});
});
it('test security rules utils (writeSecurityRules)', () => {
const payload = API.writeSecurityRules(SAMPLE_RULES.SecurityRuleList);
expect(payload).toBe(SAMPLE_XML_RULES);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,11 @@ function template(str, data) {
});
}
function getUrls(opt) {
let urls = [];
let url = opt.url;
if (opt.subdomains) {
for (let c of opt.subdomains) {
urls.push(template(url.replace("{s}", c), opt));
}
} else {
for (let c of 'abc') {
urls.push(template(url.replace("{s}", c), opt));
}
return opt.subdomains.map( c => template(url.replace("{s}", c), opt));
}
return urls;
return ['a', 'b', 'c'].map( c => template(url.replace("{s}", c), opt));
}
/*eslint-disable */
function lBoundsToOlExtent(bounds, destPrj){
Expand Down

0 comments on commit 956845f

Please sign in to comment.