Merge branch 'RED-7325' into 'master'

RED-7325 filter current user from assign approver dialog

See merge request redactmanager/red-ui!36
This commit is contained in:
Dan Percic 2023-08-28 10:13:19 +02:00
commit 6daa827a57
3 changed files with 36 additions and 23 deletions

View File

@ -1,14 +1,14 @@
<section class="dialog">
<div [innerHTML]="'assign-owner.dialog.title' | translate : { type: mode }" class="dialog-header heading-l"></div>
<div [innerHTML]="'assign-owner.dialog.title' | translate: { type: mode }" class="dialog-header heading-l"></div>
<form (submit)="save()" [formGroup]="form">
<div class="dialog-content">
<div class="iqser-input-group w-300 required">
<label>{{ 'assign-owner.dialog.label' | translate : { type: mode } }}</label>
<label>{{ 'assign-owner.dialog.label' | translate: { type: mode } }}</label>
<mat-form-field>
<mat-select [placeholder]="'initials-avatar.unassigned' | translate" formControlName="user">
<mat-option *ngFor="let userId of userOptions" [value]="userId">
{{ userId | name : { defaultValue: 'initials-avatar.unassigned' | translate } }}
{{ userId | name: { defaultValue: 'initials-avatar.unassigned' | translate } }}
</mat-option>
</mat-select>
</mat-form-field>

View File

@ -1,15 +1,15 @@
import { Component, Inject } from '@angular/core';
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog';
import { UserService } from '@users/user.service';
import { IconButtonTypes, LoadingService, Toaster } from '@iqser/common-ui';
import { FormBuilder, Validators } from '@angular/forms';
import { File, User, WorkflowFileStatus, WorkflowFileStatuses } from '@red/domain';
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog';
import { marker as _ } from '@biesbjerg/ngx-translate-extract-marker';
import { FilesService } from '@services/files/files.service';
import { ActiveDossiersService } from '@services/dossiers/active-dossiers.service';
import { PermissionsService } from '@services/permissions.service';
import { moveElementInArray } from '@utils/functions';
import { IconButtonTypes, LoadingService, Toaster } from '@iqser/common-ui';
import { getCurrentUser } from '@iqser/common-ui/lib/users';
import { File, User, WorkflowFileStatus, WorkflowFileStatuses } from '@red/domain';
import { ActiveDossiersService } from '@services/dossiers/active-dossiers.service';
import { FilesService } from '@services/files/files.service';
import { PermissionsService } from '@services/permissions.service';
import { UserService } from '@users/user.service';
import { moveElementInArray } from '@utils/functions';
class DialogData {
targetStatus: WorkflowFileStatus;
@ -23,10 +23,11 @@ class DialogData {
templateUrl: './assign-reviewer-approver-dialog.component.html',
})
export class AssignReviewerApproverDialogComponent {
readonly #dossier = this._activeDossiersService.find(this.data.files[0].dossierId);
readonly #isApprover = this.permissionsService.isApprover(this.#dossier);
readonly iconButtonTypes = IconButtonTypes;
readonly currentUser = getCurrentUser<User>();
readonly mode = this.#mode;
readonly dossier = this._activeDossiersService.find(this.data.files[0].dossierId);
readonly userOptions = this.#userOptions;
readonly form = this.#form;
@ -70,32 +71,42 @@ export class AssignReviewerApproverDialogComponent {
get #userOptions() {
const unassignUser = this.#canUnassignUser && this.data.withUnassignedOption ? ['undefined'] : [];
const cannotAssignUser = !this.permissionsService.canAssignUser(this.data.files, this.dossier);
const cannotAssignUser = !this.permissionsService.canAssignUser(this.data.files, this.#dossier);
if (this.mode === 'reviewer') {
if (this.dossier.hasReviewers && cannotAssignUser) {
if (this.#dossier.hasReviewers && cannotAssignUser) {
return [...unassignUser];
}
return this.#customSort([...this.dossier.memberIds, ...unassignUser]);
return this.#customSort([...this.#dossier.memberIds, ...unassignUser]);
}
if (this.dossier.approverIds.length > 1 && cannotAssignUser) {
if (this.#dossier.approverIds.length > 1 && cannotAssignUser) {
return [...unassignUser];
}
return this.#customSort([...this.dossier.approverIds, ...unassignUser]);
return this.#customSort([...this.#dossier.approverIds, ...unassignUser]);
}
get #canUnassignUser() {
return this.permissionsService.canUnassignUser(this.data.files, this.dossier);
return this.permissionsService.canUnassignUser(this.data.files, this.#dossier);
}
get #user(): string {
get #user() {
if (this.data.files.every(file => !file.assignee)) {
return null;
}
return this.data.files.length === 1 ? this.data.files[0].assignee : this.currentUser.id;
if (this.mode === 'reviewer') {
return this.data.files.length === 1 ? this.data.files[0].assignee : this.currentUser.id;
}
const assignee = this.data.files[0].assignee;
if (this.data.files.length === 1 && this.permissionsService.isApprover(this.#dossier, assignee)) {
return assignee;
}
return this.#isApprover ? this.currentUser.id : this.userOptions.at(0);
}
get #form() {
@ -129,7 +140,9 @@ export class AssignReviewerApproverDialogComponent {
#customSort(ids: string[]) {
let sorted = ids.sort((a, b) => this.userService.getName(a).localeCompare(this.userService.getName(b)));
sorted = moveElementInArray(sorted, this.currentUser.id, 0);
if (this.mode === 'reviewer' || (this.mode === 'approver' && this.#isApprover)) {
sorted = moveElementInArray(sorted, this.currentUser.id, 0);
}
if (sorted.includes('undefined')) {
sorted = moveElementInArray(sorted, 'undefined', 1);

View File

@ -232,8 +232,8 @@ export class PermissionsService {
return dossier.ownerId === this.#userId;
}
isApprover(dossier: Dossier): boolean {
return dossier.approverIds.indexOf(this.#userId) >= 0;
isApprover(dossier: Dossier, userId = this.#userId): boolean {
return dossier.approverIds.indexOf(userId) >= 0;
}
isDossierMember(dossier: IDossier): boolean {