updated the way of how users are automatically assigned as reviewers or approvers based on the ticket rules

This commit is contained in:
Valentin 2021-10-27 17:59:22 +03:00 committed by Timo Bejan
parent a1c56439f1
commit 2a6003e4aa
3 changed files with 54 additions and 25 deletions

View File

@ -15,6 +15,7 @@ class DialogData {
dossier?: Dossier;
files?: File[];
ignoreChanged?: boolean;
withCurrentUserAsDefault?: boolean;
}
@Component({
@ -111,10 +112,14 @@ export class AssignReviewerApproverDialogComponent {
uniqueReviewers.add(file.currentReviewer);
}
}
let singleUser: string = uniqueReviewers.size === 1 ? uniqueReviewers.values().next().value : this.userService.currentUser.id;
let singleUser: string = uniqueReviewers.size === 1 ? uniqueReviewers.values().next().value : this.userService.currentUser.id;
singleUser = this.singleUsersSelectOptions.indexOf(singleUser) >= 0 ? singleUser : this.singleUsersSelectOptions[0];
if (this.data.withCurrentUserAsDefault && this.singleUsersSelectOptions.includes(this.userService.currentUser.id)) {
singleUser = this.userService.currentUser.id;
}
this.usersForm = this._formBuilder.group({
// Allow a null reviewer if a previous reviewer exists (= it's not the first assignment) & current user is allowed to unassign
singleUser: [singleUser, this._canUnassignFiles && !singleUser ? Validators.required : null],

View File

@ -151,7 +151,7 @@ export class FileActionsComponent extends AutoUnsubscribe implements OnInit, OnD
assign($event: MouseEvent) {
const mode = this.file.isUnderApproval ? 'approver' : 'reviewer';
const files = [this.file];
this._dialogService.openDialog('assignFile', $event, { mode, files }, () => {
this._dialogService.openDialog('assignFile', $event, { mode, files, withCurrentUserAsDefault: true }, () => {
this.actionPerformed.emit('assign-reviewer');
});
}
@ -173,10 +173,10 @@ export class FileActionsComponent extends AutoUnsubscribe implements OnInit, OnD
});
}
setFileUnderApproval($event: MouseEvent) {
async setFileUnderApproval($event: MouseEvent) {
$event.stopPropagation();
if (this.dossiersService.activeDossier.approverIds.length > 1) {
this._fileActionService.assignFile('approver', $event, this.file, () => this.reloadDossiers('assign-reviewer'), true);
await this._fileActionService.assignFile('approver', $event, this.file, () => this.reloadDossiers('assign-reviewer'), true);
} else {
this.addSubscription = this._fileActionService.setFilesUnderApproval([this.file]).subscribe(() => {
this.reloadDossiers('set-under-approval');
@ -210,8 +210,8 @@ export class FileActionsComponent extends AutoUnsubscribe implements OnInit, OnD
});
}
setFileUnderReview($event: MouseEvent, ignoreDialogChanges = false) {
this._fileActionService.assignFile(
async setFileUnderReview($event: MouseEvent, ignoreDialogChanges = false) {
await this._fileActionService.assignFile(
'reviewer',
$event,
this.file,

View File

@ -86,38 +86,58 @@ export class FileActionService {
);
}
assignFile(
async assignFile(
mode: 'reviewer' | 'approver',
$event: MouseEvent,
file = this._appStateService.activeFile,
callback?: Function,
ignoreChanged = false,
) {
const userIds = this._getUserIds(mode);
if (userIds.length === 1 || userIds.includes(this._userService.currentUser.id)) {
$event?.stopPropagation(); // event$ is null when called from workflow view
const userId = userIds.length === 1 ? userIds[0] : this._userService.currentUser.id;
this._assignFile(userId, mode, [file]).then(async () => {
if (callback) {
await callback();
}
});
$event?.stopPropagation();
const currentUserId = this._userService.currentUser.id;
const eligibleUsersIds = this._getUserIds(mode);
if (file.isUnassigned) {
await this._assignFile(currentUserId, mode, file, callback);
} else if (file.currentReviewer === currentUserId) {
if (eligibleUsersIds.includes(currentUserId)) {
await this._assignFile(currentUserId, mode, file, callback);
} else if (eligibleUsersIds.length === 1) {
await this._assignFile(eligibleUsersIds[0], mode, file, callback);
} else {
const files = [file];
this._dialogService.openDialog('assignFile', null, { mode, files, ignoreChanged }, async () => {
if (callback) {
await callback();
}
});
}
} else {
const data = { mode, files: [file], ignoreChanged };
this._dialogService.openDialog('assignFile', $event, data, async () => {
if (callback) {
await callback();
}
});
if (eligibleUsersIds.length === 1) {
await this._assignFile(eligibleUsersIds[0], mode, file, callback);
} else {
const files = [file];
this._dialogService.openDialog(
'assignFile',
null,
{ mode, files, ignoreChanged, withCurrentUserAsDefault: true },
async () => {
if (callback) {
await callback();
}
},
);
}
}
}
private async _assignFile(userId: string, mode: 'reviewer' | 'approver', files: File[]) {
private async _assignFile(userId: string, mode: 'reviewer' | 'approver', file: File, callback?: Function) {
try {
if (mode === 'reviewer') {
await this._filesService
.setReviewerFor(
files.map(f => f.fileId),
[file].map(f => f.fileId),
this._dossiersService.activeDossierId,
userId,
)
@ -125,12 +145,16 @@ export class FileActionService {
} else {
await this._filesService
.setUnderApprovalFor(
files.map(f => f.fileId),
[file].map(f => f.fileId),
this._dossiersService.activeDossierId,
userId,
)
.toPromise();
}
if (callback) {
await callback();
}
} catch (error) {
this._toaster.error(_('error.http.generic'), { params: error });
}