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. * @param message The message to show or an "real" error, which will be passed to the console.
*/ */
protected raiseError = (message: string | Error): void => { protected raiseError = (message: string | Error): void => {
let errorNotification: string;
if (message instanceof Error) { if (message instanceof Error) {
console.error(message); if (message.message) {
message = this.translate.instant('A client error occured. Please contact your system administrator.'); errorNotification = message.message;
} else {
errorNotification = this.translate.instant(
'A client error occurred. Please contact your system administrator.'
);
}
} else {
errorNotification = message;
} }
this.messageSnackBar = this.matSnackBar.open(message as string, this.translate.instant('OK'), { this.messageSnackBar = this.matSnackBar.open(errorNotification, this.translate.instant('OK'), {
duration: 0 duration: 0
}); });
}; };

View File

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