foreman_ansible 6.0.1 → 6.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (144) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/ansible_roles_controller.rb +12 -8
  3. data/app/controllers/ansible_variables_controller.rb +4 -0
  4. data/app/controllers/api/v2/ansible_inventories_controller.rb +2 -2
  5. data/app/controllers/api/v2/ansible_roles_controller.rb +32 -11
  6. data/app/controllers/api/v2/ansible_variables_controller.rb +6 -4
  7. data/app/controllers/foreman_ansible/concerns/import_controller_helper.rb +3 -3
  8. data/app/helpers/foreman_ansible/ansible_reports_helper.rb +10 -5
  9. data/app/helpers/foreman_ansible/ansible_roles_data_preparations.rb +95 -0
  10. data/app/helpers/foreman_ansible/ansible_roles_helper.rb +20 -1
  11. data/app/jobs/sync_roles_and_variables.rb +20 -0
  12. data/app/models/concerns/foreman_ansible/host_managed_extensions.rb +10 -7
  13. data/app/models/concerns/foreman_ansible/hostgroup_extensions.rb +19 -4
  14. data/app/models/foreman_ansible/ansible_provider.rb +3 -2
  15. data/app/models/host_ansible_role.rb +1 -0
  16. data/app/models/hostgroup_ansible_role.rb +1 -0
  17. data/app/models/setting/ansible.rb +9 -0
  18. data/app/services/foreman_ansible/ansible_report_importer.rb +4 -0
  19. data/app/services/foreman_ansible/ansible_report_scanner.rb +15 -1
  20. data/app/services/foreman_ansible/api_roles_importer.rb +23 -11
  21. data/app/services/foreman_ansible/fact_parser.rb +21 -1
  22. data/app/services/foreman_ansible/import_roles_and_variables_error_notification.rb +31 -0
  23. data/app/services/foreman_ansible/import_roles_and_variables_success_notification.rb +26 -0
  24. data/app/services/foreman_ansible/inventory_creator.rb +3 -7
  25. data/app/services/foreman_ansible/operating_system_parser.rb +8 -2
  26. data/app/services/foreman_ansible/roles_importer.rb +3 -2
  27. data/app/services/foreman_ansible/ui_roles_importer.rb +2 -2
  28. data/app/services/foreman_ansible/variables_importer.rb +36 -1
  29. data/app/views/ansible_roles/import.html.erb +10 -50
  30. data/app/views/ansible_variables/index.html.erb +1 -2
  31. data/app/views/api/v2/ansible_roles/sync.json.rabl +5 -0
  32. data/app/views/foreman_ansible/ansible_roles/_select_tab_content.html.erb +8 -17
  33. data/app/views/foreman_ansible/config_reports/_ansible.html.erb +13 -6
  34. data/app/views/foreman_ansible/job_templates/ansible_collections_-_install_from_galaxy.erb +28 -0
  35. data/app/views/foreman_ansible/job_templates/ansible_roles_-_install_from_galaxy.erb +1 -1
  36. data/app/views/foreman_ansible/job_templates/capsule_upgrade_-_ansible_default.erb +2 -3
  37. data/app/views/foreman_ansible/job_templates/convert_to_rhel.erb +44 -0
  38. data/config/routes.rb +5 -4
  39. data/db/migrate/20210120150019_add_position_to_ansible_role.rb +27 -0
  40. data/db/seeds.d/100_common_parameters.rb +7 -0
  41. data/db/seeds.d/90_notification_blueprints.rb +19 -1
  42. data/lib/foreman_ansible/engine.rb +1 -0
  43. data/lib/foreman_ansible/register.rb +5 -5
  44. data/lib/foreman_ansible/version.rb +1 -1
  45. data/locale/ca/LC_MESSAGES/foreman_ansible.mo +0 -0
  46. data/locale/ca/foreman_ansible.po +1 -1
  47. data/locale/cs_CZ/LC_MESSAGES/foreman_ansible.mo +0 -0
  48. data/locale/cs_CZ/foreman_ansible.po +1 -1
  49. data/locale/de/LC_MESSAGES/foreman_ansible.mo +0 -0
  50. data/locale/de/foreman_ansible.po +1 -1
  51. data/locale/en/LC_MESSAGES/foreman_ansible.mo +0 -0
  52. data/locale/en/foreman_ansible.po +1 -1
  53. data/locale/en_GB/LC_MESSAGES/foreman_ansible.mo +0 -0
  54. data/locale/en_GB/foreman_ansible.po +1 -1
  55. data/locale/es/LC_MESSAGES/foreman_ansible.mo +0 -0
  56. data/locale/es/foreman_ansible.po +1 -1
  57. data/locale/fr/LC_MESSAGES/foreman_ansible.mo +0 -0
  58. data/locale/fr/foreman_ansible.po +1 -1
  59. data/locale/gl/LC_MESSAGES/foreman_ansible.mo +0 -0
  60. data/locale/gl/foreman_ansible.po +1 -1
  61. data/locale/it/LC_MESSAGES/foreman_ansible.mo +0 -0
  62. data/locale/it/foreman_ansible.po +1 -1
  63. data/locale/ja/LC_MESSAGES/foreman_ansible.mo +0 -0
  64. data/locale/ja/foreman_ansible.po +1 -1
  65. data/locale/ko/LC_MESSAGES/foreman_ansible.mo +0 -0
  66. data/locale/ko/foreman_ansible.po +1 -1
  67. data/locale/nl_NL/LC_MESSAGES/foreman_ansible.mo +0 -0
  68. data/locale/nl_NL/foreman_ansible.po +1 -1
  69. data/locale/pl/LC_MESSAGES/foreman_ansible.mo +0 -0
  70. data/locale/pl/foreman_ansible.po +1 -1
  71. data/locale/pt_BR/LC_MESSAGES/foreman_ansible.mo +0 -0
  72. data/locale/pt_BR/foreman_ansible.po +1 -1
  73. data/locale/ru/LC_MESSAGES/foreman_ansible.mo +0 -0
  74. data/locale/ru/foreman_ansible.po +1 -1
  75. data/locale/sv_SE/LC_MESSAGES/foreman_ansible.mo +0 -0
  76. data/locale/sv_SE/foreman_ansible.po +1 -1
  77. data/locale/zh_CN/LC_MESSAGES/foreman_ansible.mo +0 -0
  78. data/locale/zh_CN/foreman_ansible.po +1 -1
  79. data/locale/zh_TW/LC_MESSAGES/foreman_ansible.mo +0 -0
  80. data/locale/zh_TW/foreman_ansible.po +1 -1
  81. data/package.json +11 -42
  82. data/test/factories/ansible_roles.rb +12 -0
  83. data/test/factories/host_ansible_enhancements.rb +23 -0
  84. data/test/foreman_ansible/helpers/ansible_roles_helper_test.rb +45 -0
  85. data/test/functional/ansible_variables_controller_test.rb +0 -15
  86. data/test/functional/api/v2/ansible_roles_controller_test.rb +23 -0
  87. data/test/functional/api/v2/hostgroups_controller_test.rb +5 -4
  88. data/test/functional/api/v2/hosts_controller_test.rb +9 -8
  89. data/test/functional/hosts_controller_test.rb +10 -6
  90. data/test/unit/ansible_provider_test.rb +1 -1
  91. data/test/unit/concerns/host_managed_extensions_test.rb +17 -3
  92. data/test/unit/concerns/hostgroup_extensions_test.rb +13 -7
  93. data/test/unit/host_ansible_role_test.rb +2 -1
  94. data/test/unit/hostgroup_ansible_role_test.rb +2 -1
  95. data/test/unit/ignore_roles_test.rb +43 -0
  96. data/test/unit/import_roles_and_variables.rb +60 -0
  97. data/test/unit/lib/foreman_ansible_core/ansible_runner_test.rb +3 -3
  98. data/test/unit/lib/foreman_ansible_core/playbook_runner_test.rb +3 -3
  99. data/test/unit/services/ansible_variables_importer_test.rb +13 -0
  100. data/test/unit/services/api_roles_importer_test.rb +22 -5
  101. data/test/unit/services/fact_parser_test.rb +16 -0
  102. data/test/unit/services/inventory_creator_test.rb +16 -8
  103. data/test/unit/services/ui_roles_importer_test.rb +2 -2
  104. data/webpack/__mocks__/foremanReact/common/helpers.js +13 -0
  105. data/webpack/__mocks__/foremanReact/components/common/forms/OrderableSelect/helpers.js +5 -0
  106. data/webpack/__mocks__/foremanReact/redux/API.js +7 -0
  107. data/webpack/components/AnsibleRolesAndVariables/AnsibleRolesAndVariables.js +178 -0
  108. data/webpack/components/AnsibleRolesAndVariables/AnsibleRolesAndVariables.scss +9 -0
  109. data/webpack/components/AnsibleRolesAndVariables/AnsibleRolesAndVariablesActions.js +39 -0
  110. data/webpack/components/AnsibleRolesAndVariables/AnsibleRolesAndVariablesConstants.js +4 -0
  111. data/webpack/components/AnsibleRolesAndVariables/AnsibleRolesAndVariablesHelpers.js +11 -0
  112. data/webpack/components/AnsibleRolesAndVariables/__test__/AnsibleRolesAndVariablesHelpers.test.js +50 -0
  113. data/webpack/components/AnsibleRolesAndVariables/__test__/AnsibleRolesAndVariablesImport.test.js +39 -0
  114. data/webpack/components/AnsibleRolesAndVariables/__test__/__snapshots__/AnsibleRolesAndVariablesImport.test.js.snap +177 -0
  115. data/webpack/components/AnsibleRolesAndVariables/index.js +31 -0
  116. data/webpack/components/AnsibleRolesSwitcher/AnsibleRolesSwitcher.js +25 -27
  117. data/webpack/components/AnsibleRolesSwitcher/AnsibleRolesSwitcher.scss +1 -1
  118. data/webpack/components/AnsibleRolesSwitcher/AnsibleRolesSwitcherActions.js +20 -14
  119. data/webpack/components/AnsibleRolesSwitcher/AnsibleRolesSwitcherConstants.js +1 -2
  120. data/webpack/components/AnsibleRolesSwitcher/AnsibleRolesSwitcherReducer.js +13 -8
  121. data/webpack/components/AnsibleRolesSwitcher/AnsibleRolesSwitcherSelectors.js +8 -28
  122. data/webpack/components/AnsibleRolesSwitcher/__fixtures__/ansibleRolesSwitcherReducer.fixtures.js +1 -0
  123. data/webpack/components/AnsibleRolesSwitcher/__tests__/AnsibleRolesSwitcher.test.js +6 -4
  124. data/webpack/components/AnsibleRolesSwitcher/__tests__/AnsibleRolesSwitcherReducer.test.js +1 -9
  125. data/webpack/components/AnsibleRolesSwitcher/__tests__/AnsibleRolesSwitcherSelectors.test.js +3 -16
  126. data/webpack/components/AnsibleRolesSwitcher/__tests__/__snapshots__/AnsibleRolesSwitcher.test.js.snap +4 -8
  127. data/webpack/components/AnsibleRolesSwitcher/__tests__/__snapshots__/AnsibleRolesSwitcherReducer.test.js.snap +8 -97
  128. data/webpack/components/AnsibleRolesSwitcher/__tests__/__snapshots__/AnsibleRolesSwitcherSelectors.test.js.snap +5 -30
  129. data/webpack/components/AnsibleRolesSwitcher/components/AnsiblePermissionDenied.test.js +1 -1
  130. data/webpack/components/AnsibleRolesSwitcher/components/AnsibleRole.js +5 -2
  131. data/webpack/components/AnsibleRolesSwitcher/components/AnsibleRole.test.js +1 -1
  132. data/webpack/components/AnsibleRolesSwitcher/components/AnsibleRoleInputs.js +43 -0
  133. data/webpack/components/AnsibleRolesSwitcher/components/AnsibleRoleInputs.test.js +19 -0
  134. data/webpack/components/AnsibleRolesSwitcher/components/AssignedRolesList.js +63 -51
  135. data/webpack/components/AnsibleRolesSwitcher/components/AssignedRolesList.test.js +4 -1
  136. data/webpack/components/AnsibleRolesSwitcher/components/AvailableRolesList.test.js +1 -1
  137. data/webpack/components/AnsibleRolesSwitcher/components/OrderedRolesTooltip.js +23 -0
  138. data/webpack/components/AnsibleRolesSwitcher/components/__snapshots__/AnsibleRoleInputs.test.js.snap +51 -0
  139. data/webpack/components/AnsibleRolesSwitcher/components/__snapshots__/AssignedRolesList.test.js.snap +28 -28
  140. data/webpack/components/AnsibleRolesSwitcher/index.js +4 -8
  141. data/webpack/index.js +6 -13
  142. metadata +60 -15
  143. data/app/views/ansible_variables/import.html.erb +0 -56
  144. data/webpack/test_setup.js +0 -12
@@ -0,0 +1,31 @@
1
+ import React from 'react';
2
+ import { useDispatch } from 'react-redux';
3
+ import { push } from 'connected-react-router';
4
+
5
+ import ImportRolesAndVariablesTable from './AnsibleRolesAndVariables';
6
+ import { onSubmit } from './AnsibleRolesAndVariablesActions';
7
+ import { ANSIBLE_ROLES_INDEX } from './AnsibleRolesAndVariablesConstants';
8
+
9
+ const WrappedImportRolesAndVariables = props => {
10
+ const cols = [
11
+ { title: 'Name' },
12
+ { title: 'Operation' },
13
+ { title: 'Variables' },
14
+ { title: 'Hosts Count' },
15
+ { title: 'Hostgroups count' },
16
+ ];
17
+ const dispatch = useDispatch();
18
+ const submit = (rows, proxy) => dispatch(onSubmit(rows, proxy));
19
+ const onCancel = () => {
20
+ dispatch(push(ANSIBLE_ROLES_INDEX));
21
+ };
22
+ return (
23
+ <ImportRolesAndVariablesTable
24
+ {...props}
25
+ columnsData={cols}
26
+ onSubmit={submit}
27
+ onCancel={onCancel}
28
+ />
29
+ );
30
+ };
31
+ export default WrappedImportRolesAndVariables;
@@ -7,6 +7,7 @@ import { translate as __ } from 'foremanReact/common/I18n';
7
7
  import AvailableRolesList from './components/AvailableRolesList';
8
8
  import AssignedRolesList from './components/AssignedRolesList';
9
9
  import AnsibleRolesSwitcherError from './components/AnsibleRolesSwitcherError';
10
+ import OrderedRolesTooltip from './components/OrderedRolesTooltip';
10
11
  import { excludeAssignedRolesSearch } from './AnsibleRolesSwitcherHelpers';
11
12
 
12
13
  class AnsibleRolesSwitcher extends React.Component {
@@ -17,7 +18,7 @@ class AnsibleRolesSwitcher extends React.Component {
17
18
  inheritedRoleIds,
18
19
  resourceId,
19
20
  resourceName,
20
- } = this.props.data;
21
+ } = this.props;
21
22
 
22
23
  this.props.getAnsibleRoles(
23
24
  availableRolesUrl,
@@ -37,13 +38,11 @@ class AnsibleRolesSwitcher extends React.Component {
37
38
  itemCount,
38
39
  addAnsibleRole,
39
40
  removeAnsibleRole,
41
+ moveAnsibleRole,
40
42
  getAnsibleRoles,
41
- changeAssignedPage,
42
- assignedPagination,
43
- assignedRolesCount,
44
43
  assignedRoles,
45
- allAssignedRoles,
46
44
  unassignedRoles,
45
+ toDestroyRoles,
47
46
  error,
48
47
  } = this.props;
49
48
 
@@ -52,17 +51,17 @@ class AnsibleRolesSwitcher extends React.Component {
52
51
  inheritedRoleIds,
53
52
  resourceId,
54
53
  resourceName,
55
- } = this.props.data;
54
+ } = this.props;
56
55
 
57
56
  const onListingChange = paginationArgs =>
58
57
  getAnsibleRoles(
59
58
  availableRolesUrl,
60
- allAssignedRoles,
59
+ assignedRoles,
61
60
  inheritedRoleIds,
62
61
  resourceId,
63
62
  resourceName,
64
63
  paginationArgs,
65
- excludeAssignedRolesSearch(allAssignedRoles)
64
+ excludeAssignedRolesSearch(assignedRoles)
66
65
  );
67
66
 
68
67
  return (
@@ -85,16 +84,18 @@ class AnsibleRolesSwitcher extends React.Component {
85
84
 
86
85
  <Col sm={6} className="assigned-roles-container">
87
86
  <div className="assigned-roles-header">
88
- <h2>{__('Assigned Ansible Roles')}</h2>
87
+ <h2>
88
+ <OrderedRolesTooltip />
89
+ {__('Assigned Ansible Roles')}
90
+ </h2>
89
91
  </div>
90
92
  <AssignedRolesList
91
93
  assignedRoles={assignedRoles}
92
- allAssignedRoles={allAssignedRoles}
93
- pagination={assignedPagination}
94
- itemCount={assignedRolesCount}
95
- onPaginationChange={changeAssignedPage}
94
+ unassignedRoles={unassignedRoles}
96
95
  onRemoveRole={removeAnsibleRole}
96
+ onMoveRole={moveAnsibleRole}
97
97
  resourceName={lowerCase(resourceName || '')}
98
+ toDestroyRoles={toDestroyRoles}
98
99
  />
99
100
  </Col>
100
101
  </Row>
@@ -104,13 +105,11 @@ class AnsibleRolesSwitcher extends React.Component {
104
105
  }
105
106
 
106
107
  AnsibleRolesSwitcher.propTypes = {
107
- data: PropTypes.shape({
108
- initialAssignedRoles: PropTypes.arrayOf(PropTypes.object),
109
- availableRolesUrl: PropTypes.string,
110
- inheritedRoleIds: PropTypes.arrayOf(PropTypes.number),
111
- resourceId: PropTypes.number,
112
- resourceName: PropTypes.string,
113
- }).isRequired,
108
+ initialAssignedRoles: PropTypes.arrayOf(PropTypes.object),
109
+ availableRolesUrl: PropTypes.string.isRequired,
110
+ inheritedRoleIds: PropTypes.arrayOf(PropTypes.number),
111
+ resourceId: PropTypes.number,
112
+ resourceName: PropTypes.string,
114
113
  getAnsibleRoles: PropTypes.func.isRequired,
115
114
  loading: PropTypes.bool.isRequired,
116
115
  pagination: PropTypes.shape({
@@ -120,14 +119,9 @@ AnsibleRolesSwitcher.propTypes = {
120
119
  itemCount: PropTypes.number.isRequired,
121
120
  addAnsibleRole: PropTypes.func.isRequired,
122
121
  removeAnsibleRole: PropTypes.func.isRequired,
123
- changeAssignedPage: PropTypes.func.isRequired,
124
- assignedPagination: PropTypes.shape({
125
- page: PropTypes.number,
126
- perPage: PropTypes.number,
127
- }).isRequired,
128
- assignedRolesCount: PropTypes.number.isRequired,
122
+ moveAnsibleRole: PropTypes.func.isRequired,
129
123
  assignedRoles: PropTypes.arrayOf(PropTypes.object).isRequired,
130
- allAssignedRoles: PropTypes.arrayOf(PropTypes.object).isRequired,
124
+ toDestroyRoles: PropTypes.arrayOf(PropTypes.object).isRequired,
131
125
  unassignedRoles: PropTypes.arrayOf(PropTypes.object).isRequired,
132
126
  error: PropTypes.shape({
133
127
  errorMsg: PropTypes.string,
@@ -137,6 +131,10 @@ AnsibleRolesSwitcher.propTypes = {
137
131
 
138
132
  AnsibleRolesSwitcher.defaultProps = {
139
133
  error: {},
134
+ resourceId: null,
135
+ resourceName: '',
136
+ initialAssignedRoles: [],
137
+ inheritedRoleIds: [],
140
138
  };
141
139
 
142
140
  export default AnsibleRolesSwitcher;
@@ -10,7 +10,7 @@
10
10
  }
11
11
 
12
12
  .list-group-item.ansible-role-movable:hover {
13
- cursor: pointer;
13
+ cursor: grab;
14
14
  }
15
15
  }
16
16
 
@@ -10,6 +10,7 @@ import {
10
10
  ANSIBLE_ROLES_FAILURE,
11
11
  ANSIBLE_ROLES_ADD,
12
12
  ANSIBLE_ROLES_REMOVE,
13
+ ANSIBLE_ROLES_MOVE,
13
14
  ANSIBLE_ROLES_ASSIGNED_PAGE_CHANGE,
14
15
  } from './AnsibleRolesSwitcherConstants';
15
16
 
@@ -21,7 +22,7 @@ export const getAnsibleRoles = (
21
22
  resourceName,
22
23
  pagination,
23
24
  search
24
- ) => dispatch => {
25
+ ) => async dispatch => {
25
26
  dispatch({ type: ANSIBLE_ROLES_REQUEST });
26
27
 
27
28
  const params = {
@@ -30,19 +31,19 @@ export const getAnsibleRoles = (
30
31
  ...propsToSnakeCase({ resourceId, resourceName }),
31
32
  };
32
33
 
33
- return api
34
- .get(url, {}, params)
35
- .then(({ data }) =>
36
- dispatch({
37
- type: ANSIBLE_ROLES_SUCCESS,
38
- payload: {
39
- initialAssignedRoles,
40
- inheritedRoleIds,
41
- ...propsToCamelCase(data),
42
- },
43
- })
44
- )
45
- .catch(error => dispatch(errorHandler(ANSIBLE_ROLES_FAILURE, error)));
34
+ try {
35
+ const res = await api.get(url, {}, params);
36
+ return dispatch({
37
+ type: ANSIBLE_ROLES_SUCCESS,
38
+ payload: {
39
+ initialAssignedRoles,
40
+ inheritedRoleIds,
41
+ ...propsToCamelCase(res.data),
42
+ },
43
+ });
44
+ } catch (error) {
45
+ return dispatch(errorHandler(ANSIBLE_ROLES_FAILURE, error));
46
+ }
46
47
  };
47
48
 
48
49
  const errorHandler = (msg, err) => {
@@ -63,6 +64,11 @@ export const removeAnsibleRole = role => ({
63
64
  payload: { role },
64
65
  });
65
66
 
67
+ export const moveAnsibleRole = roles => ({
68
+ type: ANSIBLE_ROLES_MOVE,
69
+ payload: { roles },
70
+ });
71
+
66
72
  export const changeAssignedPage = pagination => ({
67
73
  type: ANSIBLE_ROLES_ASSIGNED_PAGE_CHANGE,
68
74
  payload: { pagination },
@@ -3,5 +3,4 @@ export const ANSIBLE_ROLES_SUCCESS = 'ANSIBLE_ROLES_SUCCESS';
3
3
  export const ANSIBLE_ROLES_FAILURE = 'ANSIBLE_ROLES_FAILURE';
4
4
  export const ANSIBLE_ROLES_ADD = 'ANSIBLE_ROLES_ADD';
5
5
  export const ANSIBLE_ROLES_REMOVE = 'ANSIBLE_ROLES_REMOVE';
6
- export const ANSIBLE_ROLES_ASSIGNED_PAGE_CHANGE =
7
- 'ANSIBLE_ROLES_ASSIGNED_PAGE_CHANGE';
6
+ export const ANSIBLE_ROLES_MOVE = 'ANSIBLE_ROLE_MOVE';
@@ -6,7 +6,7 @@ import {
6
6
  ANSIBLE_ROLES_FAILURE,
7
7
  ANSIBLE_ROLES_ADD,
8
8
  ANSIBLE_ROLES_REMOVE,
9
- ANSIBLE_ROLES_ASSIGNED_PAGE_CHANGE,
9
+ ANSIBLE_ROLES_MOVE,
10
10
  } from './AnsibleRolesSwitcherConstants';
11
11
 
12
12
  export const initialState = Immutable({
@@ -17,12 +17,9 @@ export const initialState = Immutable({
17
17
  perPage: 10,
18
18
  },
19
19
  assignedRoles: [],
20
+ toDestroyRoles: [],
20
21
  inheritedRoleIds: [],
21
22
  results: [],
22
- assignedPagination: {
23
- page: 1,
24
- perPage: 10,
25
- },
26
23
  error: { errorMsg: '', status: '', statusText: '' },
27
24
  });
28
25
 
@@ -49,6 +46,9 @@ const ansibleRoles = (state = initialState, action) => {
49
46
  case ANSIBLE_ROLES_ADD:
50
47
  return state.merge({
51
48
  assignedRoles: state.assignedRoles.concat([payload.role]),
49
+ toDestroyRoles: state.toDestroyRoles.filter(
50
+ item => item.id !== payload.role.id
51
+ ),
52
52
  itemCount: state.itemCount - 1,
53
53
  });
54
54
  case ANSIBLE_ROLES_REMOVE:
@@ -56,11 +56,16 @@ const ansibleRoles = (state = initialState, action) => {
56
56
  assignedRoles: Immutable.flatMap(state.assignedRoles, item =>
57
57
  item.id === payload.role.id ? [] : item
58
58
  ),
59
- results: state.results.concat([payload.role]),
59
+ results: state.results.find(item => payload.role.id === item.id)
60
+ ? state.results
61
+ : state.results.concat([payload.role]),
62
+ toDestroyRoles: state.toDestroyRoles.concat([
63
+ { ...payload.role, destroy: true },
64
+ ]),
60
65
  itemCount: state.itemCount + 1,
61
66
  });
62
- case ANSIBLE_ROLES_ASSIGNED_PAGE_CHANGE:
63
- return state.set('assignedPagination', payload.pagination);
67
+ case ANSIBLE_ROLES_MOVE:
68
+ return state.set('assignedRoles', payload.roles);
64
69
  default:
65
70
  return state;
66
71
  }
@@ -1,16 +1,7 @@
1
- import { differenceBy, slice, includes, uniq } from 'lodash';
1
+ import { differenceBy, includes } from 'lodash';
2
2
  import Immutable from 'seamless-immutable';
3
3
  import { createSelector } from 'reselect';
4
-
5
- const compare = (a, b) => {
6
- if (a.name < b.name) {
7
- return -1;
8
- }
9
- if (a.name > b.name) {
10
- return 1;
11
- }
12
- return 0;
13
- };
4
+ import { propsToCamelCase } from 'foremanReact/common/helpers';
14
5
 
15
6
  const switcherState = state => state.foremanAnsible.ansibleRolesSwitcher;
16
7
 
@@ -21,7 +12,7 @@ const markInheritedRoles = (roles, inheritedRoleIds) =>
21
12
 
22
13
  export const selectResults = state =>
23
14
  Immutable(
24
- Immutable.asMutable(uniq(switcherState(state).results)).sort(compare)
15
+ Immutable.asMutable(switcherState(state).results.map(propsToCamelCase))
25
16
  );
26
17
 
27
18
  export const selectItemCount = state => switcherState(state).itemCount;
@@ -29,16 +20,15 @@ export const selectItemCount = state => switcherState(state).itemCount;
29
20
  export const selectAssignedRoles = state =>
30
21
  Immutable.asMutable(
31
22
  markInheritedRoles(
32
- switcherState(state).assignedRoles,
23
+ switcherState(state).assignedRoles.map(propsToCamelCase),
33
24
  switcherState(state).inheritedRoleIds
34
25
  )
35
- ).sort(compare);
26
+ );
27
+
28
+ export const selectToDestroyRoles = state =>
29
+ switcherState(state).toDestroyRoles;
36
30
 
37
- export const selectAssignedRolesCount = state =>
38
- selectAssignedRoles(state).length;
39
31
  export const selectLoading = state => switcherState(state).loading;
40
- export const selectAssignedPagination = state =>
41
- switcherState(state).assignedPagination;
42
32
  export const selectError = state => switcherState(state).error;
43
33
  export const selectPagination = state => switcherState(state).pagination;
44
34
 
@@ -56,13 +46,3 @@ export const selectUnassignedRoles = createSelector(
56
46
  selectAssignedRoles,
57
47
  (results, assignedRoles) => differenceBy(results, assignedRoles, 'id')
58
48
  );
59
-
60
- export const selectAssignedRolesPage = createSelector(
61
- selectAssignedPagination,
62
- selectAssignedRoles,
63
- (assignedPagination, assignedRoles) => {
64
- const offset = (assignedPagination.page - 1) * assignedPagination.perPage;
65
-
66
- return slice(assignedRoles, offset, offset + assignedPagination.perPage);
67
- }
68
- );
@@ -23,6 +23,7 @@ export const successState = Immutable({
23
23
  ...ansibleRolesLong.slice(4, 6),
24
24
  ],
25
25
  results: ansibleRolesLong,
26
+ toDestroyRoles: [],
26
27
  assignedPagination: {
27
28
  page: 1,
28
29
  perPage: 20,
@@ -1,4 +1,4 @@
1
- import { testComponentSnapshotsWithFixtures } from 'react-redux-test-utils';
1
+ import { testComponentSnapshotsWithFixtures } from '@theforeman/test';
2
2
 
3
3
  import AnsibleRolesSwitcher from '../AnsibleRolesSwitcher';
4
4
 
@@ -13,16 +13,18 @@ const fixtures = {
13
13
  itemCount: 20,
14
14
  addAnsibleRole: noop,
15
15
  removeAnsibleRole: noop,
16
+ moveAnsibleRole: noop,
16
17
  getAnsibleRoles: noop,
17
18
  changeAssignedPage: noop,
18
19
  assignedPagination: { page: 1, perPage: 12 },
19
20
  assignedRolesCount: 2,
20
21
  assignedRoles: [],
21
22
  unassignedRoles: [],
22
- data: {
23
- initialAssignedRoles: [],
24
- },
23
+ initialAssignedRoles: [],
25
24
  error: { statusText: '', errorMsg: '' },
25
+ allAssignedRoles: [],
26
+ toDestroyRoles: [],
27
+ availableRolesUrl: 'http://test/roles',
26
28
  },
27
29
  };
28
30
 
@@ -1,4 +1,4 @@
1
- import { testReducerSnapshotWithFixtures } from 'react-redux-test-utils';
1
+ import { testReducerSnapshotWithFixtures } from '@theforeman/test';
2
2
 
3
3
  import reducer, { initialState } from '../AnsibleRolesSwitcherReducer';
4
4
  import { ansibleRolesLong } from '../__fixtures__/ansibleRolesData.fixtures';
@@ -15,7 +15,6 @@ import {
15
15
  ANSIBLE_ROLES_FAILURE,
16
16
  ANSIBLE_ROLES_ADD,
17
17
  ANSIBLE_ROLES_REMOVE,
18
- ANSIBLE_ROLES_ASSIGNED_PAGE_CHANGE,
19
18
  } from '../AnsibleRolesSwitcherConstants';
20
19
 
21
20
  const fixtures = {
@@ -60,13 +59,6 @@ const fixtures = {
60
59
  payload: { role: ansibleRolesLong[5] },
61
60
  },
62
61
  },
63
- 'should change pagination for assigned roles': {
64
- state: successState,
65
- action: {
66
- type: ANSIBLE_ROLES_ASSIGNED_PAGE_CHANGE,
67
- payload: { pagination: { page: 20, perPage: 5 } },
68
- },
69
- },
70
62
  };
71
63
 
72
64
  describe('AnsibleRolesSwitcherReducer', () =>
@@ -1,13 +1,7 @@
1
- import { testSelectorsSnapshotWithFixtures } from 'react-redux-test-utils';
1
+ import { testSelectorsSnapshotWithFixtures } from '@theforeman/test';
2
2
 
3
- import {
4
- selectUnassignedRoles,
5
- selectAssignedRolesPage,
6
- } from '../AnsibleRolesSwitcherSelectors';
7
- import {
8
- ansibleRolesShort,
9
- ansibleRolesLong,
10
- } from '../__fixtures__/ansibleRolesData.fixtures';
3
+ import { selectUnassignedRoles } from '../AnsibleRolesSwitcherSelectors';
4
+ import { ansibleRolesShort } from '../__fixtures__/ansibleRolesData.fixtures';
11
5
 
12
6
  const stateFactory = obj => ({
13
7
  foremanAnsible: {
@@ -25,18 +19,11 @@ const state2 = {
25
19
  assignedRoles: [],
26
20
  };
27
21
 
28
- const state3 = {
29
- assignedRoles: ansibleRolesLong,
30
- assignedPagination: { page: 2, perPage: 5 },
31
- };
32
-
33
22
  const fixtures = {
34
23
  'should return unassigned roles': () =>
35
24
  selectUnassignedRoles(stateFactory(state1)),
36
25
  'should return all roles when no roles assigned': () =>
37
26
  selectUnassignedRoles(stateFactory(state2)),
38
- 'should return requested page': () =>
39
- selectAssignedRolesPage(stateFactory(state3)),
40
27
  };
41
28
 
42
29
  describe('AnsibleRolesSwitcherSelectors', () =>