2017-11-07 14:32:31 +01:00
|
|
|
/*
|
|
|
|
|
*
|
|
|
|
|
* EditPage actions
|
|
|
|
|
*
|
|
|
|
|
*/
|
2017-11-15 15:11:10 +01:00
|
|
|
import { fromJS, List, Map } from 'immutable';
|
2017-11-30 15:01:19 +01:00
|
|
|
import { get, replace } from 'lodash';
|
2017-11-07 14:32:31 +01:00
|
|
|
import {
|
2017-11-07 18:16:42 +01:00
|
|
|
ADD_USER,
|
2017-11-15 15:11:10 +01:00
|
|
|
GET_PERMISSIONS,
|
|
|
|
|
GET_PERMISSIONS_SUCCEEDED,
|
2017-11-30 11:07:54 +01:00
|
|
|
GET_POLICIES,
|
|
|
|
|
GET_POLICIES_SUCCEEDED,
|
2017-11-15 14:00:51 +01:00
|
|
|
GET_ROLE,
|
|
|
|
|
GET_ROLE_SUCCEEDED,
|
2017-11-30 16:34:43 +01:00
|
|
|
GET_ROUTES_SUCCEEDED,
|
2017-11-23 12:43:40 +01:00
|
|
|
GET_USER,
|
|
|
|
|
GET_USER_SUCCEEDED,
|
2017-11-07 16:33:15 +01:00
|
|
|
ON_CANCEL,
|
|
|
|
|
ON_CHANGE_INPUT,
|
2017-11-23 13:09:05 +01:00
|
|
|
ON_CLICK_ADD,
|
2017-11-07 18:16:42 +01:00
|
|
|
ON_CLICK_DELETE,
|
2017-11-30 12:10:23 +01:00
|
|
|
RESET_SHOULD_DISPLAY_POLICIES_HINT,
|
2017-11-29 18:51:56 +01:00
|
|
|
SELECT_ALL_ACTIONS,
|
2017-11-23 12:15:06 +01:00
|
|
|
SET_ACTION_TYPE,
|
|
|
|
|
SET_ERRORS,
|
2017-11-15 14:00:51 +01:00
|
|
|
SET_FORM,
|
2017-11-30 15:01:19 +01:00
|
|
|
SET_INPUT_POLICIES_PATH,
|
2017-11-23 17:13:46 +01:00
|
|
|
SET_ROLE_ID,
|
2017-11-30 12:10:23 +01:00
|
|
|
SET_SHOULD_DISPLAY_POLICIES_HINT,
|
2017-11-23 12:15:06 +01:00
|
|
|
SUBMIT,
|
|
|
|
|
SUBMIT_ERROR,
|
|
|
|
|
SUBMIT_SUCCEEDED,
|
2017-11-07 14:32:31 +01:00
|
|
|
} from './constants';
|
|
|
|
|
|
2017-11-07 18:16:42 +01:00
|
|
|
export function addUser(newUser) {
|
|
|
|
|
return {
|
|
|
|
|
type: ADD_USER,
|
|
|
|
|
newUser,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-15 15:11:10 +01:00
|
|
|
export function getPermissions() {
|
|
|
|
|
return {
|
|
|
|
|
type: GET_PERMISSIONS,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function getPermissionsSucceeded(data) {
|
|
|
|
|
const permissions = Map(fromJS(data.permissions));
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
type: GET_PERMISSIONS_SUCCEEDED,
|
|
|
|
|
permissions,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-30 11:07:54 +01:00
|
|
|
|
|
|
|
|
export function getPolicies() {
|
|
|
|
|
return {
|
|
|
|
|
type: GET_POLICIES,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function getPoliciesSucceeded(policies) {
|
2017-11-30 15:01:19 +01:00
|
|
|
const formattedPolicies = policies.policies.reduce((acc, current) => {
|
|
|
|
|
acc.push({ value: current });
|
|
|
|
|
|
|
|
|
|
return acc;
|
|
|
|
|
},[]);
|
|
|
|
|
|
2017-11-30 11:07:54 +01:00
|
|
|
return {
|
|
|
|
|
type: GET_POLICIES_SUCCEEDED,
|
2017-11-30 15:01:19 +01:00
|
|
|
policies: [{ name: 'users-permissions.Policies.InputSelect.empty', value: '' }].concat(formattedPolicies),
|
2017-11-30 11:07:54 +01:00
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-15 15:11:10 +01:00
|
|
|
export function getRole(id) {
|
2017-11-15 14:00:51 +01:00
|
|
|
return {
|
|
|
|
|
type: GET_ROLE,
|
2017-11-15 15:11:10 +01:00
|
|
|
id,
|
2017-11-15 14:00:51 +01:00
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function getRoleSucceeded(data) {
|
2017-11-15 15:11:10 +01:00
|
|
|
const form = Map({
|
|
|
|
|
name: get(data, ['role', 'name']),
|
|
|
|
|
description: get(data, ['role', 'description']),
|
|
|
|
|
users: List(get(data, ['role', 'users'])),
|
|
|
|
|
permissions: Map(fromJS(get(data, ['role', 'permissions']))),
|
|
|
|
|
});
|
|
|
|
|
|
2017-11-15 14:00:51 +01:00
|
|
|
return {
|
|
|
|
|
type: GET_ROLE_SUCCEEDED,
|
2017-11-15 15:11:10 +01:00
|
|
|
form,
|
2017-11-15 14:00:51 +01:00
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-30 16:34:43 +01:00
|
|
|
export function getRoutesSucceeded(routes) {
|
|
|
|
|
return {
|
|
|
|
|
type: GET_ROUTES_SUCCEEDED,
|
|
|
|
|
routes,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-23 12:43:40 +01:00
|
|
|
export function getUser(user) {
|
|
|
|
|
return {
|
|
|
|
|
type: GET_USER,
|
|
|
|
|
user,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function getUserSucceeded(users) {
|
|
|
|
|
return {
|
|
|
|
|
type: GET_USER_SUCCEEDED,
|
|
|
|
|
users,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-07 16:33:15 +01:00
|
|
|
export function onCancel() {
|
2017-11-07 14:32:31 +01:00
|
|
|
return {
|
2017-11-07 16:33:15 +01:00
|
|
|
type: ON_CANCEL,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function onChangeInput({ target }) {
|
2017-11-20 14:21:08 +01:00
|
|
|
const keys = ['modifiedData'].concat(target.name.split('.'));
|
|
|
|
|
|
2017-11-07 16:33:15 +01:00
|
|
|
return {
|
|
|
|
|
type: ON_CHANGE_INPUT,
|
2017-11-16 13:43:55 +01:00
|
|
|
keys,
|
2017-11-07 16:33:15 +01:00
|
|
|
value: target.value,
|
2017-11-07 14:32:31 +01:00
|
|
|
};
|
|
|
|
|
}
|
2017-11-07 18:16:42 +01:00
|
|
|
|
2017-11-23 13:09:05 +01:00
|
|
|
export function onClickAdd(itemToAdd) {
|
|
|
|
|
return {
|
|
|
|
|
type: ON_CLICK_ADD,
|
|
|
|
|
itemToAdd,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-07 18:16:42 +01:00
|
|
|
export function onClickDelete(itemToDelete) {
|
|
|
|
|
return {
|
|
|
|
|
type: ON_CLICK_DELETE,
|
|
|
|
|
itemToDelete,
|
|
|
|
|
};
|
|
|
|
|
}
|
2017-11-29 18:51:56 +01:00
|
|
|
|
2017-11-30 12:10:23 +01:00
|
|
|
export function resetShouldDisplayPoliciesHint() {
|
|
|
|
|
return {
|
|
|
|
|
type: RESET_SHOULD_DISPLAY_POLICIES_HINT,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-29 18:51:56 +01:00
|
|
|
export function selectAllActions(name, shouldEnable) {
|
|
|
|
|
return {
|
|
|
|
|
type: SELECT_ALL_ACTIONS,
|
|
|
|
|
keys: ['modifiedData'].concat(name.split('.')),
|
|
|
|
|
shouldEnable,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-23 12:15:06 +01:00
|
|
|
export function setActionType(action) {
|
|
|
|
|
const actionType = action === 'create' ? 'POST' : 'PUT';
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
type: SET_ACTION_TYPE,
|
|
|
|
|
actionType,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function setErrors(formErrors) {
|
|
|
|
|
return {
|
|
|
|
|
type: SET_ERRORS,
|
|
|
|
|
formErrors,
|
|
|
|
|
};
|
|
|
|
|
}
|
2017-11-15 14:00:51 +01:00
|
|
|
|
|
|
|
|
export function setForm() {
|
|
|
|
|
const form = Map({
|
|
|
|
|
name: '',
|
|
|
|
|
description: '',
|
2017-11-23 12:15:06 +01:00
|
|
|
users: List([]),
|
2017-11-15 15:11:10 +01:00
|
|
|
permissions: Map({}),
|
2017-11-15 14:00:51 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
type: SET_FORM,
|
|
|
|
|
form,
|
|
|
|
|
};
|
|
|
|
|
}
|
2017-11-23 12:15:06 +01:00
|
|
|
|
2017-11-30 15:01:19 +01:00
|
|
|
export function setInputPoliciesPath(path) {
|
|
|
|
|
const inputPath = replace(path, 'enabled', 'policy');
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
type: SET_INPUT_POLICIES_PATH,
|
|
|
|
|
inputPath,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-23 17:13:46 +01:00
|
|
|
export function setRoleId(roleId) {
|
|
|
|
|
return {
|
|
|
|
|
type: SET_ROLE_ID,
|
|
|
|
|
roleId,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-30 12:10:23 +01:00
|
|
|
export function setShouldDisplayPolicieshint() {
|
|
|
|
|
return {
|
|
|
|
|
type: SET_SHOULD_DISPLAY_POLICIES_HINT,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-23 12:15:06 +01:00
|
|
|
export function submit() {
|
|
|
|
|
return {
|
|
|
|
|
type: SUBMIT,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function submitError(errors) {
|
|
|
|
|
return {
|
|
|
|
|
type: SUBMIT_ERROR,
|
|
|
|
|
errors,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function submitSucceeded() {
|
|
|
|
|
return {
|
|
|
|
|
type: SUBMIT_SUCCEEDED,
|
|
|
|
|
};
|
|
|
|
|
}
|