foreman-tasks 1.0.1 → 2.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (169) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +12 -12
  3. data/.rubocop_todo.yml +34 -116
  4. data/README.md +2 -0
  5. data/app/controllers/foreman_tasks/api/recurring_logics_controller.rb +20 -1
  6. data/app/controllers/foreman_tasks/api/tasks_controller.rb +65 -10
  7. data/app/controllers/foreman_tasks/concerns/hosts_controller_extension.rb +1 -1
  8. data/app/controllers/foreman_tasks/recurring_logics_controller.rb +19 -0
  9. data/app/controllers/foreman_tasks/tasks_controller.rb +9 -14
  10. data/app/helpers/foreman_tasks/foreman_tasks_helper.rb +1 -3
  11. data/app/lib/actions/helpers/humanizer.rb +1 -3
  12. data/app/lib/actions/proxy_action.rb +33 -12
  13. data/app/lib/foreman_tasks/concerns/polling_action_extensions.rb +12 -0
  14. data/app/models/foreman_tasks/concerns/action_triggering.rb +1 -1
  15. data/app/models/foreman_tasks/recurring_logic.rb +1 -0
  16. data/app/models/foreman_tasks/remote_task.rb +1 -0
  17. data/app/models/foreman_tasks/task.rb +8 -0
  18. data/app/models/foreman_tasks/task/dynflow_task.rb +2 -1
  19. data/app/models/foreman_tasks/task/search.rb +11 -1
  20. data/app/models/setting/foreman_tasks.rb +7 -2
  21. data/app/services/foreman_tasks/troubleshooting_help_generator.rb +0 -4
  22. data/app/services/ui_notifications/tasks/task_bulk_cancel.rb +36 -0
  23. data/app/services/ui_notifications/tasks/task_bulk_resume.rb +38 -0
  24. data/app/services/ui_notifications/tasks/task_bulk_stop.rb +36 -0
  25. data/app/views/foreman_tasks/api/recurring_logics/base.json.rabl +2 -1
  26. data/app/views/foreman_tasks/api/tasks/details.json.rabl +1 -1
  27. data/app/views/foreman_tasks/api/tasks/show.json.rabl +1 -1
  28. data/app/views/foreman_tasks/recurring_logics/index.html.erb +30 -0
  29. data/app/views/foreman_tasks/tasks/show.html.erb +3 -0
  30. data/config/routes.rb +8 -0
  31. data/db/migrate/20200517215015_rename_bookmarks_controller.rb +35 -0
  32. data/db/migrate/20200519093217_drop_dynflow_allow_dangerous_actions_setting.foreman_tasks.rb +5 -0
  33. data/db/migrate/20200611090846_add_task_lock_index_on_resource_type_and_task_id.rb +9 -0
  34. data/db/seeds.d/30-notification_blueprints.rb +21 -0
  35. data/foreman-tasks.gemspec +5 -6
  36. data/gemfile.d/foreman-tasks.rb +1 -0
  37. data/lib/foreman_tasks/dynflow/console_authorizer.rb +2 -2
  38. data/lib/foreman_tasks/engine.rb +17 -19
  39. data/lib/foreman_tasks/tasks/cleanup.rake +1 -1
  40. data/lib/foreman_tasks/tasks/export_tasks.rake +2 -2
  41. data/lib/foreman_tasks/test_extensions.rb +1 -1
  42. data/lib/foreman_tasks/version.rb +1 -1
  43. data/locale/action_names.rb +2 -2
  44. data/locale/en/LC_MESSAGES/foreman_tasks.mo +0 -0
  45. data/locale/en/foreman_tasks.po +270 -54
  46. data/locale/foreman_tasks.pot +630 -292
  47. data/locale/fr/LC_MESSAGES/foreman_tasks.mo +0 -0
  48. data/locale/fr/foreman_tasks.po +817 -0
  49. data/locale/ja/LC_MESSAGES/foreman_tasks.mo +0 -0
  50. data/locale/ja/foreman_tasks.po +817 -0
  51. data/locale/zh_CN/LC_MESSAGES/foreman_tasks.mo +0 -0
  52. data/locale/zh_CN/foreman_tasks.po +816 -0
  53. data/package.json +1 -2
  54. data/script/rails +2 -2
  55. data/script/travis_run_js_tests.sh +2 -2
  56. data/test/factories/task_factory.rb +34 -2
  57. data/test/foreman_tasks_test_helper.rb +4 -0
  58. data/test/lib/concerns/polling_action_extensions_test.rb +34 -0
  59. data/test/unit/actions/action_with_sub_plans_test.rb +1 -1
  60. data/test/unit/task_test.rb +160 -74
  61. data/webpack/ForemanTasks/Components/TaskActions/TaskAction.test.js +60 -0
  62. data/webpack/ForemanTasks/Components/TaskActions/TaskActionHelpers.js +67 -0
  63. data/webpack/ForemanTasks/Components/TaskActions/TaskActionHelpers.test.js +46 -0
  64. data/webpack/ForemanTasks/Components/TaskActions/TaskActionsConstants.js +16 -0
  65. data/webpack/ForemanTasks/Components/TaskActions/UnlockModals.js +60 -0
  66. data/webpack/ForemanTasks/Components/TaskActions/UnlockModals.test.js +14 -0
  67. data/webpack/ForemanTasks/Components/TaskActions/__snapshots__/TaskAction.test.js.snap +233 -0
  68. data/webpack/ForemanTasks/Components/TaskActions/__snapshots__/UnlockModals.test.js.snap +25 -0
  69. data/webpack/ForemanTasks/Components/TaskActions/index.js +115 -0
  70. data/webpack/ForemanTasks/Components/TaskDetails/Components/RunningSteps.js +17 -3
  71. data/webpack/ForemanTasks/Components/TaskDetails/Components/Task.js +132 -165
  72. data/webpack/ForemanTasks/Components/TaskDetails/Components/TaskInfo.js +3 -12
  73. data/webpack/ForemanTasks/Components/TaskDetails/Components/__tests__/RunningSteps.test.js +8 -1
  74. data/webpack/ForemanTasks/Components/TaskDetails/Components/__tests__/Task.test.js +68 -3
  75. data/webpack/ForemanTasks/Components/TaskDetails/Components/__tests__/TaskInfo.test.js +0 -1
  76. data/webpack/ForemanTasks/Components/TaskDetails/Components/__tests__/__snapshots__/RunningSteps.test.js.snap +1 -1
  77. data/webpack/ForemanTasks/Components/TaskDetails/Components/__tests__/__snapshots__/Task.test.js.snap +108 -75
  78. data/webpack/ForemanTasks/Components/TaskDetails/Components/__tests__/__snapshots__/TaskInfo.test.js.snap +3 -9
  79. data/webpack/ForemanTasks/Components/TaskDetails/TaskDetails.js +35 -5
  80. data/webpack/ForemanTasks/Components/TaskDetails/TaskDetailsActions.js +34 -14
  81. data/webpack/ForemanTasks/Components/TaskDetails/TaskDetailsConstants.js +3 -4
  82. data/webpack/ForemanTasks/Components/TaskDetails/TaskDetailsReducer.js +0 -6
  83. data/webpack/ForemanTasks/Components/TaskDetails/TaskDetailsSelectors.js +4 -10
  84. data/webpack/ForemanTasks/Components/TaskDetails/TasksDetailsHelper.js +6 -1
  85. data/webpack/ForemanTasks/Components/TaskDetails/__tests__/TaskDetails.fixtures.js +8 -0
  86. data/webpack/ForemanTasks/Components/TaskDetails/__tests__/TaskDetails.test.js +7 -1
  87. data/webpack/ForemanTasks/Components/TaskDetails/__tests__/TaskDetailsActions.test.js +18 -2
  88. data/webpack/ForemanTasks/Components/TaskDetails/__tests__/__snapshots__/TaskDetails.test.js.snap +30 -13
  89. data/webpack/ForemanTasks/Components/TaskDetails/__tests__/__snapshots__/TaskDetailsActions.test.js.snap +91 -0
  90. data/webpack/ForemanTasks/Components/TaskDetails/__tests__/integration.test.js +13 -4
  91. data/webpack/ForemanTasks/Components/TaskDetails/index.js +6 -8
  92. data/webpack/ForemanTasks/Components/TasksDashboard/TasksDashboardActions.js +1 -1
  93. data/webpack/ForemanTasks/Components/TasksDashboard/TasksDashboardConstants.js +5 -0
  94. data/webpack/ForemanTasks/Components/TasksDashboard/TasksDashboardHelper.js +3 -2
  95. data/webpack/ForemanTasks/Components/TasksDashboard/__tests__/TasksDashboardActions.test.js +2 -2
  96. data/webpack/ForemanTasks/Components/TasksTable/Components/ActionSelectButton.js +14 -1
  97. data/webpack/ForemanTasks/Components/TasksTable/Components/ConfirmModal/ConfirmModal.js +83 -0
  98. data/webpack/ForemanTasks/Components/TasksTable/Components/ConfirmModal/ConfirmModalActions.js +106 -0
  99. data/webpack/ForemanTasks/Components/TasksTable/Components/ConfirmModal/ConfirmModalReducer.js +38 -0
  100. data/webpack/ForemanTasks/Components/TasksTable/Components/ConfirmModal/ConfirmModalSelectors.js +45 -0
  101. data/webpack/ForemanTasks/Components/TasksTable/Components/ConfirmModal/__test__/ConfirmModal.test.js +36 -0
  102. data/webpack/ForemanTasks/Components/TasksTable/Components/ConfirmModal/__test__/ConfirmModalActions.test.js +205 -0
  103. data/webpack/ForemanTasks/Components/TasksTable/Components/ConfirmModal/__test__/ConfirmModalReducer.test.js +27 -0
  104. data/webpack/ForemanTasks/Components/TasksTable/Components/ConfirmModal/__test__/ConfirmModalSelectors.test.js +54 -0
  105. data/webpack/ForemanTasks/Components/TasksTable/Components/ConfirmModal/__test__/__snapshots__/ConfirmModal.test.js.snap +41 -0
  106. data/webpack/ForemanTasks/Components/TasksTable/Components/ConfirmModal/__test__/__snapshots__/ConfirmModalReducer.test.js.snap +19 -0
  107. data/webpack/ForemanTasks/Components/TasksTable/Components/ConfirmModal/__test__/__snapshots__/ConfirmModalSelectors.test.js.snap +30 -0
  108. data/webpack/ForemanTasks/Components/TasksTable/Components/ConfirmModal/index.js +29 -0
  109. data/webpack/ForemanTasks/Components/TasksTable/Components/SelectAllAlert.js +43 -0
  110. data/webpack/ForemanTasks/Components/TasksTable/Components/__test__/ActionSelectButton.test.js +1 -0
  111. data/webpack/ForemanTasks/Components/TasksTable/Components/__test__/SelectAllAlert.test.js +29 -0
  112. data/webpack/ForemanTasks/Components/TasksTable/Components/__test__/__snapshots__/ActionSelectButton.test.js.snap +11 -0
  113. data/webpack/ForemanTasks/Components/TasksTable/Components/__test__/__snapshots__/SelectAllAlert.test.js.snap +75 -0
  114. data/webpack/ForemanTasks/Components/TasksTable/SubTasksPage.js +4 -1
  115. data/webpack/ForemanTasks/Components/TasksTable/TasksBulkActions.js +247 -0
  116. data/webpack/ForemanTasks/Components/TasksTable/TasksTable.js +37 -19
  117. data/webpack/ForemanTasks/Components/TasksTable/TasksTableActions.js +56 -92
  118. data/webpack/ForemanTasks/Components/TasksTable/TasksTableConstants.js +19 -11
  119. data/webpack/ForemanTasks/Components/TasksTable/TasksTableHelpers.js +4 -3
  120. data/webpack/ForemanTasks/Components/TasksTable/TasksTablePage.js +64 -73
  121. data/webpack/ForemanTasks/Components/TasksTable/TasksTableReducer.js +21 -2
  122. data/webpack/ForemanTasks/Components/TasksTable/TasksTableSchema.js +2 -2
  123. data/webpack/ForemanTasks/Components/TasksTable/TasksTableSelectors.js +13 -4
  124. data/webpack/ForemanTasks/Components/TasksTable/__tests__/TasksBulkActions.test.js +147 -0
  125. data/webpack/ForemanTasks/Components/TasksTable/__tests__/TasksTable.fixtures.js +3 -10
  126. data/webpack/ForemanTasks/Components/TasksTable/__tests__/TasksTableActions.test.js +46 -74
  127. data/webpack/ForemanTasks/Components/TasksTable/__tests__/TasksTableHelpers.test.js +17 -1
  128. data/webpack/ForemanTasks/Components/TasksTable/__tests__/TasksTablePage.test.js +9 -1
  129. data/webpack/ForemanTasks/Components/TasksTable/__tests__/TasksTableReducer.test.js +22 -1
  130. data/webpack/ForemanTasks/Components/TasksTable/__tests__/__snapshots__/SubTasksPage.test.js.snap +4 -12
  131. data/webpack/ForemanTasks/Components/TasksTable/__tests__/__snapshots__/TasksBulkActions.test.js.snap +336 -0
  132. data/webpack/ForemanTasks/Components/TasksTable/__tests__/__snapshots__/TasksIndexPage.test.js.snap +3 -12
  133. data/webpack/ForemanTasks/Components/TasksTable/__tests__/__snapshots__/TasksTableActions.test.js.snap +22 -158
  134. data/webpack/ForemanTasks/Components/TasksTable/__tests__/__snapshots__/TasksTablePage.test.js.snap +56 -132
  135. data/webpack/ForemanTasks/Components/TasksTable/__tests__/__snapshots__/TasksTableReducer.test.js.snap +34 -0
  136. data/webpack/ForemanTasks/Components/TasksTable/formatters/__test__/selectionHeaderCellFormatter.test.js +1 -1
  137. data/webpack/ForemanTasks/Components/TasksTable/formatters/selectionHeaderCellFormatter.js +2 -2
  138. data/webpack/ForemanTasks/Components/TasksTable/index.js +10 -4
  139. data/webpack/ForemanTasks/Components/common/ActionButtons/ActionButton.js +47 -19
  140. data/webpack/ForemanTasks/Components/common/ActionButtons/ActionButton.test.js +61 -14
  141. data/webpack/ForemanTasks/Components/common/ActionButtons/__snapshots__/ActionButton.test.js.snap +80 -21
  142. data/webpack/ForemanTasks/Components/common/ClickConfirmation/ClickConfirmation.scss +9 -0
  143. data/webpack/ForemanTasks/Components/common/ClickConfirmation/ClickConfirmation.test.js +44 -0
  144. data/webpack/ForemanTasks/Components/common/ClickConfirmation/__snapshots__/ClickConfirmation.test.js.snap +52 -0
  145. data/webpack/ForemanTasks/Components/common/ClickConfirmation/index.js +59 -66
  146. data/webpack/ForemanTasks/Components/common/ToastsHelpers/ToastTypesConstants.js +11 -0
  147. data/webpack/ForemanTasks/Components/common/ToastsHelpers/index.js +15 -0
  148. data/webpack/ForemanTasks/ForemanTasksReducers.js +2 -0
  149. data/webpack/ForemanTasks/Routes/ForemanTasksRoutes.test.js +2 -1
  150. data/webpack/__mocks__/foremanReact/components/ForemanModal/ForemanModalHooks.js +2 -2
  151. data/webpack/__mocks__/foremanReact/components/ForemanModal/index.js +17 -3
  152. data/webpack/__mocks__/foremanReact/components/common/ActionButtons/ActionButtons.js +3 -0
  153. data/webpack/__mocks__/foremanReact/{API.js → redux/API.js} +1 -1
  154. metadata +76 -27
  155. data/webpack/ForemanTasks/Components/TasksTable/Components/CancelConfirm.js +0 -53
  156. data/webpack/ForemanTasks/Components/TasksTable/Components/ConfirmationModals.js +0 -56
  157. data/webpack/ForemanTasks/Components/TasksTable/Components/ResumeConfirm.js +0 -52
  158. data/webpack/ForemanTasks/Components/TasksTable/Components/__test__/CancelConfirm.test.js +0 -26
  159. data/webpack/ForemanTasks/Components/TasksTable/Components/__test__/ConfirmationModals.test.js +0 -24
  160. data/webpack/ForemanTasks/Components/TasksTable/Components/__test__/ResumeConfirm.test.js +0 -26
  161. data/webpack/ForemanTasks/Components/TasksTable/Components/__test__/__snapshots__/CancelConfirm.test.js.snap +0 -65
  162. data/webpack/ForemanTasks/Components/TasksTable/Components/__test__/__snapshots__/ConfirmationModals.test.js.snap +0 -30
  163. data/webpack/ForemanTasks/Components/TasksTable/Components/__test__/__snapshots__/ResumeConfirm.test.js.snap +0 -63
  164. data/webpack/ForemanTasks/Components/common/ActionButtons/CancelButton.js +0 -23
  165. data/webpack/ForemanTasks/Components/common/ActionButtons/CancelButton.test.js +0 -26
  166. data/webpack/ForemanTasks/Components/common/ActionButtons/ResumeButton.js +0 -23
  167. data/webpack/ForemanTasks/Components/common/ActionButtons/ResumeButton.test.js +0 -27
  168. data/webpack/ForemanTasks/Components/common/ActionButtons/__snapshots__/CancelButton.test.js.snap +0 -15
  169. data/webpack/ForemanTasks/Components/common/ActionButtons/__snapshots__/ResumeButton.test.js.snap +0 -15
@@ -0,0 +1,67 @@
1
+ import { translate as __, sprintf } from 'foremanReact/common/I18n';
2
+ import { addToast } from 'foremanReact/redux/actions/toasts';
3
+ import { TASKS_DASHBOARD_JS_QUERY_MODES } from '../TasksDashboard/TasksDashboardConstants';
4
+ import { timeToHoursNumber } from '../TasksDashboard/TasksDashboardHelper';
5
+ import {
6
+ successToastData,
7
+ errorToastData,
8
+ warningToastData,
9
+ } from '../common/ToastsHelpers';
10
+
11
+ export const convertDashboardQuery = query => {
12
+ const {
13
+ time_mode: timeMode,
14
+ time_horizon: timeHorizon,
15
+ state,
16
+ result,
17
+ search,
18
+ } = query;
19
+
20
+ const hours = timeToHoursNumber(timeHorizon);
21
+ const timestamp = new Date(new Date() - hours * 60 * 60 * 1000);
22
+ let dashboardTime = '';
23
+ const stateQuery = state ? `state=${state}` : '';
24
+ const resultQuery = result ? `result=${result}` : '';
25
+ if (timeMode === TASKS_DASHBOARD_JS_QUERY_MODES.RECENT) {
26
+ dashboardTime = `(state_updated_at>${timestamp.toISOString()} or state_updated_at = NULL)`;
27
+ } else if (timeMode === TASKS_DASHBOARD_JS_QUERY_MODES.OLDER) {
28
+ dashboardTime = `(state_updated_at>${timestamp.toISOString()})`;
29
+ }
30
+ const newQuery = [stateQuery, resultQuery, search, dashboardTime]
31
+ .filter(Boolean)
32
+ .join(' and ');
33
+ return newQuery;
34
+ };
35
+
36
+ export const resumeToastInfo = {
37
+ resumed: successToastData(__('was resumed')),
38
+ failed: errorToastData(__('could not be resumed')),
39
+ skipped: warningToastData(__('task has to be resumable')),
40
+ };
41
+
42
+ export const cancelToastInfo = {
43
+ cancelled: successToastData(__('was cancelled')),
44
+ skipped: warningToastData(__('task has to be cancellable')),
45
+ };
46
+
47
+ export const forceCancelToastInfo = {
48
+ forceCancelled: successToastData(__('resources were unlocked with force.')),
49
+ failed: warningToastData(__('cannot be cancelled with force at the moment.')),
50
+ };
51
+
52
+ export const unlockToastInfo = {
53
+ unlocked: successToastData(__('resources were unlocked ')),
54
+ failed: warningToastData(__('resources cannot be unlocked at the moment.')),
55
+ };
56
+
57
+ export const toastDispatch = ({ type, name, toastInfo, dispatch }) => {
58
+ dispatch(
59
+ addToast({
60
+ type: toastInfo[type].type,
61
+ message: sprintf('%(name)s Task execution %(type)s', {
62
+ name,
63
+ type: toastInfo[type].message,
64
+ }),
65
+ })
66
+ );
67
+ };
@@ -0,0 +1,46 @@
1
+ import { convertDashboardQuery } from './TaskActionHelpers';
2
+ import {
3
+ TASKS_DASHBOARD_JS_QUERY_MODES,
4
+ TASKS_DASHBOARD_AVAILABLE_TIMES,
5
+ } from '../TasksDashboard/TasksDashboardConstants';
6
+
7
+ let realDate;
8
+
9
+ describe('convertDashboardQuery', () => {
10
+ it('convertDashboardQuery should work with full query', () => {
11
+ // Setup
12
+ const currentDate = new Date('2020-05-08T11:01:58.135Z');
13
+ realDate = Date;
14
+ global.Date = class extends Date {
15
+ constructor(date) {
16
+ if (date) {
17
+ // eslint-disable-next-line constructor-super
18
+ return super(date);
19
+ }
20
+ return currentDate;
21
+ }
22
+ };
23
+ const query = {
24
+ time_mode: TASKS_DASHBOARD_JS_QUERY_MODES.RECENT,
25
+ time_horizon: TASKS_DASHBOARD_AVAILABLE_TIMES.WEEK,
26
+ state: 'stopped',
27
+ result: 'error',
28
+ search: 'action~job',
29
+ };
30
+ expect(convertDashboardQuery(query)).toEqual(
31
+ 'state=stopped and result=error and action~job and (state_updated_at>2020-05-01T11:01:58.135Z or state_updated_at = NULL)'
32
+ );
33
+ // Cleanup
34
+ global.Date = realDate;
35
+ });
36
+ it('convertDashboardQuery should work with only search query', () => {
37
+ const query = {
38
+ search: 'action~job',
39
+ };
40
+ expect(convertDashboardQuery(query)).toEqual('action~job');
41
+ });
42
+ it('convertDashboardQuery should work with no query', () => {
43
+ const query = {};
44
+ expect(convertDashboardQuery(query)).toEqual('');
45
+ });
46
+ });
@@ -0,0 +1,16 @@
1
+ export const UNLOCK_MODAL = 'unlockModal';
2
+ export const FORCE_UNLOCK_MODAL = 'forceUnlockModal';
3
+
4
+ export const TASKS_RESUME_REQUEST = 'TASKS_RESUME_REQUEST';
5
+ export const TASKS_RESUME_SUCCESS = 'TASKS_RESUME_SUCCESS';
6
+ export const TASKS_RESUME_FAILURE = 'TASKS_RESUME_FAILURE';
7
+ export const TASKS_CANCEL_REQUEST = 'TASKS_CANCEL_REQUEST';
8
+ export const TASKS_CANCEL_SUCCESS = 'TASKS_CANCEL_SUCCESS';
9
+ export const TASKS_CANCEL_FAILURE = 'TASKS_CANCEL_FAILURE';
10
+
11
+ export const TASKS_FORCE_CANCEL_REQUEST = 'TASKS_FORCE_CANCEL_REQUEST';
12
+ export const TASKS_FORCE_CANCEL_SUCCESS = 'TASKS_FORCE_CANCEL_SUCCESS';
13
+ export const TASKS_FORCE_CANCEL_FAILURE = 'TASKS_FORCE_CANCEL_FAILURE';
14
+ export const TASKS_UNLOCK_REQUEST = 'TASKS_UNLOCK_REQUEST';
15
+ export const TASKS_UNLOCK_SUCCESS = 'TASKS_UNLOCK_SUCCESS';
16
+ export const TASKS_UNLOCK_FAILURE = 'TASKS_UNLOCK_FAILURE';
@@ -0,0 +1,60 @@
1
+ import React from 'react';
2
+ import PropTypes from 'prop-types';
3
+ import { translate as __, sprintf } from 'foremanReact/common/I18n';
4
+ import { ClickConfirmation } from '../common/ClickConfirmation';
5
+ import { UNLOCK_MODAL, FORCE_UNLOCK_MODAL } from './TaskActionsConstants';
6
+
7
+ const confirmationMessage = __(
8
+ 'I understand that this may cause harm and have working database backups of all backend services.'
9
+ );
10
+
11
+ export const UnlockModal = ({ onClick, id }) => (
12
+ <ClickConfirmation
13
+ id={id}
14
+ title={__('Unlock')}
15
+ body={__(
16
+ "This will unlock the resources that the task is running against. Please note that this might lead to inconsistent state and should be used with caution, after making sure that the task can't be resumed."
17
+ )}
18
+ confirmationMessage={confirmationMessage}
19
+ confirmAction={__('Unlock')}
20
+ onClick={onClick}
21
+ confirmType="warning"
22
+ />
23
+ );
24
+
25
+ export const ForceUnlockModal = ({ onClick, id, selectedRowsLen }) => (
26
+ <ClickConfirmation
27
+ id={id}
28
+ title={__('Force Unlock')}
29
+ body={sprintf(
30
+ __(
31
+ `Resources for %s task(s) will be unlocked and will not prevent other tasks from being run. As the task(s) might be still running, it should be avoided to use this unless you are really sure the task(s) got stuck.`
32
+ ),
33
+ selectedRowsLen
34
+ )}
35
+ confirmationMessage={confirmationMessage}
36
+ confirmAction={__('Force Unlock')}
37
+ onClick={onClick}
38
+ confirmType="danger"
39
+ />
40
+ );
41
+
42
+ UnlockModal.propTypes = {
43
+ onClick: PropTypes.func.isRequired,
44
+ id: PropTypes.string,
45
+ };
46
+
47
+ ForceUnlockModal.propTypes = {
48
+ onClick: PropTypes.func.isRequired,
49
+ id: PropTypes.string,
50
+ selectedRowsLen: PropTypes.number,
51
+ };
52
+
53
+ UnlockModal.defaultProps = {
54
+ id: UNLOCK_MODAL,
55
+ };
56
+
57
+ ForceUnlockModal.defaultProps = {
58
+ id: FORCE_UNLOCK_MODAL,
59
+ selectedRowsLen: 1,
60
+ };
@@ -0,0 +1,14 @@
1
+ import { testComponentSnapshotsWithFixtures } from '@theforeman/test';
2
+
3
+ import { UnlockModal, ForceUnlockModal } from './UnlockModals';
4
+
5
+ const fixtures = {
6
+ render: { taskID: 'some-id', onClick: jest.fn() },
7
+ };
8
+
9
+ describe('UnlockModal', () => {
10
+ testComponentSnapshotsWithFixtures(UnlockModal, fixtures);
11
+ });
12
+ describe('ForceUnlockModal', () => {
13
+ testComponentSnapshotsWithFixtures(ForceUnlockModal, fixtures);
14
+ });
@@ -0,0 +1,233 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`Tasks actions should cancelTaskRequest and fail 1`] = `
4
+ Array [
5
+ Array [
6
+ Object {
7
+ "payload": Object {
8
+ "message": Object {
9
+ "message": "Trying to cancel some-name task",
10
+ "type": "info",
11
+ },
12
+ },
13
+ "type": "TOASTS_ADD",
14
+ },
15
+ ],
16
+ Array [
17
+ Object {
18
+ "type": "TASKS_CANCEL_REQUEST",
19
+ },
20
+ ],
21
+ Array [
22
+ Object {
23
+ "payload": [Error: Network Error],
24
+ "type": "TASKS_CANCEL_FAILURE",
25
+ },
26
+ ],
27
+ Array [
28
+ Object {
29
+ "payload": Object {
30
+ "message": Object {
31
+ "message": "some-name Task execution task has to be cancellable",
32
+ "type": "warning",
33
+ },
34
+ },
35
+ "type": "TOASTS_ADD",
36
+ },
37
+ ],
38
+ ]
39
+ `;
40
+
41
+ exports[`Tasks actions should cancelTaskRequest and succeed 1`] = `
42
+ Array [
43
+ Array [
44
+ Object {
45
+ "payload": Object {
46
+ "message": Object {
47
+ "message": "Trying to cancel some-name task",
48
+ "type": "info",
49
+ },
50
+ },
51
+ "type": "TOASTS_ADD",
52
+ },
53
+ ],
54
+ Array [
55
+ Object {
56
+ "type": "TASKS_CANCEL_REQUEST",
57
+ },
58
+ ],
59
+ Array [
60
+ Object {
61
+ "type": "TASKS_CANCEL_SUCCESS",
62
+ },
63
+ ],
64
+ Array [
65
+ Object {
66
+ "payload": Object {
67
+ "message": Object {
68
+ "message": "some-name Task execution was cancelled",
69
+ "type": "success",
70
+ },
71
+ },
72
+ "type": "TOASTS_ADD",
73
+ },
74
+ ],
75
+ ]
76
+ `;
77
+
78
+ exports[`Tasks actions should forceCancelTaskRequest and fail 1`] = `
79
+ Array [
80
+ Array [
81
+ Object {
82
+ "type": "TASKS_FORCE_CANCEL_REQUEST",
83
+ },
84
+ ],
85
+ Array [
86
+ Object {
87
+ "type": "TASKS_FORCE_CANCEL_FAILURE",
88
+ },
89
+ ],
90
+ Array [
91
+ Object {
92
+ "payload": Object {
93
+ "message": Object {
94
+ "message": "some-name Task execution cannot be cancelled with force at the moment.",
95
+ "type": "warning",
96
+ },
97
+ },
98
+ "type": "TOASTS_ADD",
99
+ },
100
+ ],
101
+ ]
102
+ `;
103
+
104
+ exports[`Tasks actions should forceCancelTaskRequest and succeed 1`] = `
105
+ Array [
106
+ Array [
107
+ Object {
108
+ "type": "TASKS_FORCE_CANCEL_REQUEST",
109
+ },
110
+ ],
111
+ Array [
112
+ Object {
113
+ "type": "TASKS_FORCE_CANCEL_SUCCESS",
114
+ },
115
+ ],
116
+ Array [
117
+ Object {
118
+ "payload": Object {
119
+ "message": Object {
120
+ "message": "some-name Task execution resources were unlocked with force.",
121
+ "type": "success",
122
+ },
123
+ },
124
+ "type": "TOASTS_ADD",
125
+ },
126
+ ],
127
+ ]
128
+ `;
129
+
130
+ exports[`Tasks actions should resumeTaskRequest and fail 1`] = `
131
+ Array [
132
+ Array [
133
+ Object {
134
+ "type": "TASKS_RESUME_REQUEST",
135
+ },
136
+ ],
137
+ Array [
138
+ Object {
139
+ "payload": [Error: Network Error],
140
+ "type": "TASKS_RESUME_FAILURE",
141
+ },
142
+ ],
143
+ Array [
144
+ Object {
145
+ "payload": Object {
146
+ "message": Object {
147
+ "message": "some-name Task execution could not be resumed",
148
+ "type": "error",
149
+ },
150
+ },
151
+ "type": "TOASTS_ADD",
152
+ },
153
+ ],
154
+ ]
155
+ `;
156
+
157
+ exports[`Tasks actions should resumeTaskRequest and succeed 1`] = `
158
+ Array [
159
+ Array [
160
+ Object {
161
+ "type": "TASKS_RESUME_REQUEST",
162
+ },
163
+ ],
164
+ Array [
165
+ Object {
166
+ "type": "TASKS_RESUME_SUCCESS",
167
+ },
168
+ ],
169
+ Array [
170
+ Object {
171
+ "payload": Object {
172
+ "message": Object {
173
+ "message": "some-name Task execution was resumed",
174
+ "type": "success",
175
+ },
176
+ },
177
+ "type": "TOASTS_ADD",
178
+ },
179
+ ],
180
+ ]
181
+ `;
182
+
183
+ exports[`Tasks actions should unlockTaskRequest and fail 1`] = `
184
+ Array [
185
+ Array [
186
+ Object {
187
+ "type": "TASKS_FORCE_CANCEL_REQUEST",
188
+ },
189
+ ],
190
+ Array [
191
+ Object {
192
+ "type": "TASKS_FORCE_CANCEL_FAILURE",
193
+ },
194
+ ],
195
+ Array [
196
+ Object {
197
+ "payload": Object {
198
+ "message": Object {
199
+ "message": "some-name Task execution cannot be cancelled with force at the moment.",
200
+ "type": "warning",
201
+ },
202
+ },
203
+ "type": "TOASTS_ADD",
204
+ },
205
+ ],
206
+ ]
207
+ `;
208
+
209
+ exports[`Tasks actions should unlockTaskRequest and succeed 1`] = `
210
+ Array [
211
+ Array [
212
+ Object {
213
+ "type": "TASKS_UNLOCK_REQUEST",
214
+ },
215
+ ],
216
+ Array [
217
+ Object {
218
+ "type": "TASKS_UNLOCK_SUCCESS",
219
+ },
220
+ ],
221
+ Array [
222
+ Object {
223
+ "payload": Object {
224
+ "message": Object {
225
+ "message": "some-name Task execution resources were unlocked ",
226
+ "type": "success",
227
+ },
228
+ },
229
+ "type": "TOASTS_ADD",
230
+ },
231
+ ],
232
+ ]
233
+ `;
@@ -0,0 +1,25 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`ForceUnlockModal render 1`] = `
4
+ <ClickConfirmation
5
+ body="Resources for 1 task(s) will be unlocked and will not prevent other tasks from being run. As the task(s) might be still running, it should be avoided to use this unless you are really sure the task(s) got stuck."
6
+ confirmAction="Force Unlock"
7
+ confirmType="danger"
8
+ confirmationMessage="I understand that this may cause harm and have working database backups of all backend services."
9
+ id="forceUnlockModal"
10
+ onClick={[MockFunction]}
11
+ title="Force Unlock"
12
+ />
13
+ `;
14
+
15
+ exports[`UnlockModal render 1`] = `
16
+ <ClickConfirmation
17
+ body="This will unlock the resources that the task is running against. Please note that this might lead to inconsistent state and should be used with caution, after making sure that the task can't be resumed."
18
+ confirmAction="Unlock"
19
+ confirmType="warning"
20
+ confirmationMessage="I understand that this may cause harm and have working database backups of all backend services."
21
+ id="unlockModal"
22
+ onClick={[MockFunction]}
23
+ title="Unlock"
24
+ />
25
+ `;