foreman_ansible 6.2.0 → 6.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/ansible_roles_controller.rb +12 -8
- data/app/controllers/ansible_variables_controller.rb +4 -0
- data/app/controllers/api/v2/ansible_roles_controller.rb +32 -11
- data/app/controllers/api/v2/ansible_variables_controller.rb +6 -4
- data/app/controllers/foreman_ansible/concerns/import_controller_helper.rb +3 -3
- data/app/helpers/foreman_ansible/ansible_reports_helper.rb +8 -0
- data/app/helpers/foreman_ansible/ansible_roles_data_preparations.rb +95 -0
- data/app/helpers/foreman_ansible/ansible_roles_helper.rb +20 -1
- data/app/jobs/sync_roles_and_variables.rb +20 -0
- data/app/models/concerns/foreman_ansible/host_managed_extensions.rb +7 -4
- data/app/models/concerns/foreman_ansible/hostgroup_extensions.rb +7 -4
- data/app/models/foreman_ansible/ansible_provider.rb +2 -1
- data/app/models/host_ansible_role.rb +1 -0
- data/app/models/hostgroup_ansible_role.rb +1 -0
- data/app/models/setting/ansible.rb +9 -0
- data/app/services/foreman_ansible/ansible_report_importer.rb +4 -0
- data/app/services/foreman_ansible/ansible_report_scanner.rb +15 -1
- data/app/services/foreman_ansible/api_roles_importer.rb +23 -11
- data/app/services/foreman_ansible/fact_parser.rb +21 -1
- data/app/services/foreman_ansible/import_roles_and_variables_error_notification.rb +31 -0
- data/app/services/foreman_ansible/import_roles_and_variables_success_notification.rb +26 -0
- data/app/services/foreman_ansible/inventory_creator.rb +3 -7
- data/app/services/foreman_ansible/roles_importer.rb +3 -2
- data/app/services/foreman_ansible/ui_roles_importer.rb +2 -2
- data/app/services/foreman_ansible/variables_importer.rb +32 -2
- data/app/views/ansible_roles/import.html.erb +10 -50
- data/app/views/ansible_variables/index.html.erb +1 -2
- data/app/views/api/v2/ansible_roles/sync.json.rabl +5 -0
- data/app/views/foreman_ansible/ansible_roles/_select_tab_content.html.erb +1 -2
- data/app/views/foreman_ansible/config_reports/_ansible.html.erb +13 -6
- data/app/views/foreman_ansible/job_templates/ansible_collections_-_install_from_galaxy.erb +28 -0
- data/app/views/foreman_ansible/job_templates/convert_to_rhel.erb +44 -0
- data/config/routes.rb +5 -4
- data/db/migrate/20210120150019_add_position_to_ansible_role.rb +27 -0
- data/db/seeds.d/100_common_parameters.rb +7 -0
- data/db/seeds.d/90_notification_blueprints.rb +19 -1
- data/lib/foreman_ansible/engine.rb +1 -0
- data/lib/foreman_ansible/register.rb +5 -5
- data/lib/foreman_ansible/version.rb +1 -1
- data/locale/ca/LC_MESSAGES/foreman_ansible.mo +0 -0
- data/locale/ca/foreman_ansible.po +1 -1
- data/locale/cs_CZ/LC_MESSAGES/foreman_ansible.mo +0 -0
- data/locale/cs_CZ/foreman_ansible.po +1 -1
- data/locale/de/LC_MESSAGES/foreman_ansible.mo +0 -0
- data/locale/de/foreman_ansible.po +1 -1
- data/locale/en/LC_MESSAGES/foreman_ansible.mo +0 -0
- data/locale/en/foreman_ansible.po +1 -1
- data/locale/en_GB/LC_MESSAGES/foreman_ansible.mo +0 -0
- data/locale/en_GB/foreman_ansible.po +1 -1
- data/locale/es/LC_MESSAGES/foreman_ansible.mo +0 -0
- data/locale/es/foreman_ansible.po +1 -1
- data/locale/fr/LC_MESSAGES/foreman_ansible.mo +0 -0
- data/locale/fr/foreman_ansible.po +1 -1
- data/locale/gl/LC_MESSAGES/foreman_ansible.mo +0 -0
- data/locale/gl/foreman_ansible.po +1 -1
- data/locale/it/LC_MESSAGES/foreman_ansible.mo +0 -0
- data/locale/it/foreman_ansible.po +1 -1
- data/locale/ja/LC_MESSAGES/foreman_ansible.mo +0 -0
- data/locale/ja/foreman_ansible.po +1 -1
- data/locale/ko/LC_MESSAGES/foreman_ansible.mo +0 -0
- data/locale/ko/foreman_ansible.po +1 -1
- data/locale/nl_NL/LC_MESSAGES/foreman_ansible.mo +0 -0
- data/locale/nl_NL/foreman_ansible.po +1 -1
- data/locale/pl/LC_MESSAGES/foreman_ansible.mo +0 -0
- data/locale/pl/foreman_ansible.po +1 -1
- data/locale/pt_BR/LC_MESSAGES/foreman_ansible.mo +0 -0
- data/locale/pt_BR/foreman_ansible.po +1 -1
- data/locale/ru/LC_MESSAGES/foreman_ansible.mo +0 -0
- data/locale/ru/foreman_ansible.po +1 -1
- data/locale/sv_SE/LC_MESSAGES/foreman_ansible.mo +0 -0
- data/locale/sv_SE/foreman_ansible.po +1 -1
- data/locale/zh_CN/LC_MESSAGES/foreman_ansible.mo +0 -0
- data/locale/zh_CN/foreman_ansible.po +1 -1
- data/locale/zh_TW/LC_MESSAGES/foreman_ansible.mo +0 -0
- data/locale/zh_TW/foreman_ansible.po +1 -1
- data/test/factories/ansible_roles.rb +12 -0
- data/test/factories/host_ansible_enhancements.rb +23 -0
- data/test/foreman_ansible/helpers/ansible_roles_helper_test.rb +45 -0
- data/test/functional/ansible_variables_controller_test.rb +0 -15
- data/test/functional/api/v2/ansible_roles_controller_test.rb +23 -0
- data/test/functional/api/v2/hostgroups_controller_test.rb +5 -4
- data/test/functional/api/v2/hosts_controller_test.rb +9 -8
- data/test/functional/hosts_controller_test.rb +10 -6
- data/test/unit/concerns/host_managed_extensions_test.rb +17 -3
- data/test/unit/concerns/hostgroup_extensions_test.rb +13 -7
- data/test/unit/host_ansible_role_test.rb +2 -1
- data/test/unit/hostgroup_ansible_role_test.rb +2 -1
- data/test/unit/ignore_roles_test.rb +43 -0
- data/test/unit/import_roles_and_variables.rb +60 -0
- data/test/unit/services/api_roles_importer_test.rb +22 -5
- data/test/unit/services/fact_parser_test.rb +16 -0
- data/test/unit/services/inventory_creator_test.rb +15 -7
- data/test/unit/services/ui_roles_importer_test.rb +2 -2
- data/webpack/__mocks__/foremanReact/common/helpers.js +13 -0
- data/webpack/__mocks__/foremanReact/components/common/forms/OrderableSelect/helpers.js +5 -0
- data/webpack/__mocks__/foremanReact/redux/API.js +7 -0
- data/webpack/components/AnsibleRolesAndVariables/AnsibleRolesAndVariables.js +178 -0
- data/webpack/components/AnsibleRolesAndVariables/AnsibleRolesAndVariables.scss +9 -0
- data/webpack/components/AnsibleRolesAndVariables/AnsibleRolesAndVariablesActions.js +39 -0
- data/webpack/components/AnsibleRolesAndVariables/AnsibleRolesAndVariablesConstants.js +4 -0
- data/webpack/components/AnsibleRolesAndVariables/AnsibleRolesAndVariablesHelpers.js +11 -0
- data/webpack/components/AnsibleRolesAndVariables/__test__/AnsibleRolesAndVariablesHelpers.test.js +50 -0
- data/webpack/components/AnsibleRolesAndVariables/__test__/AnsibleRolesAndVariablesImport.test.js +39 -0
- data/webpack/components/AnsibleRolesAndVariables/__test__/__snapshots__/AnsibleRolesAndVariablesImport.test.js.snap +177 -0
- data/webpack/components/AnsibleRolesAndVariables/index.js +31 -0
- data/webpack/components/AnsibleRolesSwitcher/AnsibleRolesSwitcher.js +14 -18
- data/webpack/components/AnsibleRolesSwitcher/AnsibleRolesSwitcher.scss +1 -1
- data/webpack/components/AnsibleRolesSwitcher/AnsibleRolesSwitcherActions.js +6 -0
- data/webpack/components/AnsibleRolesSwitcher/AnsibleRolesSwitcherConstants.js +1 -2
- data/webpack/components/AnsibleRolesSwitcher/AnsibleRolesSwitcherReducer.js +13 -8
- data/webpack/components/AnsibleRolesSwitcher/AnsibleRolesSwitcherSelectors.js +8 -28
- data/webpack/components/AnsibleRolesSwitcher/__fixtures__/ansibleRolesSwitcherReducer.fixtures.js +1 -0
- data/webpack/components/AnsibleRolesSwitcher/__tests__/AnsibleRolesSwitcher.test.js +2 -0
- data/webpack/components/AnsibleRolesSwitcher/__tests__/AnsibleRolesSwitcherReducer.test.js +0 -8
- data/webpack/components/AnsibleRolesSwitcher/__tests__/AnsibleRolesSwitcherSelectors.test.js +2 -15
- data/webpack/components/AnsibleRolesSwitcher/__tests__/__snapshots__/AnsibleRolesSwitcher.test.js.snap +4 -9
- data/webpack/components/AnsibleRolesSwitcher/__tests__/__snapshots__/AnsibleRolesSwitcherReducer.test.js.snap +8 -97
- data/webpack/components/AnsibleRolesSwitcher/__tests__/__snapshots__/AnsibleRolesSwitcherSelectors.test.js.snap +5 -30
- data/webpack/components/AnsibleRolesSwitcher/components/AnsibleRole.js +5 -2
- data/webpack/components/AnsibleRolesSwitcher/components/AnsibleRoleInputs.js +43 -0
- data/webpack/components/AnsibleRolesSwitcher/components/AnsibleRoleInputs.test.js +19 -0
- data/webpack/components/AnsibleRolesSwitcher/components/AssignedRolesList.js +63 -51
- data/webpack/components/AnsibleRolesSwitcher/components/AssignedRolesList.test.js +3 -0
- data/webpack/components/AnsibleRolesSwitcher/components/OrderedRolesTooltip.js +23 -0
- data/webpack/components/AnsibleRolesSwitcher/components/__snapshots__/AnsibleRoleInputs.test.js.snap +51 -0
- data/webpack/components/AnsibleRolesSwitcher/components/__snapshots__/AssignedRolesList.test.js.snap +28 -28
- data/webpack/components/AnsibleRolesSwitcher/index.js +3 -7
- data/webpack/index.js +6 -0
- metadata +55 -9
- data/app/views/ansible_variables/import.html.erb +0 -56
@@ -13,6 +13,7 @@ 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 },
|
@@ -22,6 +23,7 @@ const fixtures = {
|
|
22
23
|
initialAssignedRoles: [],
|
23
24
|
error: { statusText: '', errorMsg: '' },
|
24
25
|
allAssignedRoles: [],
|
26
|
+
toDestroyRoles: [],
|
25
27
|
availableRolesUrl: 'http://test/roles',
|
26
28
|
},
|
27
29
|
};
|
@@ -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', () =>
|
data/webpack/components/AnsibleRolesSwitcher/__tests__/AnsibleRolesSwitcherSelectors.test.js
CHANGED
@@ -1,13 +1,7 @@
|
|
1
1
|
import { testSelectorsSnapshotWithFixtures } from '@theforeman/test';
|
2
2
|
|
3
|
-
import {
|
4
|
-
|
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', () =>
|
@@ -57,22 +57,17 @@ exports[`AnsibleRolesSwitcher should render 1`] = `
|
|
57
57
|
className="assigned-roles-header"
|
58
58
|
>
|
59
59
|
<h2>
|
60
|
+
<OrderedRolesTooltip />
|
60
61
|
Assigned Ansible Roles
|
61
62
|
</h2>
|
62
63
|
</div>
|
63
64
|
<AssignedRolesList
|
64
|
-
allAssignedRoles={Array []}
|
65
65
|
assignedRoles={Array []}
|
66
|
-
|
67
|
-
onPaginationChange={[Function]}
|
66
|
+
onMoveRole={[Function]}
|
68
67
|
onRemoveRole={[Function]}
|
69
|
-
pagination={
|
70
|
-
Object {
|
71
|
-
"page": 1,
|
72
|
-
"perPage": 12,
|
73
|
-
}
|
74
|
-
}
|
75
68
|
resourceName=""
|
69
|
+
toDestroyRoles={Array []}
|
70
|
+
unassignedRoles={Array []}
|
76
71
|
/>
|
77
72
|
</Col>
|
78
73
|
</Row>
|
@@ -82,87 +82,7 @@ Object {
|
|
82
82
|
"name": "anonymous.something",
|
83
83
|
},
|
84
84
|
],
|
85
|
-
|
86
|
-
`;
|
87
|
-
|
88
|
-
exports[`AnsibleRolesSwitcherReducer should change pagination for assigned roles 1`] = `
|
89
|
-
Object {
|
90
|
-
"assignedPagination": Object {
|
91
|
-
"page": 20,
|
92
|
-
"perPage": 5,
|
93
|
-
},
|
94
|
-
"assignedRoles": Array [
|
95
|
-
Object {
|
96
|
-
"id": 4,
|
97
|
-
"inherited": true,
|
98
|
-
"name": "geerlingguy.java",
|
99
|
-
},
|
100
|
-
Object {
|
101
|
-
"id": 5,
|
102
|
-
"name": "naftulikay.golang",
|
103
|
-
},
|
104
|
-
Object {
|
105
|
-
"id": 6,
|
106
|
-
"name": "theforeman.foreman_scap_client",
|
107
|
-
},
|
108
|
-
],
|
109
|
-
"error": Object {
|
110
|
-
"errorMsg": "",
|
111
|
-
"status": "",
|
112
|
-
"statusText": "",
|
113
|
-
},
|
114
|
-
"itemCount": 11,
|
115
|
-
"loading": false,
|
116
|
-
"pagination": Object {
|
117
|
-
"page": 1,
|
118
|
-
"perPage": 5,
|
119
|
-
},
|
120
|
-
"results": Array [
|
121
|
-
Object {
|
122
|
-
"id": 1,
|
123
|
-
"name": "sthirugn.motd",
|
124
|
-
},
|
125
|
-
Object {
|
126
|
-
"id": 2,
|
127
|
-
"name": "jtyr.ntp",
|
128
|
-
},
|
129
|
-
Object {
|
130
|
-
"id": 3,
|
131
|
-
"name": "rvm.ruby",
|
132
|
-
},
|
133
|
-
Object {
|
134
|
-
"id": 4,
|
135
|
-
"name": "geerlingguy.java",
|
136
|
-
},
|
137
|
-
Object {
|
138
|
-
"id": 5,
|
139
|
-
"name": "naftulikay.golang",
|
140
|
-
},
|
141
|
-
Object {
|
142
|
-
"id": 6,
|
143
|
-
"name": "theforeman.foreman_scap_client",
|
144
|
-
},
|
145
|
-
Object {
|
146
|
-
"id": 7,
|
147
|
-
"name": "ansible.ansible",
|
148
|
-
},
|
149
|
-
Object {
|
150
|
-
"id": 8,
|
151
|
-
"name": "puppet.puppet",
|
152
|
-
},
|
153
|
-
Object {
|
154
|
-
"id": 9,
|
155
|
-
"name": "chef.chef",
|
156
|
-
},
|
157
|
-
Object {
|
158
|
-
"id": 10,
|
159
|
-
"name": "salt.salt",
|
160
|
-
},
|
161
|
-
Object {
|
162
|
-
"id": 11,
|
163
|
-
"name": "anonymous.something",
|
164
|
-
},
|
165
|
-
],
|
85
|
+
"toDestroyRoles": Array [],
|
166
86
|
}
|
167
87
|
`;
|
168
88
|
|
@@ -239,7 +159,10 @@ Object {
|
|
239
159
|
"id": 11,
|
240
160
|
"name": "anonymous.something",
|
241
161
|
},
|
162
|
+
],
|
163
|
+
"toDestroyRoles": Array [
|
242
164
|
Object {
|
165
|
+
"destroy": true,
|
243
166
|
"id": 6,
|
244
167
|
"name": "theforeman.foreman_scap_client",
|
245
168
|
},
|
@@ -249,10 +172,6 @@ Object {
|
|
249
172
|
|
250
173
|
exports[`AnsibleRolesSwitcherReducer should return initial state 1`] = `
|
251
174
|
Object {
|
252
|
-
"assignedPagination": Object {
|
253
|
-
"page": 1,
|
254
|
-
"perPage": 10,
|
255
|
-
},
|
256
175
|
"assignedRoles": Array [],
|
257
176
|
"error": Object {
|
258
177
|
"errorMsg": "",
|
@@ -267,15 +186,12 @@ Object {
|
|
267
186
|
"perPage": 10,
|
268
187
|
},
|
269
188
|
"results": Array [],
|
189
|
+
"toDestroyRoles": Array [],
|
270
190
|
}
|
271
191
|
`;
|
272
192
|
|
273
193
|
exports[`AnsibleRolesSwitcherReducer should start loading on Ansible roles request 1`] = `
|
274
194
|
Object {
|
275
|
-
"assignedPagination": Object {
|
276
|
-
"page": 1,
|
277
|
-
"perPage": 10,
|
278
|
-
},
|
279
195
|
"assignedRoles": Array [],
|
280
196
|
"error": Object {
|
281
197
|
"errorMsg": "",
|
@@ -290,15 +206,12 @@ Object {
|
|
290
206
|
"perPage": 10,
|
291
207
|
},
|
292
208
|
"results": Array [],
|
209
|
+
"toDestroyRoles": Array [],
|
293
210
|
}
|
294
211
|
`;
|
295
212
|
|
296
213
|
exports[`AnsibleRolesSwitcherReducer should stop loading on Ansible roles error 1`] = `
|
297
214
|
Object {
|
298
|
-
"assignedPagination": Object {
|
299
|
-
"page": 1,
|
300
|
-
"perPage": 10,
|
301
|
-
},
|
302
215
|
"assignedRoles": Array [],
|
303
216
|
"error": Object {
|
304
217
|
"errorMsg": "Failed to fetch Ansible Roles from server.",
|
@@ -312,15 +225,12 @@ Object {
|
|
312
225
|
"perPage": 10,
|
313
226
|
},
|
314
227
|
"results": Array [],
|
228
|
+
"toDestroyRoles": Array [],
|
315
229
|
}
|
316
230
|
`;
|
317
231
|
|
318
232
|
exports[`AnsibleRolesSwitcherReducer should stop loading on Ansible roles success 1`] = `
|
319
233
|
Object {
|
320
|
-
"assignedPagination": Object {
|
321
|
-
"page": 1,
|
322
|
-
"perPage": 10,
|
323
|
-
},
|
324
234
|
"assignedRoles": Array [
|
325
235
|
Object {
|
326
236
|
"id": 4,
|
@@ -395,5 +305,6 @@ Object {
|
|
395
305
|
"name": "anonymous.something",
|
396
306
|
},
|
397
307
|
],
|
308
|
+
"toDestroyRoles": Array [],
|
398
309
|
}
|
399
310
|
`;
|
@@ -3,8 +3,8 @@
|
|
3
3
|
exports[`AnsibleRolesSwitcherSelectors should return all roles when no roles assigned 1`] = `
|
4
4
|
Array [
|
5
5
|
Object {
|
6
|
-
"id":
|
7
|
-
"name": "
|
6
|
+
"id": 1,
|
7
|
+
"name": "sthirugn.motd",
|
8
8
|
},
|
9
9
|
Object {
|
10
10
|
"id": 2,
|
@@ -15,46 +15,21 @@ Array [
|
|
15
15
|
"name": "rvm.ruby",
|
16
16
|
},
|
17
17
|
Object {
|
18
|
-
"id":
|
19
|
-
"name": "
|
18
|
+
"id": 4,
|
19
|
+
"name": "geerlingguy.java",
|
20
20
|
},
|
21
21
|
]
|
22
22
|
`;
|
23
23
|
|
24
|
-
exports[`AnsibleRolesSwitcherSelectors should return
|
24
|
+
exports[`AnsibleRolesSwitcherSelectors should return unassigned roles 1`] = `
|
25
25
|
Array [
|
26
|
-
Object {
|
27
|
-
"id": 5,
|
28
|
-
"name": "naftulikay.golang",
|
29
|
-
},
|
30
|
-
Object {
|
31
|
-
"id": 8,
|
32
|
-
"name": "puppet.puppet",
|
33
|
-
},
|
34
|
-
Object {
|
35
|
-
"id": 3,
|
36
|
-
"name": "rvm.ruby",
|
37
|
-
},
|
38
|
-
Object {
|
39
|
-
"id": 10,
|
40
|
-
"name": "salt.salt",
|
41
|
-
},
|
42
26
|
Object {
|
43
27
|
"id": 1,
|
44
28
|
"name": "sthirugn.motd",
|
45
29
|
},
|
46
|
-
]
|
47
|
-
`;
|
48
|
-
|
49
|
-
exports[`AnsibleRolesSwitcherSelectors should return unassigned roles 1`] = `
|
50
|
-
Array [
|
51
30
|
Object {
|
52
31
|
"id": 3,
|
53
32
|
"name": "rvm.ruby",
|
54
33
|
},
|
55
|
-
Object {
|
56
|
-
"id": 1,
|
57
|
-
"name": "sthirugn.motd",
|
58
|
-
},
|
59
34
|
]
|
60
35
|
`;
|
@@ -6,7 +6,7 @@ import { translate as __ } from 'foremanReact/common/I18n';
|
|
6
6
|
import AnsibleRoleActionButton from './AnsibleRoleActionButton';
|
7
7
|
import '../AnsibleRolesSwitcher.scss';
|
8
8
|
|
9
|
-
const AnsibleRole = ({ role, icon, onClick, resourceName }) => {
|
9
|
+
const AnsibleRole = ({ role, icon, onClick, resourceName, index }) => {
|
10
10
|
const text =
|
11
11
|
resourceName === 'hostgroup'
|
12
12
|
? __('This Ansible role is inherited from parent host group')
|
@@ -23,6 +23,9 @@ const AnsibleRole = ({ role, icon, onClick, resourceName }) => {
|
|
23
23
|
onClickFn(ansibleRole);
|
24
24
|
};
|
25
25
|
|
26
|
+
const headingText = (name, idx) =>
|
27
|
+
idx || idx === 0 ? `${idx + 1}. ${name}` : name;
|
28
|
+
|
26
29
|
const listItem = (click = undefined) => (
|
27
30
|
<ListView.Item
|
28
31
|
id={role.id}
|
@@ -30,7 +33,7 @@ const AnsibleRole = ({ role, icon, onClick, resourceName }) => {
|
|
30
33
|
'ansible-role-disabled': role.inherited,
|
31
34
|
'ansible-role-movable': !role.inherited,
|
32
35
|
})}
|
33
|
-
heading={role.name}
|
36
|
+
heading={headingText(role.name, index)}
|
34
37
|
actions={
|
35
38
|
role.inherited ? (
|
36
39
|
''
|
@@ -0,0 +1,43 @@
|
|
1
|
+
import React from 'react';
|
2
|
+
import PropTypes from 'prop-types';
|
3
|
+
|
4
|
+
const AnsibleRoleInputs = props => {
|
5
|
+
const { role, idx, resourceName } = props;
|
6
|
+
|
7
|
+
const fieldName = attr =>
|
8
|
+
`${resourceName}[${resourceName}_ansible_roles_attributes][${idx}][${attr}]`;
|
9
|
+
|
10
|
+
const attrName = modelName => `${modelName}AnsibleRoleId`;
|
11
|
+
|
12
|
+
const idField = (
|
13
|
+
<input
|
14
|
+
name={fieldName('id')}
|
15
|
+
value={role[attrName(resourceName)]}
|
16
|
+
type="hidden"
|
17
|
+
/>
|
18
|
+
);
|
19
|
+
return (
|
20
|
+
<React.Fragment>
|
21
|
+
{role[attrName(resourceName)] ? idField : null}
|
22
|
+
<input
|
23
|
+
name={fieldName('ansible_role_id')}
|
24
|
+
value={role.id}
|
25
|
+
type="hidden"
|
26
|
+
/>
|
27
|
+
<input name={fieldName('position')} value={idx + 1} type="hidden" />
|
28
|
+
<input
|
29
|
+
name={fieldName('_destroy')}
|
30
|
+
value={!!role.destroy}
|
31
|
+
type="hidden"
|
32
|
+
/>
|
33
|
+
</React.Fragment>
|
34
|
+
);
|
35
|
+
};
|
36
|
+
|
37
|
+
AnsibleRoleInputs.propTypes = {
|
38
|
+
role: PropTypes.object.isRequired,
|
39
|
+
idx: PropTypes.number.isRequired,
|
40
|
+
resourceName: PropTypes.string.isRequired,
|
41
|
+
};
|
42
|
+
|
43
|
+
export default AnsibleRoleInputs;
|
@@ -0,0 +1,19 @@
|
|
1
|
+
import { testComponentSnapshotsWithFixtures } from '@theforeman/test';
|
2
|
+
|
3
|
+
import AnsibleRoleInputs from './AnsibleRoleInputs';
|
4
|
+
|
5
|
+
const fixtures = {
|
6
|
+
'should render role to add': {
|
7
|
+
role: { id: 2, name: 'test.role', hostAnsibleRoleId: 5, position: 2 },
|
8
|
+
resourceName: 'host',
|
9
|
+
idx: 14,
|
10
|
+
},
|
11
|
+
'should render role to remove': {
|
12
|
+
role: { id: 2, name: 'test.role', hostAnsibleRoleId: 5, destroy: true },
|
13
|
+
resourceName: 'host',
|
14
|
+
idx: 14,
|
15
|
+
},
|
16
|
+
};
|
17
|
+
|
18
|
+
describe('AnsibleRoleInputs', () =>
|
19
|
+
testComponentSnapshotsWithFixtures(AnsibleRoleInputs, fixtures));
|
@@ -1,79 +1,91 @@
|
|
1
1
|
import React from 'react';
|
2
|
+
import { DndProvider } from 'react-dnd';
|
3
|
+
import HTML5Backend from 'react-dnd-html5-backend';
|
4
|
+
|
2
5
|
import { ListView } from 'patternfly-react';
|
3
|
-
|
4
|
-
import {
|
6
|
+
|
7
|
+
import {
|
8
|
+
orderable,
|
9
|
+
orderDragged,
|
10
|
+
} from 'foremanReact/components/common/forms/OrderableSelect/helpers';
|
11
|
+
|
5
12
|
import PropTypes from 'prop-types';
|
6
13
|
|
7
14
|
import AnsibleRole from './AnsibleRole';
|
15
|
+
import AnsibleRoleInputs from './AnsibleRoleInputs';
|
16
|
+
|
17
|
+
const OrderableRole = orderable(AnsibleRole, {
|
18
|
+
type: 'ansibleRole',
|
19
|
+
getItem: props => ({ id: props.role.id }),
|
20
|
+
direction: 'vertical',
|
21
|
+
});
|
8
22
|
|
9
23
|
const AssignedRolesList = ({
|
24
|
+
unassignedRoles,
|
10
25
|
assignedRoles,
|
11
|
-
|
12
|
-
pagination,
|
13
|
-
itemCount,
|
14
|
-
onPaginationChange,
|
26
|
+
toDestroyRoles,
|
15
27
|
onRemoveRole,
|
28
|
+
onMoveRole,
|
16
29
|
resourceName,
|
17
30
|
}) => {
|
18
|
-
const
|
19
|
-
|
31
|
+
const moveValue = (dragIndex, hoverIndex) => {
|
32
|
+
onMoveRole(orderDragged(assignedRoles, dragIndex, hoverIndex));
|
33
|
+
};
|
34
|
+
|
35
|
+
const allOwnRoles = roles => roles.filter(role => !role.inherited);
|
36
|
+
|
37
|
+
const renderRole = (role, idx) =>
|
38
|
+
role.inherited ? renderInherited(role, idx) : renderOwn(role, idx);
|
39
|
+
|
40
|
+
const renderInherited = (role, idx) => (
|
41
|
+
<AnsibleRole
|
42
|
+
key={role.id}
|
43
|
+
role={role}
|
44
|
+
index={idx}
|
45
|
+
icon="fa fa-minus-circle"
|
46
|
+
onClick={onRemoveRole}
|
47
|
+
resourceName={resourceName}
|
48
|
+
/>
|
49
|
+
);
|
50
|
+
|
51
|
+
const renderOwn = (role, idx) => (
|
52
|
+
<OrderableRole
|
53
|
+
key={role.id}
|
54
|
+
role={role}
|
55
|
+
index={idx}
|
56
|
+
moveValue={moveValue}
|
57
|
+
icon="fa fa-minus-circle"
|
58
|
+
onClick={onRemoveRole}
|
59
|
+
resourceName={resourceName}
|
60
|
+
/>
|
20
61
|
);
|
21
62
|
|
22
63
|
return (
|
23
|
-
<
|
24
|
-
<ListView>
|
25
|
-
<div className="sticky-pagination sticky-pagination-grey">
|
26
|
-
<PaginationWrapper
|
27
|
-
viewType="list"
|
28
|
-
itemCount={itemCount}
|
29
|
-
pagination={pagination}
|
30
|
-
onChange={onPaginationChange}
|
31
|
-
dropdownButtonId="assigned-ansible-roles-pagination-row-dropdown"
|
32
|
-
/>
|
33
|
-
</div>
|
34
|
-
{assignedRoles.map(role => (
|
35
|
-
<AnsibleRole
|
36
|
-
key={role.id}
|
37
|
-
role={role}
|
38
|
-
icon="fa fa-minus-circle"
|
39
|
-
onClick={onRemoveRole}
|
40
|
-
resourceName={resourceName}
|
41
|
-
/>
|
42
|
-
))}
|
43
|
-
</ListView>
|
64
|
+
<DndProvider backend={HTML5Backend}>
|
65
|
+
<ListView>{assignedRoles.map(renderRole)}</ListView>
|
44
66
|
<div>
|
45
|
-
{
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
value=""
|
50
|
-
/>
|
51
|
-
) : (
|
52
|
-
directlyAssignedRoles.map(role => (
|
53
|
-
<input
|
67
|
+
{allOwnRoles(assignedRoles)
|
68
|
+
.concat(toDestroyRoles)
|
69
|
+
.map((role, idx) => (
|
70
|
+
<AnsibleRoleInputs
|
54
71
|
key={role.id}
|
55
|
-
|
56
|
-
|
57
|
-
|
72
|
+
role={role}
|
73
|
+
idx={idx}
|
74
|
+
resourceName={resourceName}
|
58
75
|
/>
|
59
|
-
))
|
60
|
-
)}
|
76
|
+
))}
|
61
77
|
</div>
|
62
|
-
</
|
78
|
+
</DndProvider>
|
63
79
|
);
|
64
80
|
};
|
65
81
|
|
66
82
|
AssignedRolesList.propTypes = {
|
83
|
+
unassignedRoles: PropTypes.arrayOf(PropTypes.object).isRequired,
|
67
84
|
assignedRoles: PropTypes.arrayOf(PropTypes.object).isRequired,
|
68
|
-
allAssignedRoles: PropTypes.arrayOf(PropTypes.object).isRequired,
|
69
|
-
pagination: PropTypes.shape({
|
70
|
-
page: PropTypes.number,
|
71
|
-
perPage: PropTypes.number,
|
72
|
-
}).isRequired,
|
73
|
-
itemCount: PropTypes.number.isRequired,
|
74
|
-
onPaginationChange: PropTypes.func.isRequired,
|
75
85
|
onRemoveRole: PropTypes.func.isRequired,
|
86
|
+
onMoveRole: PropTypes.func.isRequired,
|
76
87
|
resourceName: PropTypes.string.isRequired,
|
88
|
+
toDestroyRoles: PropTypes.arrayOf(PropTypes.object).isRequired,
|
77
89
|
};
|
78
90
|
|
79
91
|
export default AssignedRolesList;
|