webpack/ForemanTasks/Components/TasksTable/TasksBulkActions.js in foreman-tasks-2.0.1 vs webpack/ForemanTasks/Components/TasksTable/TasksBulkActions.js in foreman-tasks-2.0.2
- old
+ new
@@ -61,11 +61,11 @@
export const bulkResumeById = ({
selected,
url,
parentTaskID,
}) => async dispatch => {
- const resumeTasks = selected.filter(task => task.isResumable);
+ const resumeTasks = selected.filter(task => task.isResumable && task.canEdit);
if (resumeTasks.length < selected.length)
dispatch(
addToast(
warningToastData(__('Not all the selected tasks can be resumed'))
)
@@ -85,11 +85,11 @@
dispatch,
});
});
});
if (data.resumed) {
- reloadPage(url, parentTaskID, dispatch);
+ reloadPage(url, parentTaskID)(dispatch);
}
} catch (error) {
handleErrorResume(error, dispatch);
}
}
@@ -133,11 +133,13 @@
export const bulkCancelById = ({
selected,
url,
parentTaskID,
}) => async dispatch => {
- const cancelTasks = selected.filter(task => task.isCancellable);
+ const cancelTasks = selected.filter(
+ task => task.isCancellable && task.canEdit
+ );
if (cancelTasks.length < selected.length)
dispatch(
addToast(
warningToastData(__('Not all the selected tasks can be cancelled'))
)
@@ -158,11 +160,11 @@
dispatch,
});
});
});
if (data.cancelled) {
- reloadPage(url, parentTaskID, dispatch);
+ reloadPage(url, parentTaskID)(dispatch);
}
} catch (error) {
handleErrorCancel(error, dispatch);
}
}
@@ -183,10 +185,22 @@
selected,
url,
parentTaskID,
}) => async dispatch => {
const stopTasks = selected.filter(task => task.state !== 'stopped');
+ const authorisedTasks = stopTasks.filter(task => task.canEdit);
+ if (authorisedTasks.length < stopTasks.length)
+ dispatch(
+ addToast(
+ warningToastData(
+ sprintf(
+ 'User has no permission for %s task(s)',
+ stopTasks.length - authorisedTasks.length
+ )
+ )
+ )
+ );
if (stopTasks.length < selected.length)
dispatch(
addToast(
warningToastData(
sprintf(
@@ -194,14 +208,17 @@
selected.length - stopTasks.length
)
)
)
);
- if (stopTasks.length > 0) {
+ if (authorisedTasks.length > 0) {
dispatch({ type: TASKS_FORCE_CANCEL_REQUEST });
try {
- const { data } = await bulkByIdRequest(stopTasks, BULK_FORCE_CANCEL_PATH);
+ const { data } = await bulkByIdRequest(
+ authorisedTasks,
+ BULK_FORCE_CANCEL_PATH
+ );
dispatch({ type: TASKS_FORCE_CANCEL_SUCCESS });
if (data.stopped_length) {
dispatch(
addToast(
successToastData(
@@ -217,10 +234,10 @@
sprintf('%s task(s) are already stopped', data.skipped_length)
)
)
);
if (data.stopped_length > 0) {
- reloadPage(url, parentTaskID, dispatch);
+ reloadPage(url, parentTaskID)(dispatch);
}
} catch (error) {
handleErrorForceCancel(error, dispatch);
}
}