234 lines
3.8 KiB
JavaScript
Raw Normal View History

/*
*
* EditPage actions
*
*/
import { fromJS, List, Map } from 'immutable';
2017-11-30 15:01:19 +01:00
import { get, replace } from 'lodash';
import {
ADD_USER,
GET_PERMISSIONS,
GET_PERMISSIONS_SUCCEEDED,
2017-11-30 11:07:54 +01:00
GET_POLICIES,
GET_POLICIES_SUCCEEDED,
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,
ON_CANCEL,
ON_CHANGE_INPUT,
2017-11-23 13:09:05 +01:00
ON_CLICK_ADD,
ON_CLICK_DELETE,
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,
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,
SET_SHOULD_DISPLAY_POLICIES_HINT,
2017-11-23 12:15:06 +01:00
SUBMIT,
SUBMIT_ERROR,
SUBMIT_SUCCEEDED,
} from './constants';
export function addUser(newUser) {
return {
type: ADD_USER,
newUser,
};
}
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
};
}
export function getRole(id) {
return {
type: GET_ROLE,
id,
};
}
export function getRoleSucceeded(data) {
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']))),
});
return {
type: GET_ROLE_SUCCEEDED,
form,
};
}
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,
};
}
export function onCancel() {
return {
type: ON_CANCEL,
};
}
export function onChangeInput({ target }) {
const keys = ['modifiedData'].concat(target.name.split('.'));
return {
type: ON_CHANGE_INPUT,
keys,
value: target.value,
};
}
2017-11-23 13:09:05 +01:00
export function onClickAdd(itemToAdd) {
return {
type: ON_CLICK_ADD,
itemToAdd,
};
}
export function onClickDelete(itemToDelete) {
return {
type: ON_CLICK_DELETE,
itemToDelete,
};
}
2017-11-29 18:51:56 +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,
};
}
export function setForm() {
const form = Map({
name: '',
description: '',
2017-11-23 12:15:06 +01:00
users: List([]),
permissions: Map({}),
});
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,
};
}
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,
};
}