Merge pull request #4943 from tsiegleauq/prevent-destructive-bulk

Prevent wrong bulk-change-state operations
This commit is contained in:
Emanuel Schütze 2019-08-27 09:00:33 +02:00 committed by GitHub
commit 0d93c5ecfc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 53 additions and 44 deletions

View File

@ -62,11 +62,19 @@ export abstract class BaseViewComponent extends BaseComponent implements OnDestr
* @param message The message to show or an "real" error, which will be passed to the console.
*/
protected raiseError = (message: string | Error): void => {
let errorNotification: string;
if (message instanceof Error) {
console.error(message);
message = this.translate.instant('A client error occured. Please contact your system administrator.');
if (message.message) {
errorNotification = message.message;
} else {
errorNotification = this.translate.instant(
'A client error occurred. Please contact your system administrator.'
);
}
this.messageSnackBar = this.matSnackBar.open(message as string, this.translate.instant('OK'), {
} else {
errorNotification = message;
}
this.messageSnackBar = this.matSnackBar.open(errorNotification, this.translate.instant('OK'), {
duration: 0
});
};

View File

@ -110,6 +110,7 @@ export class MotionMultiselectService {
* @param motions The motions to change
*/
public async setStateOfMultiple(motions: ViewMotion[]): Promise<void> {
if (motions.every(motion => motion.workflow_id === motions[0].workflow_id)) {
const title = this.translate.instant('This will set the following state for all selected motions:');
const choices = this.workflowRepo.getWorkflowStatesForMotions(motions).map(workflowState => ({
id: workflowState.id,
@ -120,11 +121,9 @@ export class MotionMultiselectService {
const message = `${motions.length} ` + this.translate.instant(this.messageForSpinner);
this.overlayService.setSpinner(true, message);
await this.repo.setMultiState(motions, selectedChoice.items as number);
// .catch(error => {
// this.overlayService.setSpinner(false);
// throw error;
// });
// this.overlayService.setSpinner(false);
}
} else {
throw new Error(this.translate.instant('You cannot change the state of motions in different workflows!'));
}
}
@ -134,7 +133,10 @@ export class MotionMultiselectService {
* @param motions The motions to change
*/
public async setRecommendation(motions: ViewMotion[]): Promise<void> {
const title = this.translate.instant('This will set the following recommendation for all selected motions:');
if (motions.every(motion => motion.workflow_id === motions[0].workflow_id)) {
const title = this.translate.instant(
'This will set the following recommendation for all selected motions:'
);
const choices = this.workflowRepo
.getWorkflowStatesForMotions(motions)
.filter(workflowState => !!workflowState.recommendation_label)
@ -149,17 +151,16 @@ export class MotionMultiselectService {
id: motion.id,
recommendation: selectedChoice.action ? 0 : (selectedChoice.items as number)
}));
const message = `${motions.length} ` + this.translate.instant(this.messageForSpinner);
this.overlayService.setSpinner(true, message);
await this.httpService.post('/rest/motions/motion/manage_multiple_recommendation/', {
motions: requestData
});
// .catch(error => {
// this.overlayService.setSpinner(false);
// throw error;
// });
// this.overlayService.setSpinner(false);
}
} else {
throw new Error(
this.translate.instant('You cannot change the recommendation of motions in different workflows!')
);
}
}