From 04420f1d7b0330708db58e18050997610dae9ad9 Mon Sep 17 00:00:00 2001 From: Damien Trouillet Date: Tue, 22 Jun 2021 17:39:48 +0200 Subject: [PATCH 1/7] Add identity screen --- .../admin-norms-routing.module.ts | 19 +++ .../admin-norms.component.html | 70 +++++++++ .../admin-identities/admin-norms.component.ts | 141 ++++++++++++++++++ .../admin-identities/admin-norms.module.ts | 26 ++++ .../modal-identity-deletion.component.html | 13 ++ .../modal-identity-deletion.component.ts | 14 ++ .../modal-identity.component.html | 66 ++++++++ .../modal-identity.component.ts | 57 +++++++ 8 files changed, 406 insertions(+) create mode 100644 src/app/admin-identities/admin-norms-routing.module.ts create mode 100644 src/app/admin-identities/admin-norms.component.html create mode 100644 src/app/admin-identities/admin-norms.component.ts create mode 100644 src/app/admin-identities/admin-norms.module.ts create mode 100644 src/app/admin-identities/modal-identity-deletion/modal-identity-deletion.component.html create mode 100644 src/app/admin-identities/modal-identity-deletion/modal-identity-deletion.component.ts create mode 100644 src/app/admin-identities/modal-identity/modal-identity.component.html create mode 100644 src/app/admin-identities/modal-identity/modal-identity.component.ts diff --git a/src/app/admin-identities/admin-norms-routing.module.ts b/src/app/admin-identities/admin-norms-routing.module.ts new file mode 100644 index 000000000..4a5004dca --- /dev/null +++ b/src/app/admin-identities/admin-norms-routing.module.ts @@ -0,0 +1,19 @@ +import {NgModule} from '@angular/core'; +import {RouterModule, Routes} from '@angular/router'; +import {AuthGuard} from '../core'; +import {AdminNormsComponent} from './admin-norms.component'; + +const routes: Routes = [ + { + path: '', + component: AdminNormsComponent, + canActivate: [AuthGuard] + } +]; + +@NgModule({ + imports: [RouterModule.forChild(routes)], + exports: [RouterModule] +}) +export class AdminNormsRoutingModule { +} diff --git a/src/app/admin-identities/admin-norms.component.html b/src/app/admin-identities/admin-norms.component.html new file mode 100644 index 000000000..438d9f2b8 --- /dev/null +++ b/src/app/admin-identities/admin-norms.component.html @@ -0,0 +1,70 @@ +
+
+
+

+ Administration +

+

+ Normes +

+
+ +
+
+ + +
+
+ + + + + + + + + + + + + + + + + + + + + +
ID + Nom + + Interpréteur + + Dossier shell + + Fichier date + +
+ {{norm.id}} + + {{norm.name}} + + {{norm.commandLine}} + + {{norm.pathShell}} + + {{norm.ctrlMDate}} + + Edit + Delete +
+
+
diff --git a/src/app/admin-identities/admin-norms.component.ts b/src/app/admin-identities/admin-norms.component.ts new file mode 100644 index 000000000..e9c4c9129 --- /dev/null +++ b/src/app/admin-identities/admin-norms.component.ts @@ -0,0 +1,141 @@ +import {AfterViewInit, Component, OnDestroy, OnInit, ViewChild} from '@angular/core'; +import {NgbModal} from '@ng-bootstrap/ng-bootstrap'; +import {ModalNormComponent} from './modal-identity/modal-norm.component'; +import {ModalNormDeletionComponent} from './modal-identity-deletion/modal-norm-deletion.component'; +import {Constants} from '../shared/Constants'; +import {Subject} from 'rxjs'; +import {Norme, NormsService} from '../core'; +import {ToastService} from '../core/services/toast.service'; +import {TranslateService} from '@ngx-translate/core'; +import {DataTableDirective} from 'angular-datatables'; +import LanguageSettings = DataTables.LanguageSettings; + +@Component({ + selector: 'app-admin-norms', + templateUrl: './admin-norms.component.html' +}) +export class AdminNormsComponent implements AfterViewInit, OnDestroy, OnInit { + @ViewChild(DataTableDirective, { static: true }) + dtElement: DataTableDirective; + dtTrigger: Subject = new Subject(); + dtOptions: DataTables.Settings = {}; + + norms: Norme[]; + columns = []; + + constructor(private modalService: NgbModal, + private constants: Constants, + private toastService: ToastService, + private normsService: NormsService, + private translateService: TranslateService) { + this.columns.push({data: 'id', name: 'id', visible: true}); + this.columns.push({data: 'name', name: 'nom', visible: true}); + this.columns.push({data: 'commandLine', name: 'interpréteur', visible: true}); + this.columns.push({data: 'pathShell', name: 'dossier shell', visible: true}); + this.columns.push({data: 'ctrlMDate', name: 'fichier date', visible: true}); + this.columns.push({data: '', name: 'actions', visible: true, orderable: false}); + + } + + ngOnInit() { + this.dtOptions = { + language: this.constants.datatable[this.translateService.currentLang] as LanguageSettings, + stateSave: true, + stateSaveParams: function (settings, data: any) { + data.search.search = ""; + }, + order: [[1, 'asc']], + pagingType: 'full_numbers', + pageLength: this.constants.numberByPage, + serverSide: true, + processing: false, + ajax: (dataTablesParameters: any, callback) => { + this.normsService + .getAll({ + page: dataTablesParameters.start / dataTablesParameters.length, + size: dataTablesParameters.length, + sort: dataTablesParameters.columns[dataTablesParameters.order[0].column].data + ',' + dataTablesParameters.order[0].dir, + name: dataTablesParameters.search.value + } + ) + .subscribe(resp => { + this.norms = resp.content; + callback({ + recordsTotal: resp.totalElements, + recordsFiltered: resp.totalElements, + data: [] + }); + }); + }, + columns: this.columns + }; + this.dtTrigger.next(); + } + + ngAfterViewInit(): void { + this.dtTrigger.next(); + } + + ngOnDestroy(): void { + this.dtTrigger.unsubscribe(); + } + + + refreshNorms() { + this.dtElement.dtInstance.then((dtInstance: DataTables.Api) => { + dtInstance.destroy(); + this.dtTrigger.next(); + }); + } + + onClickAddNorm() { + const modalRef = this.modalService.open(ModalNormComponent); + modalRef.result.then(() => { + this.toastService.showSuccess(`La norme a bien été ajoutée`); + this.refreshNorms(); + }, (reason) => { + if (reason.message !== undefined) { + this.toastService.showError( `Une erreur est survenue lors de l'ajout de la norme : ${reason.message}`); + } + }); + modalRef.componentInstance.isUpdate = false; + } + + editNorm(norm: Norme) { + const modalRef = this.modalService.open(ModalNormComponent); + modalRef.result.then(() => { + this.toastService.showSuccess(`La norme a bien été modifiée`); + this.refreshNorms(); + }, (reason) => { + if (reason.message !== undefined) { + this.toastService.showError( `Une erreur est survenue lors de la modification de la norme : ${reason.message}`); + } + }); + modalRef.componentInstance.norm = {...norm}; + modalRef.componentInstance.isUpdate = true; + } + + deleteNorm(norm: Norme) { + const modalRef = this.modalService.open(ModalNormDeletionComponent); + modalRef.result.then(() => { + this.normsService.deleteNorm(norm.id).subscribe( + () => { + this.toastService.showSuccess(`La norme a été supprimée`); + this.refreshNorms(); + }, + reason => { + this.toastService.showError( `Une erreur est survenue lors de la suppression de la norme : ${reason.detail}`); + } + ); + }); + modalRef.componentInstance.norm = norm; + } + onResizeTable(event){ + if(event.oldWidth == undefined || event.newWidth === event.oldWidth){ + return; + } + this.refreshNorms(); + } +} + + diff --git a/src/app/admin-identities/admin-norms.module.ts b/src/app/admin-identities/admin-norms.module.ts new file mode 100644 index 000000000..fe96b93f7 --- /dev/null +++ b/src/app/admin-identities/admin-norms.module.ts @@ -0,0 +1,26 @@ +import {NgModule} from '@angular/core'; +import {AdminNormsComponent} from './admin-norms.component'; +import {AdminNormsRoutingModule} from './admin-norms-routing.module'; +import {SharedModule} from '../shared'; +import {ModalNormComponent} from './modal-identity/modal-norm.component'; +import {ModalNormDeletionComponent} from './modal-identity-deletion/modal-norm-deletion.component'; +import {NgbPaginationModule} from '@ng-bootstrap/ng-bootstrap'; +import {DataTablesModule} from 'angular-datatables'; +import {AngularResizedEventModule} from "angular-resize-event"; + +@NgModule({ + declarations: [AdminNormsComponent, ModalNormComponent, ModalNormDeletionComponent], + imports: [ + AdminNormsRoutingModule, + SharedModule, + NgbPaginationModule, + DataTablesModule, + AngularResizedEventModule + ], + entryComponents: [ + ModalNormDeletionComponent, + ModalNormComponent + ] +}) +export class AdminNormsModule { +} diff --git a/src/app/admin-identities/modal-identity-deletion/modal-identity-deletion.component.html b/src/app/admin-identities/modal-identity-deletion/modal-identity-deletion.component.html new file mode 100644 index 000000000..11fd39baf --- /dev/null +++ b/src/app/admin-identities/modal-identity-deletion/modal-identity-deletion.component.html @@ -0,0 +1,13 @@ + + + diff --git a/src/app/admin-identities/modal-identity-deletion/modal-identity-deletion.component.ts b/src/app/admin-identities/modal-identity-deletion/modal-identity-deletion.component.ts new file mode 100644 index 000000000..77e811bf0 --- /dev/null +++ b/src/app/admin-identities/modal-identity-deletion/modal-identity-deletion.component.ts @@ -0,0 +1,14 @@ +import {Component} from '@angular/core'; +import {NgbActiveModal} from '@ng-bootstrap/ng-bootstrap'; +import {Norme} from '../../core'; + +@Component({ + selector: 'app-modal-identity-deletion', + templateUrl: './modal-norm-deletion.component.html' +}) +export class ModalIdentityDeletionComponent { + norm: Norme; + + constructor(public activeModal: NgbActiveModal) { + } +} diff --git a/src/app/admin-identities/modal-identity/modal-identity.component.html b/src/app/admin-identities/modal-identity/modal-identity.component.html new file mode 100644 index 000000000..77d8bcf50 --- /dev/null +++ b/src/app/admin-identities/modal-identity/modal-identity.component.html @@ -0,0 +1,66 @@ +
+ + + +
diff --git a/src/app/admin-identities/modal-identity/modal-identity.component.ts b/src/app/admin-identities/modal-identity/modal-identity.component.ts new file mode 100644 index 000000000..f150ac366 --- /dev/null +++ b/src/app/admin-identities/modal-identity/modal-identity.component.ts @@ -0,0 +1,57 @@ +import {Component, OnInit} from '@angular/core'; +import {NgbActiveModal} from '@ng-bootstrap/ng-bootstrap'; +import {NormsService, Norme} from '../../core'; + +@Component({ + selector: 'app-modal-identity', + templateUrl: './modal-identity.component.html' +}) +export class ModalIdentityComponent implements OnInit { + isUpdate = false; + title = 'Ajouter une norme'; + action = 'Ajouter'; + norm: Norme = { + id: undefined, + name: undefined, + commandLine: undefined, + ctrlMDate: undefined, + pathShell: undefined, + createdBy: undefined, + createdDate: undefined, + lastModifiedBy: undefined, + lastModifiedDate: undefined + }; + + constructor(public activeModal: NgbActiveModal, + private normsService: NormsService) { + } + + ngOnInit() { + if (this.isUpdate) { + this.title = `Modifier la norme ${this.norm.name}`; + this.action = `Modifier`; + } + } + + addNorm() { + if (!this.isUpdate) { + this.normsService.addNorm(this.norm).subscribe( + () => { + this.activeModal.close(); + }, + error => { + this.activeModal.dismiss(error); + } + ); + } else { + this.normsService.updateNorm(this.norm).subscribe( + norm => { + this.activeModal.close(norm); + }, + error => { + this.activeModal.dismiss(error); + } + ); + } + } +} From cfadb0fb40e390f1be97710d98e4ff34294ff56f Mon Sep 17 00:00:00 2001 From: Damien Trouillet Date: Wed, 23 Jun 2021 15:38:28 +0200 Subject: [PATCH 2/7] Add identity screen --- ....ts => admin-identities-routing.module.ts} | 6 +- ...t.html => admin-identities.component.html} | 38 ++--- .../admin-identities.component.ts | 141 ++++++++++++++++++ .../admin-identities.module.ts | 26 ++++ .../admin-identities/admin-norms.component.ts | 141 ------------------ .../admin-identities/admin-norms.module.ts | 26 ---- .../modal-identity-deletion.component.html | 8 +- .../modal-identity-deletion.component.ts | 6 +- .../modal-identity.component.html | 56 ++----- .../modal-identity.component.ts | 29 ++-- src/app/app-routing.module.ts | 4 + src/app/app.component.ts | 6 +- src/app/core/core.module.ts | 4 +- src/app/core/models/identity.model.ts | 11 ++ src/app/core/services/identities.service.ts | 35 +++++ .../shared/layout/aside/aside.component.html | 4 + src/assets/i18n/en.json | 26 +++- src/assets/i18n/fr.json | 26 +++- 18 files changed, 330 insertions(+), 263 deletions(-) rename src/app/admin-identities/{admin-norms-routing.module.ts => admin-identities-routing.module.ts} (65%) rename src/app/admin-identities/{admin-norms.component.html => admin-identities.component.html} (58%) create mode 100644 src/app/admin-identities/admin-identities.component.ts create mode 100644 src/app/admin-identities/admin-identities.module.ts delete mode 100644 src/app/admin-identities/admin-norms.component.ts delete mode 100644 src/app/admin-identities/admin-norms.module.ts create mode 100644 src/app/core/models/identity.model.ts create mode 100644 src/app/core/services/identities.service.ts diff --git a/src/app/admin-identities/admin-norms-routing.module.ts b/src/app/admin-identities/admin-identities-routing.module.ts similarity index 65% rename from src/app/admin-identities/admin-norms-routing.module.ts rename to src/app/admin-identities/admin-identities-routing.module.ts index 4a5004dca..419c35c46 100644 --- a/src/app/admin-identities/admin-norms-routing.module.ts +++ b/src/app/admin-identities/admin-identities-routing.module.ts @@ -1,12 +1,12 @@ import {NgModule} from '@angular/core'; import {RouterModule, Routes} from '@angular/router'; import {AuthGuard} from '../core'; -import {AdminNormsComponent} from './admin-norms.component'; +import {AdminIdentitiesComponent} from './admin-identities.component'; const routes: Routes = [ { path: '', - component: AdminNormsComponent, + component: AdminIdentitiesComponent, canActivate: [AuthGuard] } ]; @@ -15,5 +15,5 @@ const routes: Routes = [ imports: [RouterModule.forChild(routes)], exports: [RouterModule] }) -export class AdminNormsRoutingModule { +export class AdminIdentitiesRoutingModule { } diff --git a/src/app/admin-identities/admin-norms.component.html b/src/app/admin-identities/admin-identities.component.html similarity index 58% rename from src/app/admin-identities/admin-norms.component.html rename to src/app/admin-identities/admin-identities.component.html index 438d9f2b8..b00a07a3b 100644 --- a/src/app/admin-identities/admin-norms.component.html +++ b/src/app/admin-identities/admin-identities.component.html @@ -10,9 +10,9 @@

@@ -25,43 +25,31 @@

- - + - - - - + - - - diff --git a/src/app/admin-identities/admin-identities.component.ts b/src/app/admin-identities/admin-identities.component.ts new file mode 100644 index 000000000..8d37be77d --- /dev/null +++ b/src/app/admin-identities/admin-identities.component.ts @@ -0,0 +1,141 @@ +import {AfterViewInit, Component, OnDestroy, OnInit, ViewChild} from '@angular/core'; +import {NgbModal} from '@ng-bootstrap/ng-bootstrap'; +import {Constants} from '../shared/Constants'; +import {Subject} from 'rxjs'; +import {ToastService} from '../core/services/toast.service'; +import {TranslateService} from '@ngx-translate/core'; +import {DataTableDirective} from 'angular-datatables'; +import LanguageSettings = DataTables.LanguageSettings; +import {Identity} from '../core/models/identity.model'; +import {IdentitiesService} from '../core/services/identities.service'; +import {ModalIdentityComponent} from './modal-identity/modal-identity.component'; +import {ModalIdentityDeletionComponent} from './modal-identity-deletion/modal-identity-deletion.component'; + +@Component({ + selector: 'app-admin-identities', + templateUrl: './admin-identities.component.html' +}) +export class AdminIdentitiesComponent implements AfterViewInit, OnDestroy, OnInit { + @ViewChild(DataTableDirective, {static: true}) + dtElement: DataTableDirective; + dtTrigger: Subject = new Subject(); + dtOptions: DataTables.Settings = {}; + + identities: Identity[]; + columns = []; + + constructor(private modalService: NgbModal, + private constants: Constants, + private toastService: ToastService, + private identitiesService: IdentitiesService, + private translateService: TranslateService) { + this.columns.push({data: 'id', name: 'id', visible: true}); + this.columns.push({data: 'name', name: 'nom', visible: true}); + this.columns.push({data: 'login', name: 'login', visible: true}); + this.columns.push({data: '', name: 'actions', visible: true, orderable: false}); + + } + + ngOnInit() { + this.dtOptions = { + language: this.constants.datatable[this.translateService.currentLang] as LanguageSettings, + stateSave: true, + stateSaveParams(settings, data: any) { + data.search.search = ''; + }, + order: [[1, 'asc']], + pagingType: 'full_numbers', + pageLength: this.constants.numberByPage, + serverSide: true, + processing: false, + ajax: (dataTablesParameters: any, callback) => { + this.identitiesService + .getAll({ + page: dataTablesParameters.start / dataTablesParameters.length, + size: dataTablesParameters.length, + sort: dataTablesParameters.columns[dataTablesParameters.order[0].column].data + ',' + dataTablesParameters.order[0].dir, + name: dataTablesParameters.search.value + } + ) + .subscribe(resp => { + this.identities = resp.content; + callback({ + recordsTotal: resp.totalElements, + recordsFiltered: resp.totalElements, + data: [] + }); + }); + }, + columns: this.columns + }; + this.dtTrigger.next(); + } + + ngAfterViewInit(): void { + this.dtTrigger.next(); + } + + ngOnDestroy(): void { + this.dtTrigger.unsubscribe(); + } + + + refreshIdentities() { + this.dtElement.dtInstance.then((dtInstance: DataTables.Api) => { + dtInstance.destroy(); + this.dtTrigger.next(); + }); + } + + onClickAddIdentity() { + const modalRef = this.modalService.open(ModalIdentityComponent); + modalRef.result.then(() => { + this.toastService.showSuccess(`La norme a bien été ajoutée`); + this.refreshIdentities(); + }, (reason) => { + if (reason.message !== undefined) { + this.toastService.showError( `Une erreur est survenue lors de l'ajout de la norme : ${reason.message}`); + } + }); + modalRef.componentInstance.isUpdate = false; + } + + editIdentity(identity: Identity) { + const modalRef = this.modalService.open(ModalIdentityComponent); + modalRef.result.then(() => { + this.toastService.showSuccess(`La norme a bien été modifiée`); + this.refreshIdentities(); + }, (reason) => { + if (reason.message !== undefined) { + this.toastService.showError( `Une erreur est survenue lors de la modification de la norme : ${reason.message}`); + } + }); + this.identitiesService.getIdentity(identity.id).subscribe(value => modalRef.componentInstance.identity = value); + modalRef.componentInstance.isUpdate = true; + } + + deleteIdentity(identity: Identity) { + const modalRef = this.modalService.open(ModalIdentityDeletionComponent); + modalRef.result.then(() => { + this.identitiesService.deleteIdentity(identity.id).subscribe( + () => { + this.toastService.showSuccess(`La norme a été supprimée`); + this.refreshIdentities(); + }, + reason => { + this.toastService.showError( `Une erreur est survenue lors de la suppression de la norme : ${reason.detail}`); + } + ); + }); + modalRef.componentInstance.identity = identity; + } + + onResizeTable(event) { + if (event.oldWidth === undefined || event.newWidth === event.oldWidth) { + return; + } + this.refreshIdentities(); + } +} + + diff --git a/src/app/admin-identities/admin-identities.module.ts b/src/app/admin-identities/admin-identities.module.ts new file mode 100644 index 000000000..dee17e3b6 --- /dev/null +++ b/src/app/admin-identities/admin-identities.module.ts @@ -0,0 +1,26 @@ +import {NgModule} from '@angular/core'; +import {AdminIdentitiesComponent} from './admin-identities.component'; +import {AdminIdentitiesRoutingModule} from './admin-identities-routing.module'; +import {SharedModule} from '../shared'; +import {ModalIdentityComponent} from './modal-identity/modal-identity.component'; +import {ModalIdentityDeletionComponent} from './modal-identity-deletion/modal-identity-deletion.component'; +import {NgbPaginationModule} from '@ng-bootstrap/ng-bootstrap'; +import {DataTablesModule} from 'angular-datatables'; +import {AngularResizedEventModule} from 'angular-resize-event'; + +@NgModule({ + declarations: [AdminIdentitiesComponent, ModalIdentityComponent, ModalIdentityDeletionComponent], + imports: [ + AdminIdentitiesRoutingModule, + SharedModule, + NgbPaginationModule, + DataTablesModule, + AngularResizedEventModule + ], + entryComponents: [ + ModalIdentityComponent, + ModalIdentityDeletionComponent + ] +}) +export class AdminIdentitiesModule { +} diff --git a/src/app/admin-identities/admin-norms.component.ts b/src/app/admin-identities/admin-norms.component.ts deleted file mode 100644 index e9c4c9129..000000000 --- a/src/app/admin-identities/admin-norms.component.ts +++ /dev/null @@ -1,141 +0,0 @@ -import {AfterViewInit, Component, OnDestroy, OnInit, ViewChild} from '@angular/core'; -import {NgbModal} from '@ng-bootstrap/ng-bootstrap'; -import {ModalNormComponent} from './modal-identity/modal-norm.component'; -import {ModalNormDeletionComponent} from './modal-identity-deletion/modal-norm-deletion.component'; -import {Constants} from '../shared/Constants'; -import {Subject} from 'rxjs'; -import {Norme, NormsService} from '../core'; -import {ToastService} from '../core/services/toast.service'; -import {TranslateService} from '@ngx-translate/core'; -import {DataTableDirective} from 'angular-datatables'; -import LanguageSettings = DataTables.LanguageSettings; - -@Component({ - selector: 'app-admin-norms', - templateUrl: './admin-norms.component.html' -}) -export class AdminNormsComponent implements AfterViewInit, OnDestroy, OnInit { - @ViewChild(DataTableDirective, { static: true }) - dtElement: DataTableDirective; - dtTrigger: Subject = new Subject(); - dtOptions: DataTables.Settings = {}; - - norms: Norme[]; - columns = []; - - constructor(private modalService: NgbModal, - private constants: Constants, - private toastService: ToastService, - private normsService: NormsService, - private translateService: TranslateService) { - this.columns.push({data: 'id', name: 'id', visible: true}); - this.columns.push({data: 'name', name: 'nom', visible: true}); - this.columns.push({data: 'commandLine', name: 'interpréteur', visible: true}); - this.columns.push({data: 'pathShell', name: 'dossier shell', visible: true}); - this.columns.push({data: 'ctrlMDate', name: 'fichier date', visible: true}); - this.columns.push({data: '', name: 'actions', visible: true, orderable: false}); - - } - - ngOnInit() { - this.dtOptions = { - language: this.constants.datatable[this.translateService.currentLang] as LanguageSettings, - stateSave: true, - stateSaveParams: function (settings, data: any) { - data.search.search = ""; - }, - order: [[1, 'asc']], - pagingType: 'full_numbers', - pageLength: this.constants.numberByPage, - serverSide: true, - processing: false, - ajax: (dataTablesParameters: any, callback) => { - this.normsService - .getAll({ - page: dataTablesParameters.start / dataTablesParameters.length, - size: dataTablesParameters.length, - sort: dataTablesParameters.columns[dataTablesParameters.order[0].column].data + ',' + dataTablesParameters.order[0].dir, - name: dataTablesParameters.search.value - } - ) - .subscribe(resp => { - this.norms = resp.content; - callback({ - recordsTotal: resp.totalElements, - recordsFiltered: resp.totalElements, - data: [] - }); - }); - }, - columns: this.columns - }; - this.dtTrigger.next(); - } - - ngAfterViewInit(): void { - this.dtTrigger.next(); - } - - ngOnDestroy(): void { - this.dtTrigger.unsubscribe(); - } - - - refreshNorms() { - this.dtElement.dtInstance.then((dtInstance: DataTables.Api) => { - dtInstance.destroy(); - this.dtTrigger.next(); - }); - } - - onClickAddNorm() { - const modalRef = this.modalService.open(ModalNormComponent); - modalRef.result.then(() => { - this.toastService.showSuccess(`La norme a bien été ajoutée`); - this.refreshNorms(); - }, (reason) => { - if (reason.message !== undefined) { - this.toastService.showError( `Une erreur est survenue lors de l'ajout de la norme : ${reason.message}`); - } - }); - modalRef.componentInstance.isUpdate = false; - } - - editNorm(norm: Norme) { - const modalRef = this.modalService.open(ModalNormComponent); - modalRef.result.then(() => { - this.toastService.showSuccess(`La norme a bien été modifiée`); - this.refreshNorms(); - }, (reason) => { - if (reason.message !== undefined) { - this.toastService.showError( `Une erreur est survenue lors de la modification de la norme : ${reason.message}`); - } - }); - modalRef.componentInstance.norm = {...norm}; - modalRef.componentInstance.isUpdate = true; - } - - deleteNorm(norm: Norme) { - const modalRef = this.modalService.open(ModalNormDeletionComponent); - modalRef.result.then(() => { - this.normsService.deleteNorm(norm.id).subscribe( - () => { - this.toastService.showSuccess(`La norme a été supprimée`); - this.refreshNorms(); - }, - reason => { - this.toastService.showError( `Une erreur est survenue lors de la suppression de la norme : ${reason.detail}`); - } - ); - }); - modalRef.componentInstance.norm = norm; - } - onResizeTable(event){ - if(event.oldWidth == undefined || event.newWidth === event.oldWidth){ - return; - } - this.refreshNorms(); - } -} - - diff --git a/src/app/admin-identities/admin-norms.module.ts b/src/app/admin-identities/admin-norms.module.ts deleted file mode 100644 index fe96b93f7..000000000 --- a/src/app/admin-identities/admin-norms.module.ts +++ /dev/null @@ -1,26 +0,0 @@ -import {NgModule} from '@angular/core'; -import {AdminNormsComponent} from './admin-norms.component'; -import {AdminNormsRoutingModule} from './admin-norms-routing.module'; -import {SharedModule} from '../shared'; -import {ModalNormComponent} from './modal-identity/modal-norm.component'; -import {ModalNormDeletionComponent} from './modal-identity-deletion/modal-norm-deletion.component'; -import {NgbPaginationModule} from '@ng-bootstrap/ng-bootstrap'; -import {DataTablesModule} from 'angular-datatables'; -import {AngularResizedEventModule} from "angular-resize-event"; - -@NgModule({ - declarations: [AdminNormsComponent, ModalNormComponent, ModalNormDeletionComponent], - imports: [ - AdminNormsRoutingModule, - SharedModule, - NgbPaginationModule, - DataTablesModule, - AngularResizedEventModule - ], - entryComponents: [ - ModalNormDeletionComponent, - ModalNormComponent - ] -}) -export class AdminNormsModule { -} diff --git a/src/app/admin-identities/modal-identity-deletion/modal-identity-deletion.component.html b/src/app/admin-identities/modal-identity-deletion/modal-identity-deletion.component.html index 11fd39baf..a41f28d5f 100644 --- a/src/app/admin-identities/modal-identity-deletion/modal-identity-deletion.component.html +++ b/src/app/admin-identities/modal-identity-deletion/modal-identity-deletion.component.html @@ -1,13 +1,13 @@ diff --git a/src/app/admin-identities/modal-identity-deletion/modal-identity-deletion.component.ts b/src/app/admin-identities/modal-identity-deletion/modal-identity-deletion.component.ts index 77e811bf0..397a36bbc 100644 --- a/src/app/admin-identities/modal-identity-deletion/modal-identity-deletion.component.ts +++ b/src/app/admin-identities/modal-identity-deletion/modal-identity-deletion.component.ts @@ -1,13 +1,13 @@ import {Component} from '@angular/core'; import {NgbActiveModal} from '@ng-bootstrap/ng-bootstrap'; -import {Norme} from '../../core'; +import {Identity} from '../../core/models/identity.model'; @Component({ selector: 'app-modal-identity-deletion', - templateUrl: './modal-norm-deletion.component.html' + templateUrl: './modal-identity-deletion.component.html' }) export class ModalIdentityDeletionComponent { - norm: Norme; + identity: Identity; constructor(public activeModal: NgbActiveModal) { } diff --git a/src/app/admin-identities/modal-identity/modal-identity.component.html b/src/app/admin-identities/modal-identity/modal-identity.component.html index 77d8bcf50..afa3037be 100644 --- a/src/app/admin-identities/modal-identity/modal-identity.component.html +++ b/src/app/admin-identities/modal-identity/modal-identity.component.html @@ -1,4 +1,4 @@ -
+
ID + ID Nom - Interpréteur - - Dossier shell - - Fichier date + + Login
- {{norm.id}} + {{identity.id}} - {{norm.name}} + {{identity.name}} - {{norm.commandLine}} - - {{norm.pathShell}} - - {{norm.ctrlMDate}} + {{identity.login}} - Edit - Delete + + {{'IDENTITY.EDIT' | translate}} + {{'IDENTITY.DELETE' | translate}}
- + diff --git a/src/app/admin-identities/modal-identity/modal-identity.component.html b/src/app/admin-identities/modal-identity/modal-identity.component.html index afa3037be..4a7d46502 100644 --- a/src/app/admin-identities/modal-identity/modal-identity.component.html +++ b/src/app/admin-identities/modal-identity/modal-identity.component.html @@ -30,6 +30,42 @@ +
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
-
ID{{'IDENTITY.ID' | translate}} - Nom + {{'IDENTITY.NAME' | translate}} - Login + {{'IDENTITY.LOGIN' | translate}} Serveur - Login + + Identité Home @@ -54,7 +54,7 @@ {{env.host}} - {{env.login}} + {{env.identity.name}} {{env.homePath}} diff --git a/src/app/manage-environments/manage-environments.component.ts b/src/app/manage-environments/manage-environments.component.ts index 4054a2bfc..9f02e314b 100644 --- a/src/app/manage-environments/manage-environments.component.ts +++ b/src/app/manage-environments/manage-environments.component.ts @@ -7,7 +7,7 @@ import {Constants} from '../shared/Constants'; import {DataTableDirective} from 'angular-datatables'; import {Subject} from 'rxjs'; import {ToastService} from '../core/services/toast.service'; -import {TranslateService} from "@ngx-translate/core"; +import {TranslateService} from '@ngx-translate/core'; import LanguageSettings = DataTables.LanguageSettings; @Component({ @@ -38,7 +38,7 @@ export class ManageEnvironmentsComponent implements AfterViewInit, OnDestroy, On this.columns.push({data: 'id', name: 'id', visible: true}); this.columns.push({data: 'name', name: 'Nom', visible: true}); this.columns.push({data: 'host', name: 'Serveur', visible: true}); - this.columns.push({data: 'login', name: 'Login', visible: true}); + this.columns.push({data: 'identity', name: 'Identity', visible: true}); this.columns.push({data: 'homePath', name: 'Home', visible: true}); this.columns.push({data: 'prefix', name: 'Préfix', visible: true}); this.columns.push({ data: '', name: 'Action', orderable: false, visible: true}); diff --git a/src/app/manage-environments/modal-environment/modal-environment.component.html b/src/app/manage-environments/modal-environment/modal-environment.component.html index 60934be31..de448c9e1 100644 --- a/src/app/manage-environments/modal-environment/modal-environment.component.html +++ b/src/app/manage-environments/modal-environment/modal-environment.component.html @@ -31,19 +31,6 @@ -
- -
- -
-
Login requis
-
-
-
@@ -70,6 +57,18 @@
+
+ +
+ +
+
Identité requise
+
+
+
diff --git a/src/app/manage-environments/modal-environment/modal-environment.component.ts b/src/app/manage-environments/modal-environment/modal-environment.component.ts index e5396f981..6fdab8765 100644 --- a/src/app/manage-environments/modal-environment/modal-environment.component.ts +++ b/src/app/manage-environments/modal-environment/modal-environment.component.ts @@ -2,79 +2,109 @@ import {Component, OnInit} from '@angular/core'; import {NgbActiveModal} from '@ng-bootstrap/ng-bootstrap'; import {Application, Environment, Norme, EnvironmentsService, NormsService} from '../../core'; import {Pageable} from '../../core/models/pageable.model'; +import {Identity} from '../../core/models/identity.model'; +import {IdentitiesService} from '../../core/services/identities.service'; @Component({ - selector: 'app-modal-environment', - templateUrl: './modal-environment.component.html' + selector: 'app-modal-environment', + templateUrl: './modal-environment.component.html' }) export class ModalEnvironmentComponent implements OnInit { - application: Application; - isUpdate = false; - title = 'Ajouter un environnement'; - action = 'Ajouter'; - normes: Norme[]; - environment: Environment; + application: Application; + isUpdate = false; + title = 'Ajouter un environnement'; + action = 'Ajouter'; + normes: Norme[]; + identities = []; + environment: Environment; - constructor(public activeModal: NgbActiveModal, - private environmentsService: EnvironmentsService, - private normesService: NormsService) { - this.environment = { - id: undefined, - name: undefined, - homePath: undefined, - host: undefined, - login: undefined, - norme: null, - application: this.application, - prefix: undefined, - createdBy: undefined, - createdDate: undefined, - lastModifiedBy: undefined, - lastModifiedDate: undefined - }; - } - - ngOnInit() { - if (this.isUpdate) { - this.title = `Modifier l'environnement ${this.environment.name}`; - this.action = `Modifier`; + constructor(public activeModal: NgbActiveModal, + private environmentsService: EnvironmentsService, + private identitiesService: IdentitiesService, + private normesService: NormsService) { + this.environment = { + id: undefined, + name: undefined, + homePath: undefined, + host: undefined, + norme: null, + application: this.application, + prefix: undefined, + createdBy: undefined, + createdDate: undefined, + lastModifiedBy: undefined, + lastModifiedDate: undefined, + identity: undefined + }; } - this.normesService.getAllName(new Pageable(0, 1000)).subscribe( - normes => { - this.normes = normes.content; + ngOnInit() { if (this.isUpdate) { - for (const norme of this.normes) { - if (norme.id === this.environment.norme.id) { - this.environment.norme = norme; - } - } + this.title = `Modifier l'environnement ${this.environment.name}`; + this.action = `Modifier`; } - } - ); - } - addEnvironment() { - this.environment.application = this.application; + this.normesService.getAllName(new Pageable(0, 1000)).subscribe( + normes => { + this.normes = normes.content; + if (this.isUpdate) { + for (const norme of this.normes) { + if (norme.id === this.environment.norme.id) { + this.environment.norme = norme; + } + } + } + } + ); - if (!this.isUpdate) { - this.environmentsService.addEnvironment(this.environment).subscribe( - fileKind => { - this.activeModal.close(fileKind); - }, - error => { - this.activeModal.dismiss(error); - } - ); - } else { - this.environmentsService.updateEnvironment(this.environment).subscribe( - fileKind => { - this.activeModal.close(fileKind); - }, - error => { - this.activeModal.dismiss(error); + this.identitiesService.getAll(new Pageable(0, 1000)).subscribe( + identities => { + this.identities = this.identities.concat(identities.content); + if (this.isUpdate) { + for (const identity of this.identities) { + if (identity.id === this.environment.identity.id) { + this.environment.identity = identity; + } + } + } + } + ); + + this.identitiesService.getAllByApplication(this.application.id, new Pageable(0, 1000)).subscribe( + identities => { + this.identities = this.identities.concat(identities.content); + if (this.isUpdate) { + for (const identity of this.identities) { + if (identity.id === this.environment.identity.id) { + this.environment.identity = identity; + } + } + } + } + ); + } + + addEnvironment() { + this.environment.application = this.application; + + if (!this.isUpdate) { + this.environmentsService.addEnvironment(this.environment).subscribe( + fileKind => { + this.activeModal.close(fileKind); + }, + error => { + this.activeModal.dismiss(error); + } + ); + } else { + this.environmentsService.updateEnvironment(this.environment).subscribe( + fileKind => { + this.activeModal.close(fileKind); + }, + error => { + this.activeModal.dismiss(error); + } + ); } - ); } - } } diff --git a/src/app/manage-identities/manage-identities-routing.module.ts b/src/app/manage-identities/manage-identities-routing.module.ts new file mode 100644 index 000000000..ae5f3fbeb --- /dev/null +++ b/src/app/manage-identities/manage-identities-routing.module.ts @@ -0,0 +1,19 @@ +import {NgModule} from '@angular/core'; +import {RouterModule, Routes} from '@angular/router'; +import {AuthGuard} from '../core'; +import {ManageIdentitiesComponent} from './manage-identities.component'; + +const routes: Routes = [ + { + path: '', + component: ManageIdentitiesComponent, + canActivate: [AuthGuard] + } +]; + +@NgModule({ + imports: [RouterModule.forChild(routes)], + exports: [RouterModule] +}) +export class ManageIdentitiesRoutingModule { +} diff --git a/src/app/manage-identities/manage-identities.component.html b/src/app/manage-identities/manage-identities.component.html new file mode 100644 index 000000000..c2ad17fff --- /dev/null +++ b/src/app/manage-identities/manage-identities.component.html @@ -0,0 +1,49 @@ + + + + + {{'IDENTITY.NEW' | translate}} + + + + + + +
+
+ + + + + + + + + + + + + + + + + +
{{'IDENTITY.ID' | translate}} + {{'IDENTITY.NAME' | translate}} + + {{'IDENTITY.LOGIN' | translate}} + +
+ {{identity.id}} + + {{identity.name}} + + {{identity.login}} + + {{'IDENTITY.EDIT' | translate}} + {{'IDENTITY.DELETE' | translate}} +
+
+
diff --git a/src/app/manage-identities/manage-identities.component.ts b/src/app/manage-identities/manage-identities.component.ts new file mode 100644 index 000000000..6335dcdee --- /dev/null +++ b/src/app/manage-identities/manage-identities.component.ts @@ -0,0 +1,164 @@ +import {AfterViewInit, Component, OnDestroy, OnInit, ViewChild} from '@angular/core'; +import {NgbModal} from '@ng-bootstrap/ng-bootstrap'; +import {Constants} from '../shared/Constants'; +import {Subject} from 'rxjs'; +import {ToastService} from '../core/services/toast.service'; +import {TranslateService} from '@ngx-translate/core'; +import {DataTableDirective} from 'angular-datatables'; +import LanguageSettings = DataTables.LanguageSettings; +import {Identity} from '../core/models/identity.model'; +import {IdentitiesService} from '../core/services/identities.service'; +import {ModalIdentityComponent} from './modal-identity/modal-identity.component'; +import {ModalIdentityDeletionComponent} from './modal-identity-deletion/modal-identity-deletion.component'; +import {Application, ApplicationsService} from '../core'; + +@Component({ + selector: 'app-manage-identities', + templateUrl: './manage-identities.component.html' +}) +export class ManageIdentitiesComponent implements AfterViewInit, OnDestroy, OnInit { + @ViewChild(DataTableDirective, {static: true}) + dtElement: DataTableDirective; + dtTrigger: Subject = new Subject(); + dtOptions: DataTables.Settings = {}; + + identities: Identity[]; + columns = []; + + applicationSelected: Application; + + constructor(private modalService: NgbModal, + private constants: Constants, + private toastService: ToastService, + private identitiesService: IdentitiesService, + private applicationsService: ApplicationsService, + private translateService: TranslateService) { + this.columns.push({data: 'id', name: 'id', visible: true}); + this.columns.push({data: 'name', name: 'nom', visible: true}); + this.columns.push({data: 'login', name: 'login', visible: true}); + this.columns.push({data: '', name: 'actions', visible: true, orderable: false}); + + } + + applicationChanged(application: Application) { + this.applicationSelected = application; + this.applicationsService.getAllModerable().subscribe( + apps => { + for (const app of apps.content) { + if (app.id === this.applicationSelected.id) { + this.refreshIdentities(); + } + } + } + ); + } + + ngOnInit() { + this.dtOptions = { + language: this.constants.datatable[this.translateService.currentLang] as LanguageSettings, + stateSave: true, + stateSaveParams(settings, data: any) { + data.search.search = ''; + }, + order: [[1, 'asc']], + pagingType: 'full_numbers', + pageLength: this.constants.numberByPage, + serverSide: true, + processing: false, + ajax: (dataTablesParameters: any, callback) => { + if (!this.applicationSelected){ + this.identities = []; + return; + } + this.identitiesService + .getAllByApplication(this.applicationSelected.id, { + page: dataTablesParameters.start / dataTablesParameters.length, + size: dataTablesParameters.length, + sort: dataTablesParameters.columns[dataTablesParameters.order[0].column].data + ',' + dataTablesParameters.order[0].dir, + name: dataTablesParameters.search.value + } + ) + .subscribe(resp => { + this.identities = resp.content; + callback({ + recordsTotal: resp.totalElements, + recordsFiltered: resp.totalElements, + data: [] + }); + }); + }, + columns: this.columns + }; + this.dtTrigger.next(); + } + + ngAfterViewInit(): void { + this.dtTrigger.next(); + } + + ngOnDestroy(): void { + this.dtTrigger.unsubscribe(); + } + + + refreshIdentities() { + this.dtElement.dtInstance.then((dtInstance: DataTables.Api) => { + dtInstance.destroy(); + this.dtTrigger.next(); + }); + } + + onClickAddIdentity() { + const modalRef = this.modalService.open(ModalIdentityComponent); + modalRef.result.then(() => { + this.toastService.showSuccess(`La norme a bien été ajoutée`); + this.refreshIdentities(); + }, (reason) => { + if (reason.message !== undefined) { + this.toastService.showError( `Une erreur est survenue lors de l'ajout de la norme : ${reason.message}`); + } + }); + modalRef.componentInstance.isUpdate = false; + modalRef.componentInstance.applicationSelected = this.applicationSelected; + } + + editIdentity(identity: Identity) { + const modalRef = this.modalService.open(ModalIdentityComponent); + modalRef.result.then(() => { + this.toastService.showSuccess(`La norme a bien été modifiée`); + this.refreshIdentities(); + }, (reason) => { + if (reason.message !== undefined) { + this.toastService.showError( `Une erreur est survenue lors de la modification de la norme : ${reason.message}`); + } + }); + this.identitiesService.getIdentity(identity.id).subscribe(value => modalRef.componentInstance.identity = value); + modalRef.componentInstance.isUpdate = true; + modalRef.componentInstance.applicationSelected = this.applicationSelected; + } + + deleteIdentity(identity: Identity) { + const modalRef = this.modalService.open(ModalIdentityDeletionComponent); + modalRef.result.then(() => { + this.identitiesService.deleteIdentity(identity.id).subscribe( + () => { + this.toastService.showSuccess(`La norme a été supprimée`); + this.refreshIdentities(); + }, + reason => { + this.toastService.showError( `Une erreur est survenue lors de la suppression de la norme : ${reason.detail}`); + } + ); + }); + modalRef.componentInstance.identity = identity; + } + + onResizeTable(event) { + if (event.oldWidth === undefined || event.newWidth === event.oldWidth) { + return; + } + this.refreshIdentities(); + } +} + + diff --git a/src/app/manage-identities/manage-identities.module.ts b/src/app/manage-identities/manage-identities.module.ts new file mode 100644 index 000000000..296f5d189 --- /dev/null +++ b/src/app/manage-identities/manage-identities.module.ts @@ -0,0 +1,26 @@ +import {NgModule} from '@angular/core'; +import {ManageIdentitiesComponent} from './manage-identities.component'; +import {ManageIdentitiesRoutingModule} from './manage-identities-routing.module'; +import {SharedModule} from '../shared'; +import {ModalIdentityComponent} from './modal-identity/modal-identity.component'; +import {ModalIdentityDeletionComponent} from './modal-identity-deletion/modal-identity-deletion.component'; +import {NgbPaginationModule} from '@ng-bootstrap/ng-bootstrap'; +import {DataTablesModule} from 'angular-datatables'; +import {AngularResizedEventModule} from 'angular-resize-event'; + +@NgModule({ + declarations: [ManageIdentitiesComponent, ModalIdentityComponent, ModalIdentityDeletionComponent], + imports: [ + ManageIdentitiesRoutingModule, + SharedModule, + NgbPaginationModule, + DataTablesModule, + AngularResizedEventModule + ], + entryComponents: [ + ModalIdentityComponent, + ModalIdentityDeletionComponent + ] +}) +export class ManageIdentitiesModule { +} diff --git a/src/app/manage-identities/modal-identity-deletion/modal-identity-deletion.component.html b/src/app/manage-identities/modal-identity-deletion/modal-identity-deletion.component.html new file mode 100644 index 000000000..a41f28d5f --- /dev/null +++ b/src/app/manage-identities/modal-identity-deletion/modal-identity-deletion.component.html @@ -0,0 +1,13 @@ + + + diff --git a/src/app/manage-identities/modal-identity-deletion/modal-identity-deletion.component.ts b/src/app/manage-identities/modal-identity-deletion/modal-identity-deletion.component.ts new file mode 100644 index 000000000..397a36bbc --- /dev/null +++ b/src/app/manage-identities/modal-identity-deletion/modal-identity-deletion.component.ts @@ -0,0 +1,14 @@ +import {Component} from '@angular/core'; +import {NgbActiveModal} from '@ng-bootstrap/ng-bootstrap'; +import {Identity} from '../../core/models/identity.model'; + +@Component({ + selector: 'app-modal-identity-deletion', + templateUrl: './modal-identity-deletion.component.html' +}) +export class ModalIdentityDeletionComponent { + identity: Identity; + + constructor(public activeModal: NgbActiveModal) { + } +} diff --git a/src/app/manage-identities/modal-identity/modal-identity.component.html b/src/app/manage-identities/modal-identity/modal-identity.component.html new file mode 100644 index 000000000..9be410427 --- /dev/null +++ b/src/app/manage-identities/modal-identity/modal-identity.component.html @@ -0,0 +1,74 @@ + + + + + diff --git a/src/app/manage-identities/modal-identity/modal-identity.component.ts b/src/app/manage-identities/modal-identity/modal-identity.component.ts new file mode 100644 index 000000000..f9bf68a76 --- /dev/null +++ b/src/app/manage-identities/modal-identity/modal-identity.component.ts @@ -0,0 +1,76 @@ +import {Component, OnInit} from '@angular/core'; +import {NgbActiveModal} from '@ng-bootstrap/ng-bootstrap'; +import {IdentitiesService} from '../../core/services/identities.service'; +import {Identity} from '../../core/models/identity.model'; +import {Application} from '../../core'; + +@Component({ + selector: 'app-modal-identity', + templateUrl: './modal-identity.component.html' +}) +export class ModalIdentityComponent implements OnInit { + isUpdate = false; + title = 'Ajouter une identié'; + action = 'Ajouter'; + applicationSelected: Application; + identity: Identity = { + id: undefined, + name: undefined, + login: undefined, + passphrase: undefined, + password: undefined, + privatekey: undefined, + privatekeyPath: undefined, + createdBy: undefined, + createdDate: undefined, + lastModifiedBy: undefined, + lastModifiedDate: undefined, + availableApplication: undefined + }; + + constructor(public activeModal: NgbActiveModal, + private identitiesService: IdentitiesService) { + } + + ngOnInit() { + if (this.isUpdate) { + this.title = `Modifier l'identité ${this.identity.name}`; + this.action = `Modifier`; + } + } + + addIdentity() { + this.identity.availableApplication = this.applicationSelected.id; + if(this.identity.passphrase === '') { + this.identity.passphrase = undefined; + } + if(this.identity.privatekey === '') { + this.identity.privatekey = undefined; + } + if(this.identity.privatekeyPath === '') { + this.identity.privatekeyPath = undefined; + } + if(this.identity.password === '') { + this.identity.password = undefined; + } + if (!this.isUpdate) { + this.identitiesService.addIdentity(this.identity).subscribe( + () => { + this.activeModal.close(); + }, + error => { + this.activeModal.dismiss(error); + } + ); + } else { + this.identitiesService.updateIdentity(this.identity).subscribe( + identity => { + this.activeModal.close(identity); + }, + error => { + this.activeModal.dismiss(error); + } + ); + } + } +} diff --git a/src/app/shared/layout/aside/aside.component.html b/src/app/shared/layout/aside/aside.component.html index 438ceddd2..42236708c 100644 --- a/src/app/shared/layout/aside/aside.component.html +++ b/src/app/shared/layout/aside/aside.component.html @@ -65,8 +65,12 @@ + @@ -88,7 +92,7 @@ - diff --git a/src/assets/i18n/en.json b/src/assets/i18n/en.json index c0b6ad425..83974a3bf 100644 --- a/src/assets/i18n/en.json +++ b/src/assets/i18n/en.json @@ -46,7 +46,8 @@ "FOLDERS": "Folders", "NAMING": "Naming", "ENVIRONMENTS": "Manage Environments", - "ACCESS-CONTROL": "Access Control" + "ACCESS-CONTROL": "Access Control", + "IDENTITIES": "Identities" }, "ADMINISTRATION": { "TITLE": "Administration", diff --git a/src/assets/i18n/fr.json b/src/assets/i18n/fr.json index 5adf6ebf2..24f3f3a72 100644 --- a/src/assets/i18n/fr.json +++ b/src/assets/i18n/fr.json @@ -46,7 +46,8 @@ "FOLDERS": "Répertoires", "NAMING": "Nommages", "ENVIRONMENTS": "Environnements", - "ACCESS-CONTROL": "Contrôle d'accès" + "ACCESS-CONTROL": "Contrôle d'accès", + "IDENTITIES": "Identités" }, "ADMINISTRATION": { "TITLE": "Administration", From 6440170bbdddc94b79a394b1f1ea8ba17dbac57f Mon Sep 17 00:00:00 2001 From: Damien Trouillet Date: Mon, 28 Jun 2021 00:57:27 +0200 Subject: [PATCH 5/7] Add e2e test for identity --- .../integration/ebad/explore-files.spec.js | 5 +- .../ebad/manage-environnement.spec.js | 18 ++-- cypress/support/environnement.commands.js | 10 +- cypress/support/identity-admin.commands.js | 94 +++++++++++++++++++ cypress/support/index.js | 1 + cypress/support/norme.commands.js | 6 ++ .../admin-identities.component.html | 2 +- 7 files changed, 121 insertions(+), 15 deletions(-) create mode 100644 cypress/support/identity-admin.commands.js diff --git a/cypress/integration/ebad/explore-files.spec.js b/cypress/integration/ebad/explore-files.spec.js index b2d16f836..70e5044e8 100644 --- a/cypress/integration/ebad/explore-files.spec.js +++ b/cypress/integration/ebad/explore-files.spec.js @@ -4,6 +4,7 @@ context('Folders', () => { const currentDate = new Date(); const timestamp = currentDate.getTime(); this.normName = 'myNorme-'+timestamp; + this.identityName = 'myIdentity-'+timestamp; this.appName = 'APP0-'+timestamp; }); @@ -17,10 +18,11 @@ context('Folders', () => { it('Add a folder', function () { cy.login({login: this.login.admin.login, password: this.login.admin.password}) .addNorme({name: this.normName, interpreteur: '$1', shellFolder: 'shell', fileDate: 'date.txt'}) + .addIdentityAdmin({name: this.identityName, login: 'testLogin', password: 'myPassword'}) .addApplication({codeAppli: 'AA0', name: this.appName, parmPattern: 'yyyyMMdd', filePattern: 'yyyyMMdd'}) .addUserToApplication({codeAppli: 'AA0', nameAppli: this.appName,firstname: this.login.admin.firstname, login: this.login.admin.login}) .addManagerToApplication({codeAppli: 'AA0', nameAppli: this.appName,firstname: this.login.admin.firstname, login: this.login.admin.login}) - .addEnvironnement({applicationName: this.appName, name:'myEnv', host:'localhost', login:'root', homePath:'/root', prefix:'P', norme: this.normName}) + .addEnvironnement({applicationName: this.appName, name:'myEnv', host:'localhost', login:'root', homePath:'/root', prefix:'P', norme: this.normName, identity: this.identityName}) .addFolder({appliName: this.appName, envName: 'myEnv', directoryName: 'myFolder', path: 'myPath'}); cy.get('.toast-body').should('contains.text', 'Le répertoire myFolder a bien été ajouté'); }); @@ -34,6 +36,7 @@ context('Folders', () => { cy.login({login: this.login.admin.login, password: this.login.admin.password}) .deleteFolder({appliName: this.appName, envName: 'myEnv', directoryName: 'myFolder'}) .deleteApplication({codeAppli: 'AA0', name: this.appName}) + .deleteIdentityAdmin({name: this.identityName}) .deleteNorme({name: this.normName}); }); }); diff --git a/cypress/integration/ebad/manage-environnement.spec.js b/cypress/integration/ebad/manage-environnement.spec.js index 22f3d687d..1fa4d7a8a 100644 --- a/cypress/integration/ebad/manage-environnement.spec.js +++ b/cypress/integration/ebad/manage-environnement.spec.js @@ -3,6 +3,7 @@ context('Gestion Environnement', () => { const currentDate = new Date(); const timestamp = currentDate.getTime(); this.norm1Name = 'LinuxEnvCy-'+timestamp; + this.identity1Name = 'Identity-'+timestamp; this.app1Name = 'ApplicationTest1-'+timestamp; this.app2Name = 'ApplicationTest2-'+timestamp; cy.server(); @@ -42,7 +43,8 @@ context('Gestion Environnement', () => { .addApplication({codeAppli: 'EN1', name: this.app1Name, parmPattern: 'yyyyMMdd', filePattern: 'yyyyMMdd'}) .addManagerToApplication({codeAppli: 'EN1', nameAppli: this.app1Name, firstname: this.login.admin.firstname, login: this.login.admin.login}) .addNorme({name: this.norm1Name, interpreteur: '/bin/bash', shellFolder: 'shell/', fileDate: 'date.in'}) - .addEnvironnement({applicationName: this.app1Name, name: 'ProductionCy', host: 'myhost.com', login: 'batch', homePath: '/home/batch', prefix: 'P', norme: this.norm1Name}); + .addIdentityAdmin({name: this.identity1Name, login: 'testLogin', password: 'myPassword'}) + .addEnvironnement({applicationName: this.app1Name, name: 'ProductionCy', host: 'myhost.com', identity: this.identity1Name, homePath: '/home/batch', prefix: 'P', norme: this.norm1Name}); cy.get('.toast-body').should('contains.text', 'L\'environnement ProductionCy a bien été ajouté'); }); @@ -60,8 +62,8 @@ context('Gestion Environnement', () => { }).as('searchEnvironments'); cy.login({login: this.login.admin.login, password: this.login.admin.password}) - .addEnvironnement({applicationName: this.app1Name, name: 'ProductionCy', host: 'myhost.com', login: 'batch', homePath: '/home/batch', prefix: 'P', norme: this.norm1Name}) - .addEnvironnement({applicationName: this.app1Name, name: 'QACy', host: 'myhost-qa.com', login: 'batch', homePath: '/home/batch', prefix: 'Q', norme: this.norm1Name}); + .addEnvironnement({applicationName: this.app1Name, name: 'ProductionCy', host: 'myhost.com', identity: this.identity1Name, homePath: '/home/batch', prefix: 'P', norme: this.norm1Name}) + .addEnvironnement({applicationName: this.app1Name, name: 'QACy', host: 'myhost-qa.com', identity: this.identity1Name, homePath: '/home/batch', prefix: 'Q', norme: this.norm1Name}); cy.visit('http://localhost:4200'); @@ -72,14 +74,14 @@ context('Gestion Environnement', () => { cy.contains('QACy').parent('tr').within(() => { cy.get('td').eq(2).contains('myhost-qa.com') - cy.get('td').eq(3).contains('batch') + cy.get('td').eq(3).contains(this.identity1Name) cy.get('td').eq(4).contains('/home/batch') cy.get('td').eq(5).contains('Q') }); cy.contains('ProductionCy').parent('tr').within(() => { cy.get('td').eq(2).contains('myhost.com') - cy.get('td').eq(3).contains('batch') + cy.get('td').eq(3).contains(this.identity1Name) cy.get('td').eq(4).contains('/home/batch') cy.get('td').eq(5).contains('P') }); @@ -98,14 +100,13 @@ context('Gestion Environnement', () => { }).as('getEnvironments'); cy.login({login: this.login.admin.login, password: this.login.admin.password}) - .addEnvironnement({applicationName: this.app1Name, name: 'Production', host: 'myhost.com', login: 'batch', homePath: '/home/batch', prefix: 'P', norme: this.norm1Name}); + .addEnvironnement({applicationName: this.app1Name, name: 'Production', host: 'myhost.com', identity: this.identity1Name, homePath: '/home/batch', prefix: 'P', norme: this.norm1Name}); cy.updateEnvironnement({ applicationName: this.app1Name, environnementNameToUpdate: 'Production', name: 'QA', host: 'mynewhost.com', - login: 'batch2', homePath: '/home/batch2', prefix: 'Q' }); @@ -122,7 +123,7 @@ context('Gestion Environnement', () => { cy.contains('QA').parent('tr').within(() => { cy.get('td').eq(2).contains('mynewhost.com') - cy.get('td').eq(3).contains('batch2') + cy.get('td').eq(3).contains(this.identity1Name) cy.get('td').eq(4).contains('/home/batch2') cy.get('td').eq(5).contains('Q') }); @@ -131,6 +132,7 @@ context('Gestion Environnement', () => { cy.get('.toast-body').should('contains.text', 'L\'environnement a été supprimé'); cy.deleteApplication({codeAppli: 'EN1', name: this.app1Name}); + cy.deleteIdentityAdmin({name: this.identity1Name}); cy.deleteNorme({name: this.norm1Name}); }); diff --git a/cypress/support/environnement.commands.js b/cypress/support/environnement.commands.js index 43a23bee2..29f9f9476 100644 --- a/cypress/support/environnement.commands.js +++ b/cypress/support/environnement.commands.js @@ -1,5 +1,5 @@ /////////// ENVIRONNEMENT /////////////// -Cypress.Commands.add("addEnvironnement", ({applicationName, name, host, login, homePath, prefix, norme}) => { +Cypress.Commands.add("addEnvironnement", ({applicationName, name, host, identity, homePath, prefix, norme}) => { cy.server(); cy.route({ method: 'PUT', @@ -12,7 +12,7 @@ Cypress.Commands.add("addEnvironnement", ({applicationName, name, host, login, h cy.get('#addEnvAction').click(); cy.get('#name').type(name); cy.get('#host').type(host); - cy.get('#login').type(login); + cy.get('#identity').select(identity); cy.get('#homePath').type(homePath); cy.get('#prefix').type(prefix); cy.get('#norme').select(norme); @@ -57,7 +57,7 @@ Cypress.Commands.add("deleteEnvironnement", ({applicationName, environnementName Cypress.Commands.add("updateEnvironnement", ({ - applicationName, environnementNameToUpdate, name, host, login, homePath, prefix, norme + applicationName, environnementNameToUpdate, name, host, identity, homePath, prefix, norme }) => { cy.server(); cy.route({ @@ -93,8 +93,8 @@ Cypress.Commands.add("updateEnvironnement", ({ if (host) { cy.get('#host').clear().type(host); } - if (login) { - cy.get("#login").clear().type(login); + if (identity) { + cy.get("#identity").clear().select(identity); } if (homePath) { cy.get("#homePath").clear().type(homePath); diff --git a/cypress/support/identity-admin.commands.js b/cypress/support/identity-admin.commands.js new file mode 100644 index 000000000..6ad24b1bc --- /dev/null +++ b/cypress/support/identity-admin.commands.js @@ -0,0 +1,94 @@ +/////////// IDENTITY ADMIN/////////////// +Cypress.Commands.add("addIdentityAdmin", ({name, login, password, privatekey, privatekeyPath, passphrase}) => { + cy.server(); + cy.route({ + method: 'PUT', + url: '/ebad/identities' + }).as('saveIdentity'); + cy.get('#administrationMenu').click(); + cy.get('#identityAdminMenu').click(); + cy.get('#addIdentityAction').click(); + cy.get('#name').type(name); + cy.get('#login').type(login); + if (password) { + cy.get("#password").type(password); + } + if (privatekey) { + cy.get("#privatekey").type(privatekey); + } + if (passphrase) { + cy.get("#passphrase").type(passphrase); + } + if (privatekeyPath) { + cy.get("#privatekeyPath").type(privatekeyPath); + } + cy.get('form').submit(); + cy.wait('@saveIdentity'); +}); + +Cypress.Commands.add("deleteIdentityAdmin", ({name}) => { + cy.server(); + cy.route({ + method: 'GET', + url: '/ebad/identities?page=0&size=*&sort=name,asc&name='+name, + }).as('searchIdentity'); + + cy.route({ + method: 'DELETE', + url: '/ebad/identities/**' + }).as('deleteIdentity'); + + cy.get('#administrationMenu').click(); + cy.get('#identityAdminMenu').click(); + cy.get('input[type="search"]').clear(); + cy.get('input[type="search"]').type(name); + cy.wait('@searchIdentity'); + + cy.get('#actionDelete-' + name, { timeout: 10000 }).should('be.visible'); + cy.getSettled('#actionDelete-' + name, { retries: 2, delay: 500 }).click(); + + cy.get('#deleteBtn').click(); + cy.wait('@deleteIdentity'); +}); + +Cypress.Commands.add("updateIdentityAdmin", ({nameToUpdate, name, login, password, privatekey, privatekeyPath, passphrase}) => { + cy.server(); + cy.route({ + method: 'GET', + url: '/ebad/identities?page=0&size=*&sort=name,asc&name='+nameToUpdate, + }).as('searchIdentities'); + cy.route({ + method: 'PATCH', + url: '/ebad/identities' + }).as('updateIdentities'); + + cy.get('#administrationMenu').click(); + cy.get('#identityAdminMenu').click(); + cy.get('input[type="search"]').clear(); + cy.get('input[type="search"]').type(nameToUpdate); + cy.wait('@searchIdentities'); + cy.getSettled('#actionEdit-' + nameToUpdate, { retries: 2, delay: 500 }).click(); + + + if (name) { + cy.get('#name').clear().type(name); + } + if (login) { + cy.get('#login').clear().type(login); + } + if (password) { + cy.get("#password").clear().type(password); + } + if (privatekey) { + cy.get("#privatekey").clear().type(privatekey); + } + if (privatekeyPath) { + cy.get("#privatekeyPath").clear().type(privatekeyPath); + } + if (passphrase) { + cy.get("#passphrase").clear().type(passphrase); + } + cy.get('form').submit(); + cy.wait('@updateIdentities'); + +}); diff --git a/cypress/support/index.js b/cypress/support/index.js index 9a87eb567..82d34fc03 100644 --- a/cypress/support/index.js +++ b/cypress/support/index.js @@ -20,6 +20,7 @@ import './norme.commands' import './environnement.commands' import './batch.commands' import './files.commands' +import './identity-admin.commands' // Alternatively you can use CommonJS syntax: // require('./commands') diff --git a/cypress/support/norme.commands.js b/cypress/support/norme.commands.js index f49f78e54..ce58fa8e0 100644 --- a/cypress/support/norme.commands.js +++ b/cypress/support/norme.commands.js @@ -1,5 +1,10 @@ /////////// NORME /////////////// Cypress.Commands.add("addNorme", ({name, interpreteur, shellFolder, fileDate}) => { + cy.server(); + cy.route({ + method: 'PUT', + url: '/ebad/norms' + }).as('addNorm'); cy.get('#administrationMenu').click(); cy.get('#normMenu').click(); cy.get('#addNormAction').click(); @@ -8,6 +13,7 @@ Cypress.Commands.add("addNorme", ({name, interpreteur, shellFolder, fileDate}) = cy.get("#shellFolder").type(shellFolder); cy.get("#fileDate").type(fileDate); cy.get('form').submit(); + cy.wait('@addNorm'); }); Cypress.Commands.add("deleteNorme", ({name}) => { diff --git a/src/app/admin-identities/admin-identities.component.html b/src/app/admin-identities/admin-identities.component.html index 5685b0be1..a203a5d47 100644 --- a/src/app/admin-identities/admin-identities.component.html +++ b/src/app/admin-identities/admin-identities.component.html @@ -10,7 +10,7 @@

- + {{'IDENTITY.NEW' | translate}} From e8b8fd645592abc137496689e4277b94542f254a Mon Sep 17 00:00:00 2001 From: Damien Trouillet Date: Mon, 28 Jun 2021 11:00:08 +0200 Subject: [PATCH 6/7] Add identity e2e --- .../ebad/manage-identity-admin.spec.js | 137 +++++++++++++++ .../ebad/manage-identity-application.spec.js | 159 ++++++++++++++++++ cypress/support/application.commands.js | 12 ++ .../support/identity-environment.commands.js | 112 ++++++++++++ cypress/support/index.js | 1 + .../admin-identities.component.ts | 69 ++++---- src/app/core/services/identities.service.ts | 2 +- .../manage-identities.component.html | 4 +- .../manage-identities.component.ts | 77 +++++---- .../modal-identity.component.html | 2 +- src/assets/i18n/en.json | 6 +- src/assets/i18n/fr.json | 6 +- 12 files changed, 508 insertions(+), 79 deletions(-) create mode 100644 cypress/integration/ebad/manage-identity-admin.spec.js create mode 100644 cypress/integration/ebad/manage-identity-application.spec.js create mode 100644 cypress/support/identity-environment.commands.js diff --git a/cypress/integration/ebad/manage-identity-admin.spec.js b/cypress/integration/ebad/manage-identity-admin.spec.js new file mode 100644 index 000000000..2e0a8881d --- /dev/null +++ b/cypress/integration/ebad/manage-identity-admin.spec.js @@ -0,0 +1,137 @@ +context('Identities', () => { + before(function () { + const currentDate = new Date(); + const timestamp = currentDate.getTime(); + this.identity1Name = 'LinuxEnvCy-' + timestamp; + this.identity2Name = 'TestCyUnix-' + timestamp; + this.identity3Name = 'TestCyWindows-' + timestamp; + this.identity4Name = 'TestUpCyLinux-' + timestamp; + this.identity5Name = 'TestUpCyLinuxNew-' + timestamp; + cy.server(); + }); + + beforeEach(function () { + cy.visit('http://localhost:4200', { + onBeforeLoad(win) { // solution is here + Object.defineProperty(win.navigator, 'languages', { + value: ['en-US'], + }); + } + }); + cy.fixture('login.json').then((login) => { + this.login = login; + }); + }); + + it('Ajouter une identities', function () { + cy.login({login: this.login.admin.login, password: this.login.admin.password}) + .addIdentityAdmin({name: this.identity1Name, login: 'testLogin', password: 'myPassword'}) + cy.get('.toast-body').should('contains.text', 'Identity is added with success'); + }); + + it('Supprimer une identities', function () { + cy.login({login: this.login.admin.login, password: this.login.admin.password}) + .deleteIdentityAdmin({name: this.identity1Name}); + cy.get('.toast-body').should('contains.text', 'Identity is deleted with success'); + }); + + it('Lister les identités', function () { + cy.server(); + cy.route({ + method: 'GET', + url: '/ebad/identities?page=0&size=*&sort=name,asc&name=TestCy', + }).as('searchIdentitiesTest'); + + cy.login({login: this.login.admin.login, password: this.login.admin.password}) + .addIdentityAdmin({ + name: this.identity2Name, + login: 'testLogin2', password: 'myPassword' + }) + .addIdentityAdmin({ + name: this.identity3Name, + login: 'testLogin3', password: 'myPassword' + }); + + cy.visit('http://localhost:4200', { + onBeforeLoad(win) { // solution is here + Object.defineProperty(win.navigator, 'languages', { + value: ['en-US'], + }); + } + }); + cy.get('#administrationMenu').click(); + cy.get('#identityAdminMenu').click(); + cy.get('input[type="search"]').type('TestCy'); + cy.wait('@searchIdentitiesTest'); + + cy.contains(this.identity2Name).parent('tr').within(() => { + cy.get('td').eq(1).contains(this.identity2Name) + cy.get('td').eq(2).contains('testLogin2') + }); + + cy.contains(this.identity3Name).parent('tr').within(() => { + cy.get('td').eq(1).contains(this.identity3Name) + cy.get('td').eq(2).contains('testLogin3') + }); + + cy.deleteIdentityAdmin({name: this.identity2Name}); + cy.deleteIdentityAdmin({name: this.identity3Name}); + }); + + it('Modifier une identities', function () { + cy.server(); + cy.route({ + method: 'GET', + url: '/ebad/identities?page=0&size=*&sort=name,asc&name=' + this.identity5Name, + }).as('searchIdentitiesTest'); + + cy.login({login: this.login.admin.login, password: this.login.admin.password}) + .addIdentityAdmin({ + name: this.identity4Name, + login: 'testLogin4', password: 'myPassword' + }); + + cy.visit('http://localhost:4200', { + onBeforeLoad(win) { // solution is here + Object.defineProperty(win.navigator, 'languages', { + value: ['en-US'], + }); + } + }); + cy.get('#administrationMenu').click(); + cy.get('#identityAdminMenu').click(); + + cy.updateIdentityAdmin({ + nameToUpdate: this.identity4Name, + name: this.identity5Name, + login: 'testLogin5', password: 'myPassword' + + }); + + cy.get('.toast-body').should('contains.text', 'Identity is updated with success'); + + cy.visit('http://localhost:4200', { + onBeforeLoad(win) { // solution is here + Object.defineProperty(win.navigator, 'languages', { + value: ['en-US'], + }); + } + }); + cy.get('#administrationMenu').click(); + cy.get('#identityAdminMenu').click(); + + cy.get('input[type="search"]').clear(); + cy.get('input[type="search"]').type(this.identity5Name); + + cy.wait('@searchIdentitiesTest'); + + cy.contains(this.identity5Name).parent('tr').within(() => { + cy.get('td').eq(1).contains(this.identity5Name) + cy.get('td').eq(2).contains('testLogin5') + }); + + cy.deleteIdentityAdmin({name: this.identity5Name}); + cy.get('.toast-body').should('contains.text', 'Identity is deleted with success'); + + }); +}); diff --git a/cypress/integration/ebad/manage-identity-application.spec.js b/cypress/integration/ebad/manage-identity-application.spec.js new file mode 100644 index 000000000..18af75f23 --- /dev/null +++ b/cypress/integration/ebad/manage-identity-application.spec.js @@ -0,0 +1,159 @@ +context('Identities Management', () => { + before(function () { + const currentDate = new Date(); + const timestamp = currentDate.getTime(); + this.identity1Name = 'LinuxEnvCy-' + timestamp; + this.identity2Name = 'TestCyUnix-' + timestamp; + this.identity3Name = 'TestCyWindows-' + timestamp; + this.identity4Name = 'TestUpCyLinux-' + timestamp; + this.identity5Name = 'TestUpCyLinuxNew-' + timestamp; + this.app1Name = 'myApp-'+timestamp; + cy.server(); + }); + + beforeEach(function () { + cy.visit('http://localhost:4200', { + onBeforeLoad(win) { // solution is here + Object.defineProperty(win.navigator, 'languages', { + value: ['en-US'], + }); + } + }); + cy.fixture('login.json').then((login) => { + this.login = login; + }); + }); + + it('Ajouter une identité', function () { + cy.login({login: this.login.admin.login, password: this.login.admin.password}) + .addApplication({codeAppli: 'EN1', name: this.app1Name, parmPattern: 'yyyyMMdd', filePattern: 'yyyyMMdd'}) + .addManagerToApplication({codeAppli: 'EN1', nameAppli: this.app1Name, firstname: this.login.admin.firstname, login: this.login.admin.login}) + .addIdentityManage({applicationName: this.app1Name, name: this.identity1Name, login: 'testLogin', password: 'myPassword'}) + cy.get('.toast-body').should('contains.text', 'Identity is added with success'); + }); + + it('Supprimer une identities', function () { + cy.login({login: this.login.admin.login, password: this.login.admin.password}) + .deleteIdentityManage({applicationName: this.app1Name, name: this.identity1Name}); + cy.get('.toast-body').should('contains.text', 'Identity is deleted with success'); + }); + + it('Lister les identités', function () { + cy.server(); + cy.route({ + method: 'GET', + url: '/ebad/identities?applicationId=*&page=0&size=*&sort=name,asc&name=TestCy', + }).as('searchIdentitiesTest'); + + cy.login({login: this.login.admin.login, password: this.login.admin.password}) + .addIdentityManage({ + applicationName: this.app1Name, + name: this.identity2Name, + login: 'testLogin2', password: 'myPassword' + }) + .addIdentityManage({ + applicationName: this.app1Name, + name: this.identity3Name, + login: 'testLogin3', password: 'myPassword' + }); + + cy.visit('http://localhost:4200', { + onBeforeLoad(win) { // solution is here + Object.defineProperty(win.navigator, 'languages', { + value: ['en-US'], + }); + } + }); + cy.get('#managementMenu').click(); + cy.get('#identityManageMenu').click(); + + cy.route({ + method: 'GET', + url: '/ebad/identities?applicationId=*&page=0&size=*&sort=name,asc&name=' + }).as('selectApplication1'); + cy.get("#selectApplication").select(this.app1Name); + cy.wait('@selectApplication1'); + cy.getSettled('input[type="search"]', { retries: 2, delay: 500 }).type('TestCy'); + cy.wait('@searchIdentitiesTest'); + + cy.contains(this.identity2Name).parent('tr').within(() => { + cy.get('td').eq(1).contains(this.identity2Name) + cy.get('td').eq(2).contains('testLogin2') + }); + + cy.contains(this.identity3Name).parent('tr').within(() => { + cy.get('td').eq(1).contains(this.identity3Name) + cy.get('td').eq(2).contains('testLogin3') + }); + + cy.deleteIdentityManage({applicationName: this.app1Name, name: this.identity2Name}); + cy.deleteIdentityManage({applicationName: this.app1Name, name: this.identity3Name}); + }); + + it('Modifier une identities', function () { + cy.server(); + cy.route({ + method: 'GET', + url: '/ebad/identities?applicationId=*&page=0&size=*&sort=name,asc&name=' + this.identity5Name, + }).as('searchIdentitiesTest'); + + cy.login({login: this.login.admin.login, password: this.login.admin.password}) + .addIdentityManage({ + applicationName: this.app1Name, + name: this.identity4Name, + login: 'testLogin4', password: 'myPassword' + }); + + cy.visit('http://localhost:4200', { + onBeforeLoad(win) { // solution is here + Object.defineProperty(win.navigator, 'languages', { + value: ['en-US'], + }); + } + }); + cy.get('#administrationMenu').click(); + cy.get('#identityAdminMenu').click(); + + cy.updateIdentityManage({ + applicationName: this.app1Name, + nameToUpdate: this.identity4Name, + name: this.identity5Name, + login: 'testLogin5', password: 'myPassword' + + }); + + cy.get('.toast-body').should('contains.text', 'Identity is updated with success'); + + cy.visit('http://localhost:4200', { + onBeforeLoad(win) { // solution is here + Object.defineProperty(win.navigator, 'languages', { + value: ['en-US'], + }); + } + }); + cy.get('#managementMenu').click(); + cy.get('#identityManageMenu').click(); + + cy.route({ + method: 'GET', + url: '/ebad/identities?applicationId=*&page=0&size=*&sort=name,asc&name=' + }).as('selectApplication2'); + cy.get("#selectApplication").select(this.app1Name); + cy.wait('@selectApplication2'); + + cy.getSettled('input[type="search"]', { retries: 2, delay: 500 }).clear(); + cy.getSettled('input[type="search"]', { retries: 2, delay: 500 }).type(this.identity5Name); + + cy.wait('@searchIdentitiesTest'); + + cy.contains(this.identity5Name).parent('tr').within(() => { + cy.get('td').eq(1).contains(this.identity5Name) + cy.get('td').eq(2).contains('testLogin5') + }); + + cy.deleteIdentityManage({applicationName: this.app1Name, name: this.identity5Name}); + cy.get('.toast-body').should('contains.text', 'Identity is deleted with success'); + cy.deleteApplication({codeAppli: 'EN1', name: this.app1Name}); + + }); +}); diff --git a/cypress/support/application.commands.js b/cypress/support/application.commands.js index e0e3645cc..31f548fba 100644 --- a/cypress/support/application.commands.js +++ b/cypress/support/application.commands.js @@ -89,6 +89,11 @@ Cypress.Commands.add("addUserToApplication", ({codeAppli, nameAppli,firstname, l url: '/ebad/users?page=0&size=20&login='+firstname, }).as('searchUser'); + cy.route({ + method: 'PATCH', + url: '/ebad/users/application' + }).as('userApplication'); + cy.get('#administrationMenu').click(); cy.get('#applicationMenu').click(); cy.get('input[type="search"]').clear(); @@ -102,6 +107,7 @@ Cypress.Commands.add("addUserToApplication", ({codeAppli, nameAppli,firstname, l cy.wait('@searchUser'); cy.get('button').contains(login).click(); cy.get('#addUserBtn').click(); + cy.wait('@userApplication'); cy.get('#closeBtn').click(); }); @@ -117,6 +123,11 @@ Cypress.Commands.add("addManagerToApplication", ({codeAppli, nameAppli, firstnam url: '/ebad/users?page=0&size=*&login='+firstname, }).as('searchUser'); + cy.route({ + method: 'PATCH', + url: '/ebad/users/application' + }).as('userApplication'); + cy.get('#administrationMenu').click(); cy.get('#applicationMenu').click(); cy.get('input[type="search"]').clear(); @@ -130,5 +141,6 @@ Cypress.Commands.add("addManagerToApplication", ({codeAppli, nameAppli, firstnam cy.wait('@searchUser'); cy.get('button').contains(login).click(); cy.get('#addUserBtn').click(); + cy.wait('@userApplication'); cy.get('#closeBtn').click(); }); diff --git a/cypress/support/identity-environment.commands.js b/cypress/support/identity-environment.commands.js new file mode 100644 index 000000000..5bacfbcd0 --- /dev/null +++ b/cypress/support/identity-environment.commands.js @@ -0,0 +1,112 @@ +/////////// IDENTITY ADMIN/////////////// +Cypress.Commands.add("addIdentityManage", ({applicationName, name, login, password, privatekey, privatekeyPath, passphrase}) => { + cy.server(); + cy.route({ + method: 'PUT', + url: '/ebad/identities' + }).as('saveIdentity'); + cy.route({ + method: 'GET', + url: '/ebad/identities?applicationId=*&page=0&size=*&sort=name,asc&name=' + }).as('selectApplication'); + cy.get('#managementMenu').click(); + cy.get('#identityManageMenu').click(); + cy.get("#selectApplication").select(applicationName); + cy.wait('@selectApplication', {timeout: 10000}); + cy.get('#addIdentityAction').click(); + cy.get('#name').type(name); + cy.get('#login').type(login); + if (password) { + cy.get("#password").type(password); + } + if (privatekey) { + cy.get("#privatekey").type(privatekey); + } + if (passphrase) { + cy.get("#passphrase").type(passphrase); + } + if (privatekeyPath) { + cy.get("#privatekeyPath").type(privatekeyPath); + } + cy.get('#addIdentityForm').submit(); + cy.wait('@saveIdentity'); +}); + +Cypress.Commands.add("deleteIdentityManage", ({applicationName, name}) => { + cy.server(); + cy.route({ + method: 'GET', + url: '/ebad/identities?applicationId=*&page=0&size=*&sort=name,asc&name='+name, + }).as('searchIdentity'); + cy.route({ + method: 'GET', + url: '/ebad/identities?applicationId=*&page=0&size=*&sort=name,asc&name=' + }).as('selectApplication'); + cy.route({ + method: 'DELETE', + url: '/ebad/identities/**' + }).as('deleteIdentity'); + + cy.get('#managementMenu').click(); + cy.get('#identityManageMenu').click(); + cy.get("#selectApplication").select(applicationName); + cy.wait('@selectApplication'); + + cy.getSettled('input[type="search"]', { retries: 2, delay: 500 }).clear(); + cy.getSettled('input[type="search"]', { retries: 2, delay: 500 }).type(name); + cy.wait('@searchIdentity'); + + cy.get('#actionDelete-' + name, { timeout: 10000 }).should('be.visible'); + cy.getSettled('#actionDelete-' + name, { retries: 2, delay: 500 }).click(); + + cy.get('#deleteBtn').click(); + cy.wait('@deleteIdentity'); +}); + +Cypress.Commands.add("updateIdentityManage", ({applicationName, nameToUpdate, name, login, password, privatekey, privatekeyPath, passphrase}) => { + cy.server(); + cy.route({ + method: 'GET', + url: '/ebad/identities?applicationId=*&page=0&size=*&sort=name,asc&name='+nameToUpdate, + }).as('searchIdentities'); + cy.route({ + method: 'PATCH', + url: '/ebad/identities' + }).as('updateIdentities'); + cy.route({ + method: 'GET', + url: '/ebad/identities?applicationId=*&page=0&size=*&sort=name,asc&name=' + }).as('selectApplication'); + cy.get('#managementMenu').click(); + cy.get('#identityManageMenu').click(); + cy.get("#selectApplication").select(applicationName); + cy.wait('@selectApplication'); + + cy.getSettled('input[type="search"]', { retries: 2, delay: 500 }).clear(); + cy.getSettled('input[type="search"]', { retries: 2, delay: 500 }).type(nameToUpdate); + cy.wait('@searchIdentities'); + cy.getSettled('#actionEdit-' + nameToUpdate, { retries: 2, delay: 500 }).click(); + + + if (name) { + cy.get('#name').clear().type(name); + } + if (login) { + cy.get('#login').clear().type(login); + } + if (password) { + cy.get("#password").clear().type(password); + } + if (privatekey) { + cy.get("#privatekey").clear().type(privatekey); + } + if (privatekeyPath) { + cy.get("#privatekeyPath").clear().type(privatekeyPath); + } + if (passphrase) { + cy.get("#passphrase").clear().type(passphrase); + } + cy.get('#addIdentityForm').submit(); + cy.wait('@updateIdentities'); + +}); diff --git a/cypress/support/index.js b/cypress/support/index.js index 82d34fc03..b9e911f45 100644 --- a/cypress/support/index.js +++ b/cypress/support/index.js @@ -21,6 +21,7 @@ import './environnement.commands' import './batch.commands' import './files.commands' import './identity-admin.commands' +import './identity-environment.commands' // Alternatively you can use CommonJS syntax: // require('./commands') diff --git a/src/app/admin-identities/admin-identities.component.ts b/src/app/admin-identities/admin-identities.component.ts index 8d37be77d..9cf4d5f74 100644 --- a/src/app/admin-identities/admin-identities.component.ts +++ b/src/app/admin-identities/admin-identities.component.ts @@ -88,46 +88,47 @@ export class AdminIdentitiesComponent implements AfterViewInit, OnDestroy, OnIni } onClickAddIdentity() { - const modalRef = this.modalService.open(ModalIdentityComponent); - modalRef.result.then(() => { - this.toastService.showSuccess(`La norme a bien été ajoutée`); - this.refreshIdentities(); - }, (reason) => { - if (reason.message !== undefined) { - this.toastService.showError( `Une erreur est survenue lors de l'ajout de la norme : ${reason.message}`); - } - }); - modalRef.componentInstance.isUpdate = false; + const modalRef = this.modalService.open(ModalIdentityComponent); + modalRef.result.then(() => { + this.translateService.get('IDENTITY.MSG.ADD_SUCCESS').subscribe((msg) => this.toastService.showSuccess(msg)); + this.refreshIdentities(); + }, (reason) => { + if (reason.message !== undefined) { + this.translateService.get('IDENTITY.MSG.ADD_ERROR', {msg: reason.message}).subscribe((msg) => this.toastService.showError(msg)); + } + }); + modalRef.componentInstance.isUpdate = false; } editIdentity(identity: Identity) { - const modalRef = this.modalService.open(ModalIdentityComponent); - modalRef.result.then(() => { - this.toastService.showSuccess(`La norme a bien été modifiée`); - this.refreshIdentities(); - }, (reason) => { - if (reason.message !== undefined) { - this.toastService.showError( `Une erreur est survenue lors de la modification de la norme : ${reason.message}`); - } - }); - this.identitiesService.getIdentity(identity.id).subscribe(value => modalRef.componentInstance.identity = value); - modalRef.componentInstance.isUpdate = true; + const modalRef = this.modalService.open(ModalIdentityComponent); + modalRef.result.then(() => { + this.translateService.get('IDENTITY.MSG.UPDATE_SUCCESS').subscribe((msg) => this.toastService.showSuccess(msg)); + this.refreshIdentities(); + }, (reason) => { + if (reason.message !== undefined) { + this.translateService.get('IDENTITY.MSG.UPDATE_ERROR', {msg: reason.message}) + .subscribe((msg) => this.toastService.showError(msg)); + } + }); + this.identitiesService.getIdentity(identity.id).subscribe(value => modalRef.componentInstance.identity = value); + modalRef.componentInstance.isUpdate = true; } deleteIdentity(identity: Identity) { - const modalRef = this.modalService.open(ModalIdentityDeletionComponent); - modalRef.result.then(() => { - this.identitiesService.deleteIdentity(identity.id).subscribe( - () => { - this.toastService.showSuccess(`La norme a été supprimée`); - this.refreshIdentities(); - }, - reason => { - this.toastService.showError( `Une erreur est survenue lors de la suppression de la norme : ${reason.detail}`); - } - ); - }); - modalRef.componentInstance.identity = identity; + const modalRef = this.modalService.open(ModalIdentityDeletionComponent); + modalRef.result.then(() => { + this.identitiesService.deleteIdentity(identity.id).subscribe( + () => { + this.translateService.get('IDENTITY.MSG.DELETION_SUCCESS').subscribe((msg) => this.toastService.showSuccess(msg)); + this.refreshIdentities(); + }, + reason => { + this.translateService.get('IDENTITY.MSG.DELETION_ERROR', {msg: reason.message}) + .subscribe((msg) => this.toastService.showError(msg)); } + ); + }); + modalRef.componentInstance.identity = identity; } onResizeTable(event) { diff --git a/src/app/core/services/identities.service.ts b/src/app/core/services/identities.service.ts index 8b5f91096..c4690ec1f 100644 --- a/src/app/core/services/identities.service.ts +++ b/src/app/core/services/identities.service.ts @@ -18,7 +18,7 @@ export class IdentitiesService { } getAllByApplication(applicationId: number, pageable: any = new Pageable(0, 20)): Observable> { - return this.apiService.get(`/identities`, {applicationId, pageable}); + return this.apiService.get(`/identities?applicationId=${applicationId}`, pageable); } addIdentity(identity: Identity): Observable { return this.apiService.put('/identities', identity); diff --git a/src/app/manage-identities/manage-identities.component.html b/src/app/manage-identities/manage-identities.component.html index c2ad17fff..62c82a0d9 100644 --- a/src/app/manage-identities/manage-identities.component.html +++ b/src/app/manage-identities/manage-identities.component.html @@ -1,7 +1,7 @@ - {{'IDENTITY.NEW' | translate}} @@ -13,7 +13,7 @@
- +
diff --git a/src/app/manage-identities/manage-identities.component.ts b/src/app/manage-identities/manage-identities.component.ts index 6335dcdee..ef413de89 100644 --- a/src/app/manage-identities/manage-identities.component.ts +++ b/src/app/manage-identities/manage-identities.component.ts @@ -66,7 +66,7 @@ export class ManageIdentitiesComponent implements AfterViewInit, OnDestroy, OnIn serverSide: true, processing: false, ajax: (dataTablesParameters: any, callback) => { - if (!this.applicationSelected){ + if (!this.applicationSelected) { this.identities = []; return; } @@ -109,48 +109,51 @@ export class ManageIdentitiesComponent implements AfterViewInit, OnDestroy, OnIn } onClickAddIdentity() { - const modalRef = this.modalService.open(ModalIdentityComponent); - modalRef.result.then(() => { - this.toastService.showSuccess(`La norme a bien été ajoutée`); - this.refreshIdentities(); - }, (reason) => { - if (reason.message !== undefined) { - this.toastService.showError( `Une erreur est survenue lors de l'ajout de la norme : ${reason.message}`); - } - }); - modalRef.componentInstance.isUpdate = false; - modalRef.componentInstance.applicationSelected = this.applicationSelected; + const modalRef = this.modalService.open(ModalIdentityComponent); + modalRef.result.then(() => { + this.translateService.get('IDENTITY.MSG.ADD_SUCCESS').subscribe((msg) => this.toastService.showSuccess(msg)); + this.refreshIdentities(); + }, (reason) => { + if (reason.message !== undefined) { + this.translateService.get('IDENTITY.MSG.ADD_ERROR', {msg: reason.message}) + .subscribe((msg) => this.toastService.showError(msg)); + } + }); + modalRef.componentInstance.isUpdate = false; + modalRef.componentInstance.applicationSelected = this.applicationSelected; } editIdentity(identity: Identity) { - const modalRef = this.modalService.open(ModalIdentityComponent); - modalRef.result.then(() => { - this.toastService.showSuccess(`La norme a bien été modifiée`); - this.refreshIdentities(); - }, (reason) => { - if (reason.message !== undefined) { - this.toastService.showError( `Une erreur est survenue lors de la modification de la norme : ${reason.message}`); - } - }); - this.identitiesService.getIdentity(identity.id).subscribe(value => modalRef.componentInstance.identity = value); - modalRef.componentInstance.isUpdate = true; - modalRef.componentInstance.applicationSelected = this.applicationSelected; + const modalRef = this.modalService.open(ModalIdentityComponent); + modalRef.result.then(() => { + this.translateService.get('IDENTITY.MSG.UPDATE_SUCCESS').subscribe((msg) => this.toastService.showSuccess(msg)); + this.refreshIdentities(); + }, (reason) => { + if (reason.message !== undefined) { + this.translateService.get('IDENTITY.MSG.UPDATE_ERROR', {msg: reason.message}) + .subscribe((msg) => this.toastService.showError(msg)); + } + }); + this.identitiesService.getIdentity(identity.id).subscribe(value => modalRef.componentInstance.identity = value); + modalRef.componentInstance.isUpdate = true; + modalRef.componentInstance.applicationSelected = this.applicationSelected; } deleteIdentity(identity: Identity) { - const modalRef = this.modalService.open(ModalIdentityDeletionComponent); - modalRef.result.then(() => { - this.identitiesService.deleteIdentity(identity.id).subscribe( - () => { - this.toastService.showSuccess(`La norme a été supprimée`); - this.refreshIdentities(); - }, - reason => { - this.toastService.showError( `Une erreur est survenue lors de la suppression de la norme : ${reason.detail}`); - } - ); - }); - modalRef.componentInstance.identity = identity; + const modalRef = this.modalService.open(ModalIdentityDeletionComponent); + modalRef.result.then(() => { + this.identitiesService.deleteIdentity(identity.id).subscribe( + () => { + this.translateService.get('IDENTITY.MSG.DELETION_SUCCESS').subscribe((msg) => this.toastService.showSuccess(msg)); + this.refreshIdentities(); + }, + reason => { + this.translateService.get('IDENTITY.MSG.DELETION_ERROR', {msg: reason.message}) + .subscribe((msg) => this.toastService.showError(msg)); + } + ); + }); + modalRef.componentInstance.identity = identity; } onResizeTable(event) { diff --git a/src/app/manage-identities/modal-identity/modal-identity.component.html b/src/app/manage-identities/modal-identity/modal-identity.component.html index 9be410427..cc06e2d6b 100644 --- a/src/app/manage-identities/modal-identity/modal-identity.component.html +++ b/src/app/manage-identities/modal-identity/modal-identity.component.html @@ -1,4 +1,4 @@ - +
{{'IDENTITY.ID' | translate}}