Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #2773. First rules-editor implementation #2845

Merged
merged 14 commits into from
Apr 27, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docma-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@
"web/client/plugins/WFSDownload.jsx",
"web/client/plugins/ZoomIn.jsx",
"web/client/plugins/ZoomOut.jsx"
]
]
},
"./docs/**/*md",
{
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@
"react-container-dimensions": "1.3.2",
"react-copy-to-clipboard": "5.0.0",
"react-data-grid": "2.0.59",
"react-data-grid-addons": "3.0.11",
"react-dnd": "2.4.0",
"react-dnd-html5-backend": "2.4.1",
"react-dock": "0.2.4",
Expand Down
39 changes: 36 additions & 3 deletions web/client/actions/__tests__/rulesmanager-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,44 @@ const expect = require('expect');
const { RULES_SELECTED, RULES_LOADED, UPDATE_ACTIVE_RULE,
ACTION_ERROR, OPTIONS_LOADED, UPDATE_FILTERS_VALUES,
rulesSelected, rulesLoaded, updateActiveRule,
actionError, optionsLoaded, updateFiltersValues} = require('../rulesmanager');
actionError, optionsLoaded, updateFiltersValues,
SET_FILTER, setFilter,
SAVE_RULE, saveRule, cleanEditing, CLEAN_EDITING,
onEditRule, EDIT_RULE, delRules, DELETE_RULES} = require('../rulesmanager');

describe('test rules manager actions', () => {

it('rules slected', () => {
it('save rule', () => {
const rule = {};
const action = saveRule(rule);
expect(action).toExist();
expect(action.type).toBe(SAVE_RULE);
expect(action.rule).toBe(rule);
});
it('clean editing', () => {
const action = cleanEditing();
expect(action).toExist();
expect(action.type).toBe(CLEAN_EDITING);
});
it('on edit rule', () => {
const action = onEditRule();
expect(action).toExist();
expect(action.type).toBe(EDIT_RULE);
expect(action.createNew).toBe(false);
expect(action.targetPriority).toBe(0);
});
it('delete rules', () => {
const action = delRules();
expect(action).toExist();
expect(action.type).toBe(DELETE_RULES);
});
it('set Filter', () => {
const action = setFilter("key", "value");
expect(action).toExist();
expect(action.type).toBe(SET_FILTER);
expect(action.key).toBe("key");
expect(action.value).toBe("value");
});
it('rules selected', () => {
const rules = [
{ id: "rules1" },
{ id: "rules2" }
Expand Down
62 changes: 57 additions & 5 deletions web/client/actions/rulesmanager.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,57 @@ const UPDATE_ACTIVE_RULE = 'UPDATE_ACTIVE_RULE';
const UPDATE_FILTERS_VALUES = 'UPDATE_FILTERS_VALUES';
const ACTION_ERROR = 'ACTION_ERROR';
const OPTIONS_LOADED = 'OPTIONS_LOADED';
const LOADING = 'RULES_MANAGER:LOADING';
const SET_FILTER = "RULES_MANAGER:SET_FILTER";
const EDIT_RULE = "RULES_MANAGER:EDIT_RULE";
const CLEAN_EDITING = "RULES_MANAGER:CLEAN_EDITING";
const SAVE_RULE = "RULES_MANAGER:SAVE_RULE";
const RULE_SAVED = "RULES_MANAGER:RULE_SAVED";
const DELETE_RULES = "RULES_MANAGER: DELETE_RULES";

function rulesSelected(rules, merge, unselect) {
function delRules(ids) {
return {
type: DELETE_RULES,
ids
};
}

function setFilter(key, value) {
return {
type: SET_FILTER,
key,
value
};
}

function onEditRule(targetPriority = 0, createNew = false) {
return {
type: EDIT_RULE,
createNew,
targetPriority
};
}

function cleanEditing() {
return {
type: CLEAN_EDITING
};
}

function setLoading(loading) {
return {
type: LOADING,
loading
};
}

function rulesSelected(rules, merge, unselect, targetPosition) {
return {
type: RULES_SELECTED,
rules: rules,
merge: merge,
unselect: unselect
rules,
merge,
unselect,
targetPosition
};
}

Expand Down Expand Up @@ -203,6 +247,8 @@ function updateRule() {
};
}

const saveRule = (rule) => ({type: SAVE_RULE, rule});

module.exports = {
RULES_SELECTED,
RULES_LOADED,
Expand All @@ -225,5 +271,11 @@ module.exports = {
loadWorkspaces,
loadLayers,
actionError,
optionsLoaded
optionsLoaded,
LOADING, setLoading,
SET_FILTER, setFilter,
EDIT_RULE, onEditRule,
CLEAN_EDITING, cleanEditing,
SAVE_RULE, saveRule, RULE_SAVED,
DELETE_RULES, delRules
};
118 changes: 82 additions & 36 deletions web/client/api/geoserver/GeoFence.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,27 @@ const axios = require('../../libs/ajax');
const assign = require('object-assign');

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

const EMPTY_RULE = {
constraints: {},
ipaddress: "",
layer: "",
request: "",
rolename: "",
service: "",
username: "",
workspace: ""
};
var Api = {

loadRules: function(rulesPage, rulesFiltersValues) {
const options = {
'params': {
'page': rulesPage - 1,
'entries': 10
}
loadRules: function(page, rulesFiltersValues, entries = 10) {
const params = {
page,
entries,
...this.assignFiltersValue(rulesFiltersValues)
};
this.assignFiltersValue(rulesFiltersValues, options);
const options = {params, 'headers': {
'Content': 'application/json'
}};
return axios.get('geofence/rest/rules', this.addBaseUrl(options))
.then(function(response) {
return response.data;
Expand All @@ -30,9 +40,8 @@ var Api = {

getRulesCount: function(rulesFiltersValues) {
const options = {
'params': {}
'params': this.assignFiltersValue(rulesFiltersValues)
};
this.assignFiltersValue(rulesFiltersValues, options);
return axios.get('geofence/rest/rules/count', this.addBaseUrl(options)).then(function(response) {
return response.data;
});
Expand All @@ -55,40 +64,50 @@ var Api = {
},

addRule: function(rule) {
if (!rule.access) {
rule.access = "ALLOW";
const newRule = {...rule};
if (!newRule.instance) {
const {id: instanceId} = ConfigUtils.getDefaults().geoFenceGeoServerInstance;
newRule.instance = {id: instanceId};
}
if (!newRule.grant) {
newRule.grant = "ALLOW";
}
return axios.post('geofence/rest/rules', rule, this.addBaseUrl({
return axios.post('geofence/rest/rules', newRule, this.addBaseUrl({
'headers': {
'Content': 'application/json'
}
}));
},

updateRule: function(rule) {
return axios.post('geofence/rest/rules/id/' + rule.id, rule, this.addBaseUrl({
// id, priority and grant aren't updatable
const {id, priority, grant, position, ...others} = rule;
const newRule = {...EMPTY_RULE, ...others};
return axios.put(`geofence/rest/rules/id/${id}`, newRule, this.addBaseUrl({
'headers': {
'Content': 'application/json'
}
}));
},

assignFiltersValue: function(rulesFiltersValues, options) {
if (rulesFiltersValues) {
assign(options.params, {"userName": this.normalizeFilterValue(rulesFiltersValues.userName)});
assign(options.params, {"roleName": this.normalizeFilterValue(rulesFiltersValues.roleName)});
assign(options.params, {"service": this.normalizeFilterValue(rulesFiltersValues.service)});
assign(options.params, {"request": this.normalizeFilterValue(rulesFiltersValues.request)});
assign(options.params, {"workspace": this.normalizeFilterValue(rulesFiltersValues.workspace)});
assign(options.params, {"layer": this.normalizeFilterValue(rulesFiltersValues.layer)});
}
return options;
assignFiltersValue: function(rulesFiltersValues = {}) {
return Object.keys(rulesFiltersValues).map(key => ({key, normKey: this.normalizeKey(key)}))
.reduce((params, {key, normKey}) => ({...params, [normKey]: this.normalizeFilterValue(rulesFiltersValues[key])}), {});
},

normalizeFilterValue(value) {
return value === "*" ? undefined : value;
},

normalizeKey(key) {
switch (key) {
case 'username':
return 'userName';
case 'rolename':
return 'groupName';
default:
return key;
}
},
assignFilterValue: function(queryParameters, filterName, filterAny, filterValue) {
if (!filterValue) {
return;
Expand All @@ -99,29 +118,52 @@ var Api = {
assign(queryParameters, {[filterName]: filterValue});
}
},

getGroups: function() {
return axios.get('security/rest/roles', this.addBaseUrl({
getGroupsCount: function(filter = " ") {
const encodedFilter = encodeURIComponent(`%${filter}%`);
return axios.get(`geofence/rest/groups/count/${encodedFilter}`, this.addBaseUrl({
'headers': {
'Accept': 'application/json'
'Accept': 'text/plain'
}
})).then(function(response) {
return response.data;
});
},

getUsers: function() {
return axios.get('security/rest/usergroup/users', this.addBaseUrl({
getGroups: function(filter, page, entries = 10) {
const params = {
page,
entries,
nameLike: `%${filter}%`
};
const options = {params};
return axios.get(`geofence/rest/groups`, this.addBaseUrl(options)).then(function(response) {
return response.data;
});
},
getUsersCount: function(filter = " ") {
const encodedFilter = encodeURIComponent(`%${filter}%`);
return axios.get(`geofence/rest/users/count/${encodedFilter}`, this.addBaseUrl({
'headers': {
'Accept': 'application/json'
'Accept': 'text/plain'
}
})).then(function(response) {
return response.data;
});
},

getUsers: function(filter, page, entries = 10) {
const params = {
page,
entries,
nameLike: `%${filter}%`
};
const options = {params};
return axios.get(`geofence/rest/users`, this.addBaseUrl(options)).then(function(response) {
return response.data;
});
},

getWorkspaces: function() {
return axios.get('rest/workspaces', this.addBaseUrl({
return axios.get('rest/workspaces', this.addBaseUrlGS({
'headers': {
'Accept': 'application/json'
}
Expand All @@ -134,8 +176,12 @@ var Api = {
return !value ? '*' : value;
},

addBaseUrl: function(options) {
return assign(options, {baseURL: ConfigUtils.getDefaults().geoServerUrl});
addBaseUrl: function(options = {}) {
return assign(options, {baseURL: ConfigUtils.getDefaults().geoFenceUrl});
},
addBaseUrlGS: function(options = {}) {
const {url: baseURL} = ConfigUtils.getDefaults().geoFenceGeoServerInstance || {};
return assign(options, {baseURL});
}
};

Expand Down
1 change: 1 addition & 0 deletions web/client/components/data/grid/DataGrid.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class DataGrid extends Grid {
componentWillUnmount() {
if (this.canvas) {
this.canvas.removeEventListener('scroll', this.scrollListener);
this.canvas = null;
}
if (this.props.displayFilters) {
this.onToggleFilter();
Expand Down
Loading