diff --git a/src/frontend/app/administration/administration.module.ts b/src/frontend/app/administration/administration.module.ts index 02f3c146982393e7f74583b7a03751ffb0182659..07034f29afef8288cb25406461d6232492d76569 100755 --- a/src/frontend/app/administration/administration.module.ts +++ b/src/frontend/app/administration/administration.module.ts @@ -65,7 +65,8 @@ import { UpdateStatusAdministrationComponent } from './updateStatus/update-statu import { UserAdministrationComponent, UserAdministrationRedirectModalComponent } from './user/user-administration.component'; import { VersionsUpdateAdministrationComponent } from './versionUpdate/versions-update-administration.component'; import { AdministrationComponent } from './home/administration.component'; -import { UsersAdministrationComponent, UsersAdministrationRedirectModalComponent } from './user/users-administration.component'; +import { UsersAdministrationComponent } from './user/users-administration.component'; +import { UsersAdministrationRedirectModalComponent } from './user/redirect-modal/users-administration-redirect-modal.component'; import { UsersImportComponent } from './user/import/users-import.component'; import { UsersExportComponent } from './user/export/users-export.component'; import { TranslateService } from '@ngx-translate/core'; diff --git a/src/frontend/app/administration/user/redirect-modal/users-administration-redirect-modal.component.html b/src/frontend/app/administration/user/redirect-modal/users-administration-redirect-modal.component.html new file mode 100644 index 0000000000000000000000000000000000000000..ba5f355bd31a8a6a213db9a665bb6d267a38ceeb --- /dev/null +++ b/src/frontend/app/administration/user/redirect-modal/users-administration-redirect-modal.component.html @@ -0,0 +1,91 @@ +<div class="mat-dialog-content-container"> + <h1 mat-dialog-title>{{modalTitle | translate}}</h1> + <mat-dialog-content> + <ng-container *ngIf="isDeletable"> + <ng-container *ngIf="userDestTemplates.length > 0"> + <h2>{{'lang.redirectUserListDiff' | translate}}</h2> + <div class="alert-message alert-message-info" role="alert"> + <b>{{data.user.firstname}} {{data.user.lastname}}</b> <span + [innerHTML]="'lang.chooseNewDest' | translate"></span> : + </div> + + <div *ngFor="let redirectModel of userDestTemplates; index as i" id="{{redirectModel.object_id}}" + class="form-group"> + <plugin-autocomplete [labelPlaceholder]="('lang.newDest' | translate) + ' : ' + redirectModel.title" + [labelList]="('lang.availableUsers' | translate)" [routeDatas]="['/rest/autocomplete/users']" + [targetSearchKey]="'idToDisplay'" [subInfoKey]="'descriptionToDisplay'" + (triggerEvent)="setRedirectUserListModels(i, $event)" singleMode required></plugin-autocomplete> + </div> + </ng-container> + <ng-container *ngIf="userDestDifflists.length > 0"> + <h2>{{'lang.redirectUserListInstances' | translate}}</h2> + <div class="alert-message alert-message-info" role="alert"> + <b>{{data.user.firstname}} {{data.user.lastname}}</b> <span + [innerHTML]="'lang.chooseNewDestUser' | translate"></span> : + </div> + + <div id="{{data.user.user_id}}" class="form-group"> + <plugin-autocomplete [labelPlaceholder]="('lang.newDestRes' | translate)" [labelList]="('lang.availableUsers' | translate)" + [routeDatas]="['/rest/autocomplete/users']" [targetSearchKey]="'idToDisplay'" + [subInfoKey]="'descriptionToDisplay'" (triggerEvent)="setRedirectUserRes($event)" singleMode + required></plugin-autocomplete> + </div> + </ng-container> + <ng-container *ngIf="userVisaWorkflowResources.length > 0"> + <h2>{{'lang.redirectUserListInstances' | translate}}</h2> + <div class="alert-message alert-message-info" role="alert"> + <b>{{data.user.firstname}} {{data.user.lastname}}</b> <span + [innerHTML]="'lang.chooseNewDestUser' | translate"></span> : + </div> + <div id="{{data.user.user_id}}" class="form-group"> + <plugin-autocomplete [labelPlaceholder]="('lang.newDestRes' | translate)" [labelList]="('lang.availableUsers' | translate)" + [routeDatas]="['/rest/autocomplete/users/circuit']" [targetSearchKey]="'idToDisplay'" + [subInfoKey]="'descriptionToDisplay'" (triggerEvent)="setRedirectUserVisaWorkflowRes($event)" singleMode + required></plugin-autocomplete> + </div> + </ng-container> + <ng-container *ngIf="userDestTemplates.length === 0 && userDestDifflists.length === 0 && userVisaWorkflowResources.length === 0"> + <div class="alert-message alert-message-info" role="alert"> + {{'lang.' + data.user.actionMode | translate}} {{data.user.firstname}} {{data.user.lastname}} + </div> + </ng-container> + </ng-container> + <ng-container *ngIf="!isDeletable"> + <div class="alert-message alert-message-info" role="alert"> + <p><span [innerHTML]="'lang.userIsNotDeletable' | translate"></span> <b>{{data.user.firstname}} + {{data.user.lastname}}</b> </p> + <p><span [innerHTML]="'lang.userIsDeletableBy' | translate"></span></p> + </div> + <div class="modal-body" *ngIf="userDestTemplates.length > 0" class="col-md-6"> + <mat-list> + <p mat-line>{{'lang.diffusionList' | translate}}</p> + <mat-list-item *ngFor="let templateEntity of userDestTemplates"> + <mat-icon mat-list-icon><i class="fa fa-share-alt" color="primary"></i></mat-icon> + <p mat-line><span> {{templateEntity}} </span></p> + </mat-list-item> + </mat-list> + </div> + <div class="modal-body" *ngIf="userDestDifflists.length > 0" class="col-md-6"> + <mat-list> + <p mat-line>{{'lang.mailEntitiesList' | translate}}</p> + <mat-list-item *ngFor="let instanceEntity of userDestDifflists"> + <mat-icon mat-list-icon><i class="fa fa-inbox" color="primary"></i></mat-icon> + <p mat-line><span> {{instanceEntity}} </span></p> + </mat-list-item> + </mat-list> + </div> + </ng-container> + </mat-dialog-content> + <span class="divider-modal"></span> + <mat-dialog-actions> + <button mat-raised-button color="warn" *ngIf="data.user.actionMode == 'delete' && isDeletable" + type="submit" class="btn btn-danger" (click)="onSubmit()" + [disabled]="!isValid()">{{'lang.delete' | translate}} + {{'lang.user' | translate}}</button> + <button mat-raised-button color="primary" *ngIf="data.user.actionMode == 'suspend' && isDeletable" + type="submit" (click)="onSubmit()" [disabled]="!isValid()">{{'lang.suspend' | translate}} + {{'lang.user' | translate}}</button> + <button mat-raised-button color="default" *ngIf="!data.isDeletable" type="submit" + (click)="dialogRef.close()">{{'lang.close' | translate}}</button> + </mat-dialog-actions> +</div> diff --git a/src/frontend/app/administration/user/redirect-modal/users-administration-redirect-modal.component.ts b/src/frontend/app/administration/user/redirect-modal/users-administration-redirect-modal.component.ts new file mode 100644 index 0000000000000000000000000000000000000000..06f6be3fcb9aae410a5804e38df35da2625f0d21 --- /dev/null +++ b/src/frontend/app/administration/user/redirect-modal/users-administration-redirect-modal.component.ts @@ -0,0 +1,228 @@ +import { HttpClient } from '@angular/common/http'; +import { Component, Inject, OnInit } from '@angular/core'; +import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog'; +import { TranslateService } from '@ngx-translate/core'; +import { NotificationService } from '@service/notification/notification.service'; +import { of } from 'rxjs'; +import { catchError, tap } from 'rxjs/operators'; + +@Component({ + templateUrl: 'users-administration-redirect-modal.component.html', + styleUrls: ['users-administration-redirect-modal.scss'], +}) +export class UsersAdministrationRedirectModalComponent implements OnInit { + + modalTitle: string = 'lang.confirmAction'; + + isDeletable: boolean = false; + userDestTemplates: any[] = []; + userDestDifflists: any[] = []; + userDestDifflistsRedirectUserId: any = null; + userVisaWorkflowResources: any[] = []; + userVisaWorkflowResourcesRedirectUserId: any = null; + + constructor( + public translate: TranslateService, + public http: HttpClient, + @Inject(MAT_DIALOG_DATA) public data: any, + public dialogRef: MatDialogRef<UsersAdministrationRedirectModalComponent>, + private notify: NotificationService + ) { } + + async ngOnInit(): Promise<void> { + await this.getActionInfo(); + } + + async onSubmit() { + if (this.userDestTemplates.length > 0) { + await this.updateListmodels(); + } + if (this.userDestDifflists.length > 0) { + await this.updateListinstances(); + } + if (this.userVisaWorkflowResources.length > 0) { + await this.updateVisaWorkflow(); + } + if (this.data.user.actionMode === 'delete') { + await this.deleteUser(); + } else { + await this.suspendUser(); + } + this.dialogRef.close('success'); + } + + getActionInfo() { + return new Promise((resolve) => { + this.http.get(`../rest/users/${this.data.user.id}/isDeletable`).pipe( + tap((response: any) => { + if (response && response.hasOwnProperty('errors')) { + this.notify.error(response.errors); + this.dialogRef.close(''); + } else { + this.isDeletable = response.isDeletable; + if (this.isDeletable) { + this.userDestTemplates = response.listTemplates; + this.userDestDifflists = response.listInstances; + this.userVisaWorkflowResources = response.visaWorflow; + } else { + this.modalTitle = this.data.user.actionMode === 'delete' ? 'lang.unableToDelete' : 'lang.unableToSuspend'; + this.userDestTemplates = response.listTemplateEntities; + this.userDestDifflists = response.listInstanceEntities; + } + resolve(true); + } + }), + catchError((err: any) => { + this.notify.handleSoftErrors(err); + return of(false); + }) + ).subscribe(); + }); + } + + setRedirectUserListModels(index: number, user: any) { + if (this.data.user.user_id != user.id) { + this.userDestTemplates[index].redirectUserId = user.id; + } else { + this.userDestTemplates[index].redirectUserId = null; + this.notify.error(this.translate.instant('lang.userUnauthorized')); + } + } + + setRedirectUserRes(user: any) { + if (this.data.user.user_id != user.id) { + this.userDestDifflistsRedirectUserId = user.id; + } else { + this.userDestDifflistsRedirectUserId = null; + this.notify.error(this.translate.instant('lang.userUnauthorized')); + } + } + + setRedirectUserVisaWorkflowRes(user: any) { + if (this.data.user.user_id != user.id) { + this.userVisaWorkflowResourcesRedirectUserId = user.id; + } else { + this.userVisaWorkflowResourcesRedirectUserId = null; + this.notify.error(this.translate.instant('lang.userUnauthorized')); + } + } + + isValid() { + let valid = true; + + if (this.userDestTemplates.length > 0) { + this.userDestTemplates.forEach((element: any) => { + if (!element.redirectUserId) { + valid = false; + } + }); + } + if (this.userDestDifflists.length > 0) { + if (!this.userDestDifflistsRedirectUserId) { + valid = false; + } + } + return valid; + } + + updateListmodels() { + return new Promise((resolve) => { + this.http.put(`../rest/listTemplates/entityDest/itemId/${this.data.user.id}`, { redirectListModels: this.userDestTemplates }).pipe( + tap((data: any) => { + if (data != null && data.errors) { + this.notify.error(data.errors); + } else { + resolve(true); + } + }), + catchError((err: any) => { + this.notify.handleSoftErrors(err); + return of(false); + }) + ).subscribe(); + }); + } + + updateListinstances() { + this.userDestDifflists.forEach((res: any, index: number) => { + this.userDestDifflists[index].listInstances = this.userDestDifflists[index].listInstances.map((item: any) => { + return { + ...item, + item_id: (item.item_mode === 'dest' && item.item_id === this.data.user.id) ? this.userDestDifflistsRedirectUserId : item.item_id + }; + }); + }); + return new Promise((resolve) => { + this.http.put(`../rest/listinstances`, this.userDestDifflists).pipe( + tap((data: any) => { + if (data && data.hasOwnProperty('errors')) { + this.notify.error(data.errors); + } else { + resolve(true); + } + }), + catchError((err: any) => { + this.notify.handleSoftErrors(err); + return of(false); + }) + ).subscribe(); + }); + } + + updateVisaWorkflow() { + this.userVisaWorkflowResources.forEach((res: any, index: number) => { + this.userVisaWorkflowResources[index].listInstances = this.userVisaWorkflowResources[index].workflow.map((item: any) => { + return { + ...item, + item_id: (item.process_mode !== null && item.item_id === this.data.user.id) ? this.userVisaWorkflowResourcesRedirectUserId : item.item_id + }; + }); + }); + return new Promise((resolve) => { + this.http.put(`../rest/circuits/visaCircuit`, { resources: this.userVisaWorkflowResources }).pipe( + tap((data: any) => { + if (data && data.hasOwnProperty('errors')) { + this.notify.error(data.errors); + } else { + resolve(true); + } + }), + catchError((err: any) => { + this.notify.handleSoftErrors(err); + return of(false); + }) + ).subscribe(); + }); + } + + deleteUser() { + return new Promise((resolve) => { + this.http.delete(`../rest/users/${this.data.user.id}`).pipe( + tap((data: any) => { + this.notify.success(this.translate.instant('lang.userDeleted') + ' « ' + this.data.user.user_id + ' »'); + resolve(true); + }), + catchError((err: any) => { + this.notify.handleSoftErrors(err); + return of(false); + }) + ).subscribe(); + }); + } + + suspendUser() { + return new Promise((resolve) => { + this.http.put(`../rest/users/${this.data.user.id}/suspend`, this.data.user).pipe( + tap((data: any) => { + this.notify.success(this.translate.instant('lang.userSuspended')); + resolve(true); + }), + catchError((err: any) => { + this.notify.handleSoftErrors(err); + return of(false); + }) + ).subscribe(); + }); + } + +} diff --git a/src/frontend/app/administration/user/users-administration-redirect-modal.scss b/src/frontend/app/administration/user/redirect-modal/users-administration-redirect-modal.scss similarity index 100% rename from src/frontend/app/administration/user/users-administration-redirect-modal.scss rename to src/frontend/app/administration/user/redirect-modal/users-administration-redirect-modal.scss diff --git a/src/frontend/app/administration/user/users-administration-redirect-modal.component.html b/src/frontend/app/administration/user/users-administration-redirect-modal.component.html deleted file mode 100755 index 2f3c092b40074c31f0a4b9fb6130217472a88c5e..0000000000000000000000000000000000000000 --- a/src/frontend/app/administration/user/users-administration-redirect-modal.component.html +++ /dev/null @@ -1,81 +0,0 @@ -<div class="mat-dialog-content-container"> - <h1 mat-dialog-title>{{modalTitle}}</h1> - <mat-dialog-content> - <ng-container *ngIf="data.isDeletable"> - <ng-container *ngIf="data.inDiffListDest"> - <h2>{{'lang.redirectUserListDiff' | translate}}</h2> - <div class="alert-message alert-message-info" role="alert"> - <b>{{this.data.userDestRedirect.firstname}} {{this.data.userDestRedirect.lastname}}</b> <span - [innerHTML]="this.translate.instant('lang.chooseNewDest')"></span> : - </div> - - <div *ngFor="let redirectModel of data.redirectListModels; index as i" id="{{redirectModel.object_id}}" - class="form-group"> - <plugin-autocomplete [labelPlaceholder]="this.translate.instant('lang.newDest') + ' : ' + redirectModel.title" - [labelList]="this.translate.instant('lang.availableUsers')" [routeDatas]="['/rest/autocomplete/users']" - [targetSearchKey]="'idToDisplay'" [subInfoKey]="'descriptionToDisplay'" - (triggerEvent)="setRedirectUserListModels(i, $event)" singleMode required></plugin-autocomplete> - </div> - </ng-container> - <ng-container *ngIf="data.isResDestUser"> - <h2>{{'lang.redirectUserListInstances' | translate}}</h2> - <div class="alert-message alert-message-info" role="alert"> - <b>{{this.data.userDestRedirect.firstname}} {{this.data.userDestRedirect.lastname}}</b> <span - [innerHTML]="this.translate.instant('lang.chooseNewDestUser')"></span> : - </div> - - <div id="{{this.data.userDestRedirect.user_id}}" class="form-group"> - <plugin-autocomplete [labelPlaceholder]="this.translate.instant('lang.newDestRes')" [labelList]="this.translate.instant('lang.availableUsers')" - [routeDatas]="['/rest/autocomplete/users']" [targetSearchKey]="'idToDisplay'" - [subInfoKey]="'descriptionToDisplay'" (triggerEvent)="setRedirectUserRes($event)" singleMode - required></plugin-autocomplete> - </div> - </ng-container> - <ng-container *ngIf="!data.inDiffListDest && !data.isResDestUser"> - <div class="alert" role="alert"> - <b *ngIf="data.userDestRedirect.actionMode == 'delete'">{{'lang.delete' | translate}} - {{this.data.userDestRedirect.firstname}} {{this.data.userDestRedirect.lastname}}</b> - <b *ngIf="data.userDestRedirect.actionMode == 'suspend'">{{'lang.suspend' | translate}} - {{this.data.userDestRedirect.firstname}} {{this.data.userDestRedirect.lastname}}</b> - </div> - </ng-container> - </ng-container> - <ng-container *ngIf="!data.isDeletable"> - <div class="alert-message alert-message-info" role="alert"> - <p><span [innerHTML]="this.translate.instant('lang.userIsNotDeletable')"></span> <b>{{this.data.userDestRedirect.firstname}} - {{this.data.userDestRedirect.lastname}}</b> </p> - <p><span [innerHTML]="this.translate.instant('lang.userIsDeletableBy')"></span></p> - </div> - <div class="modal-body" *ngIf="data.inTemplateList" class="col-md-6"> - <mat-list> - <p mat-line>{{'lang.diffusionList' | translate}}</p> - <mat-list-item *ngFor="let templateEntity of data.listTemplateEntities"> - <mat-icon mat-list-icon><i class="fa fa-share-alt" color="primary"></i></mat-icon> - <p mat-line><span> {{templateEntity}} </span></p> - </mat-list-item> - </mat-list> - </div> - <div class="modal-body" *ngIf="data.inInstanceList" class="col-md-6"> - <mat-list> - <p mat-line>{{'lang.mailEntitiesList' | translate}}</p> - <mat-list-item *ngFor="let instanceEntity of data.listInstanceEntities"> - <mat-icon mat-list-icon><i class="fa fa-inbox" color="primary"></i></mat-icon> - <p mat-line><span> {{instanceEntity}} </span></p> - </mat-list-item> - </mat-list> - </div> - </ng-container> - </mat-dialog-content> - <span class="divider-modal"></span> - <mat-dialog-actions> - <button mat-raised-button color="warn" *ngIf="data.userDestRedirect.actionMode == 'delete' && data.isDeletable" - type="submit" class="btn btn-danger" (click)="dialogRef.close(this.data)" - [disabled]="!sendFunction()">{{'lang.delete' | translate}} - {{'lang.user' | translate}}</button> - <button mat-raised-button color="primary" *ngIf="data.userDestRedirect.actionMode == 'suspend' && data.isDeletable" - type="submit" (click)="dialogRef.close(this.data)" [disabled]="!sendFunction()">{{'lang.suspend' | translate}} - {{'lang.user' | translate}}</button> - <button mat-raised-button color="primary" *ngIf="!data.isDeletable" type="submit" - (click)="dialogRef.close()">{{'lang.close' | translate}}</button> - </mat-dialog-actions> -</div> diff --git a/src/frontend/app/administration/user/users-administration.component.html b/src/frontend/app/administration/user/users-administration.component.html index ba1ca24257669a8f86a5545dacc56384fb34416f..08ed4d39c0cbb8cb7bd6e05e0e038bfc9b1a16ed 100755 --- a/src/frontend/app/administration/user/users-administration.component.html +++ b/src/frontend/app/administration/user/users-administration.component.html @@ -108,7 +108,7 @@ <mat-cell *matCellDef="let element" style="justify-content: flex-end;"> <button mat-icon-button color="primary" [disabled]="element.id===user.id || (['root_visible', 'root_invisible'].indexOf(element.mode) > -1 && headerService.user.mode === 'standard')" *ngIf="element.status != 'SPD'" matTooltip="{{'lang.suspend' | translate}}" - (click)="$event.stopPropagation();deleteUser(element, 'suspend')"> + (click)="$event.stopPropagation();actionUserPrompt(element, 'suspend')"> <mat-icon class="fa fa-pause fa-2x" aria-hidden="true"></mat-icon> </button> <button mat-icon-button color="accent" *ngIf="element.status == 'SPD'" @@ -118,7 +118,7 @@ </button> <button mat-icon-button color="warn" [disabled]="element.id===user.id || ['root_visible', 'root_invisible'].indexOf(element.mode) > -1" matTooltip="{{'lang.delete' | translate}}" data-toggle="modal" data-target="#changeDiffListDest" - (click)="$event.stopPropagation();deleteUser(element, 'delete')"> + (click)="$event.stopPropagation();actionUserPrompt(element, 'delete')"> <mat-icon class="fa fa-trash-alt fa-2x"></mat-icon> </button> </mat-cell> diff --git a/src/frontend/app/administration/user/users-administration.component.ts b/src/frontend/app/administration/user/users-administration.component.ts index ccb6167b61cfc035460e2a660e9449f15fbb46fa..ae8dcfed4c99aec8821370a52d38dcbffe8442fa 100755 --- a/src/frontend/app/administration/user/users-administration.component.ts +++ b/src/frontend/app/administration/user/users-administration.component.ts @@ -1,4 +1,4 @@ -import { Component, OnInit, ViewChild, Inject, TemplateRef, ViewContainerRef, ElementRef, ChangeDetectorRef } from '@angular/core'; +import { Component, OnInit, ViewChild, TemplateRef, ViewContainerRef } from '@angular/core'; import { HttpClient } from '@angular/common/http'; import { TranslateService } from '@ngx-translate/core'; import { MatDialog, MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog'; @@ -13,6 +13,7 @@ import { UsersImportComponent } from './import/users-import.component'; import { UsersExportComponent } from './export/users-export.component'; import { catchError, filter, tap } from 'rxjs/operators'; import { AdministrationService } from '../administration.service'; +import { UsersAdministrationRedirectModalComponent } from './redirect-modal/users-administration-redirect-modal.component'; @Component({ templateUrl: 'users-administration.component.html', @@ -109,13 +110,7 @@ export class UsersAdministrationComponent implements OnInit { this.http.put('../rest/users/' + user.id, user) .subscribe(() => { this.notify.success(this.translate.instant('lang.userAuthorized')); - if (this.quota.userQuota) { - this.quota.inactives--; - this.quota.actives++; - if (this.quota.actives > this.quota.userQuota) { - this.notify.error(this.translate.instant('lang.quotaExceeded')); - } - } + this.updateQuota(user, 'activate'); }, (err) => { user.status = 'SPD'; this.notify.error(err.error.errors); @@ -123,275 +118,49 @@ export class UsersAdministrationComponent implements OnInit { } } - deleteUser(user: any, mode: string) { - user.actionMode = mode; - - this.http.get('../rest/users/' + user.id + '/isDeletable') - .subscribe((response: any) => { - if (response && response.hasOwnProperty('errors')) { - this.notify.error(response.errors); - } else { - user.isDeletable = response.isDeletable; - - if (response.isDeletable) { - this.config = { - panelClass: 'maarch-modal', - data: { - userDestRedirect: user, - isDeletable: response.isDeletable, - redirectListInstances: response.listInstances, - redirectListModels: response.listTemplates - } - }; - } else { - this.config = { - panelClass: 'maarch-modal', - data: { - userDestRedirect: user, - isDeletable: response.isDeletable, - listInstanceEntities: response.listInstanceEntities, - listTemplateEntities: response.listTemplateEntities - } - }; - - } - - // open modale - this.dialogRef = this.dialog.open(UsersAdministrationRedirectModalComponent, this.config); - this.dialogRef.afterClosed().subscribe((result: any) => { - - if (result && user.isDeletable) { - user.inDiffListDest = result.inDiffListDest; - user.isResDestUser = result.isResDestUser; - - if (result.inDiffListDest) { - user.redirectListModels = result.redirectListModels; - } - - if (result.isResDestUser) { - user.redirectDestResUserId = result.redirectDestResUserId; - - result.redirectListInstances.forEach((list: any) => { - list.listInstances.forEach((element: any) => { - if (element.item_mode === 'dest' && element.item_id === user.user_id) { - element.item_id = user.redirectDestResUserId; - } - }); - }); - - user.redirectListInstances = result.redirectListInstances; - } - - if (user.inDiffListDest && user.isResDestUser) { // user is inDiffListDest and isResDestUser - - // update listModels - this.http.put('../rest/listTemplates/entityDest/itemId/' + user.id, user) - .subscribe(() => { - this.http.put('../rest/listinstances', user.redirectListInstances) - .subscribe((data: any) => { - if (data != null && data.errors) { - this.notify.error(data.errors); - } else { - - // delete user - if (user.actionMode === 'delete') { - this.http.delete('../rest/users/' + user.id) - .subscribe(() => { - for (const i in this.data) { - if (this.data[i].id == user.id) { - this.data.splice(Number(i), 1); - } - } - this.adminService.setDataSource('admin_users', this.data, this.sort, this.paginator, this.filterColumns); - - if (this.quota.userQuota && user.status !== 'SPD') { - this.quota.actives--; - } else if (this.quota.userQuota && user.status === 'SPD') { - this.quota.inactives--; - } - - this.notify.success(this.translate.instant('lang.userDeleted') + ' « ' + user.user_id + ' »'); - - // end delete user - }, (err) => { - this.notify.error(err.error.errors); - }); - // suspend user - } else if (user.actionMode === 'suspend') { - this.http.put('../rest/users/' + user.id + '/suspend', user) - .subscribe(() => { - user.status = 'SPD'; - this.notify.success(this.translate.instant('lang.userSuspended')); - if (this.quota.userQuota) { - this.quota.inactives++; - this.quota.actives--; - } - - }, (err) => { - user.status = 'OK'; - this.notify.error(err.error.errors); - }); - } - } - // end update listInstances - }, (err) => { - this.notify.error(err.error.errors); - }); - }, (err) => { - this.notify.error(err.error.errors); - }); - - } else if (user.inDiffListDest && !user.isResDestUser) { // user is inDiffListDest - // update listModels - this.http.put('../rest/listTemplates/entityDest/itemId/' + user.id, user) - .subscribe(() => { - // delete user - if (user.actionMode === 'delete') { - this.http.delete('../rest/users/' + user.id) - .subscribe(() => { - for (const i in this.data) { - if (this.data[i].id == user.id) { - this.data.splice(Number(i), 1); - } - } - this.adminService.setDataSource('admin_users', this.data, this.sort, this.paginator, this.filterColumns); - - if (this.quota.userQuota && user.status === 'OK') { - this.quota.actives--; - } else if (this.quota.userQuota && user.status === 'SPD') { - this.quota.inactives--; - } - - this.notify.success(this.translate.instant('lang.userDeleted') + ' « ' + user.user_id + ' »'); - - // end delete user - }, (err) => { - this.notify.error(err.error.errors); - }); - // suspend user - } else if (user.actionMode === 'suspend') { - this.http.put('../rest/users/' + user.id + '/suspend', user) - .subscribe(() => { - user.status = 'SPD'; - this.notify.success(this.translate.instant('lang.userSuspended')); - if (this.quota.userQuota) { - this.quota.inactives++; - this.quota.actives--; - } - - }, (err) => { - user.status = 'OK'; - this.notify.error(err.error.errors); - }); - } - }, (err) => { - this.notify.error(err.error.errors); - }); - - } else if (!user.inDiffListDest && user.isResDestUser) { // user isResDestUser - // update listInstances - this.http.put('../rest/listinstances', user.redirectListInstances) - .subscribe((data: any) => { - if (data && data.hasOwnProperty('errors')) { - this.notify.error(data.errors); - } else { - - // delete user - if (user.actionMode === 'delete') { - this.http.delete('../rest/users/' + user.id) - .subscribe(() => { - for (const i in this.data) { - if (this.data[i].id === user.id) { - this.data.splice(Number(i), 1); - } - } - this.adminService.setDataSource('admin_users', this.data, this.sort, this.paginator, this.filterColumns); - - if (this.quota.userQuota && user.status === 'OK') { - this.quota.actives--; - } else if (this.quota.userQuota && user.status === 'SPD') { - this.quota.inactives--; - } - - this.notify.success(this.translate.instant('lang.userDeleted') + ' « ' + user.user_id + ' »'); - - // end delete user - }, (err) => { - this.notify.error(err.error.errors); - }); - // suspend user - } else if (user.actionMode === 'suspend') { - this.http.put('../rest/users/' + user.id + '/suspend', user) - .subscribe(() => { - user.status = 'SPD'; - this.notify.success(this.translate.instant('lang.userSuspended')); - if (this.quota.userQuota) { - this.quota.inactives++; - this.quota.actives--; - } - - }, (err) => { - user.status = 'OK'; - this.notify.error(err.error.errors); - }); - } - } - // end update listInstances - }, (err) => { - this.notify.error(err.error.errors); - }); - - } else if (!user.inDiffListDest && !user.isResDestUser) { // user is not inDiffListDest and is not isResDestUser - - // delete user - if (user.actionMode === 'delete') { - this.http.delete('../rest/users/' + user.id) - .subscribe(() => { - for (const i in this.data) { - if (this.data[i].id == user.id) { - this.data.splice(Number(i), 1); - } - } - this.adminService.setDataSource('admin_users', this.data, this.sort, this.paginator, this.filterColumns); - - if (this.quota.userQuota && user.status === 'OK') { - this.quota.actives--; - } else if (this.quota.userQuota && user.status === 'SPD') { - this.quota.inactives--; - } - - this.notify.success(this.translate.instant('lang.userDeleted') + ' « ' + user.user_id + ' »'); + updateQuota(user: any, mode: string) { + if (mode === 'delete') { + if (this.quota.userQuota && user.status === 'OK') { + this.quota.actives--; + } else if (this.quota.userQuota && user.status === 'SPD') { + this.quota.inactives--; + } + } else if (mode === 'suspend') { + if (this.quota.userQuota) { + this.quota.inactives++; + this.quota.actives--; + } + } else if (mode === 'activate') { + if (this.quota.userQuota) { + this.quota.inactives--; + this.quota.actives++; + if (this.quota.actives > this.quota.userQuota) { + this.notify.error(this.translate.instant('lang.quotaExceeded')); + } + } + } + } - // end delete user - }, (err) => { - this.notify.error(err.error.errors); - }); - // suspend user - } else if (user.actionMode === 'suspend') { - this.http.put('../rest/users/' + user.id + '/suspend', user) - .subscribe(() => { - user.status = 'SPD'; - this.notify.success(this.translate.instant('lang.userSuspended')); - if (this.quota.userQuota) { - this.quota.inactives++; - this.quota.actives--; - } + actionUserPrompt(user: any, mode: string) { + user.actionMode = mode; - }, (err) => { - user.status = 'OK'; - this.notify.error(err.error.errors); - }); - } - } + this.dialogRef = this.dialog.open(UsersAdministrationRedirectModalComponent, { panelClass: 'maarch-modal', data: { user: user } }); + this.dialogRef.afterClosed().pipe( + filter((res: any) => res === 'success'), + tap((res: any) => { + this.updateQuota(user, mode); + if (user.actionMode === 'delete') { + for (const i in this.data) { + if (this.data[i].id == user.id) { + this.data.splice(Number(i), 1); } - - // close modale - }); + } + this.adminService.setDataSource('admin_users', this.data, this.sort, this.paginator, this.filterColumns); + } else { + user.status = 'SPD'; } - // end isDeletable - }, (err) => { - this.notify.error(err.error.errors); - }); + }) + ).subscribe(); } toggleWebserviceAccount() { @@ -428,93 +197,4 @@ export class UsersAdministrationComponent implements OnInit { this.dialog.open(UsersExportComponent, { panelClass: 'maarch-modal', width: '400px', autoFocus: false }); } - -} -@Component({ - templateUrl: 'users-administration-redirect-modal.component.html', - styleUrls: ['users-administration-redirect-modal.scss'], -}) -export class UsersAdministrationRedirectModalComponent implements OnInit { - - loadModel: boolean = false; - loadInstance: boolean = false; - modalTitle: string = this.translate.instant('lang.confirmAction'); - - constructor( - public translate: TranslateService, - public http: HttpClient, - @Inject(MAT_DIALOG_DATA) public data: any, - public dialogRef: MatDialogRef<UsersAdministrationRedirectModalComponent>, - private notify: NotificationService) { - } - - ngOnInit(): void { - - if (this.data.isDeletable) { - // get listModel - if (this.data.redirectListModels.length > 0) { - this.data.inDiffListDest = true; - } - - // get listInstances - if (this.data.redirectListInstances.length > 0) { - this.data.isResDestUser = true; - } - } else { - if (this.data.userDestRedirect.actionMode === 'delete') { - this.modalTitle = this.translate.instant('lang.unableToDelete'); - } else { - this.modalTitle = this.translate.instant('lang.unableToSuspend'); - } - // get listModel - if (this.data.listTemplateEntities.length > 0) { - this.data.inTemplateList = true; - } - - // get listInstances - if (this.data.listInstanceEntities.length > 0) { - this.data.inInstanceList = true; - } - } - } - - setRedirectUserListModels(index: number, user: any) { - if (this.data.userDestRedirect.user_id != user.id) { - this.data.redirectListModels[index].redirectUserId = user.id; - } else { - this.data.redirectListModels[index].redirectUserId = null; - this.notify.error(this.translate.instant('lang.userUnauthorized')); - } - - } - - setRedirectUserRes(user: any) { - if (this.data.userDestRedirect.user_id != user.id) { - this.data.redirectDestResUserId = user.id; - } else { - this.data.redirectDestResUserId = null; - this.notify.error(this.translate.instant('lang.userUnauthorized')); - } - - } - - sendFunction() { - let valid = true; - - if (this.data.inDiffListDest) { - this.data.redirectListModels.forEach((element: any) => { - if (!element.redirectUserId) { - valid = false; - } - }); - } - - if (this.data.isResDestUser) { - if (!this.data.redirectDestResUserId) { - valid = false; - } - } - - return valid; - } -} +} \ No newline at end of file diff --git a/src/lang/lang-fr.json b/src/lang/lang-fr.json index 5683afa7a697c8c03a91e061d037e6bf1899b658..6e4b8761122730682684106422c2421022f3d206 100644 --- a/src/lang/lang-fr.json +++ b/src/lang/lang-fr.json @@ -2151,5 +2151,6 @@ "insteadOf": "À la place de", "doNotDefine": "Ne pas définir", "infoImportNoIdToCreate": "La colonne <b>id</b> doit être vide pour la création", - "almostThere": "Vous y êtes presque !" + "almostThere": "Vous y êtes presque !", + "redirectUserVisaWorkflow": "Changement de viseur / signataire pour les courriers en cours de visa / signature" }