From 54c896cbb9e99dd17a047cbe46b37866eb04678c Mon Sep 17 00:00:00 2001 From: Pavlo Tkach <3469726+ptkach@users.noreply.github.com> Date: Mon, 6 May 2024 14:32:54 -0400 Subject: [PATCH] Add console epp password integration (#2426) --- .../app/navigation/navigation.component.html | 2 +- .../security/eppPasswordEdit.component.ts | 37 +++++++++++++------ .../app/settings/security/security.service.ts | 15 +++++++- .../app/shared/services/backend.service.ts | 17 ++++++++- .../shared/services/globalLoader.service.ts | 2 +- 5 files changed, 57 insertions(+), 16 deletions(-) diff --git a/console-webapp/src/app/navigation/navigation.component.html b/console-webapp/src/app/navigation/navigation.component.html index 561f86705..c157c42f9 100644 --- a/console-webapp/src/app/navigation/navigation.component.html +++ b/console-webapp/src/app/navigation/navigation.component.html @@ -7,7 +7,7 @@ *matTreeNodeDef="let node" matTreeNodeToggle (click)="onClick(node)" - [class.active]="router.url.endsWith(node.path)" + [class.active]="router.url.includes(node.path)" > {{ node.iconName }} diff --git a/console-webapp/src/app/settings/security/eppPasswordEdit.component.ts b/console-webapp/src/app/settings/security/eppPasswordEdit.component.ts index 4fb8dca16..152def7d7 100644 --- a/console-webapp/src/app/settings/security/eppPasswordEdit.component.ts +++ b/console-webapp/src/app/settings/security/eppPasswordEdit.component.ts @@ -12,6 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +import { HttpErrorResponse } from '@angular/common/http'; import { Component } from '@angular/core'; import { AbstractControl, @@ -68,9 +69,12 @@ export default class EppPasswordEditComponent { ) { this.passwordUpdateForm?.get('newPasswordRepeat')?.setErrors(null); } else { - this.passwordUpdateForm - ?.get('newPasswordRepeat') - ?.setErrors({ passwordsDontMatch: control.value }); + // latest angular just won't detect the error without setTimeout + setTimeout(() => { + this.passwordUpdateForm + ?.get('newPasswordRepeat') + ?.setErrors({ passwordsDontMatch: control.value }); + }); } return null; }; @@ -92,15 +96,24 @@ export default class EppPasswordEditComponent { }); save() { - debugger; - // this.securityService.saveEppPassword().subscribe({ - // complete: () => { - // this.goBack(); - // }, - // error: (err: HttpErrorResponse) => { - // this._snackBar.open(err.error); - // }, - // }); + const { oldPassword, newPassword, newPasswordRepeat } = + this.passwordUpdateForm.value; + if (!oldPassword || !newPassword || !newPasswordRepeat) return; + this.securityService + .saveEppPassword({ + registrarId: this.registrarService.registrarId(), + oldPassword, + newPassword, + newPasswordRepeat, + }) + .subscribe({ + complete: () => { + this.goBack(); + }, + error: (err: HttpErrorResponse) => { + this._snackBar.open(err.error); + }, + }); } goBack() { diff --git a/console-webapp/src/app/settings/security/security.service.ts b/console-webapp/src/app/settings/security/security.service.ts index ada53f993..798c33dbf 100644 --- a/console-webapp/src/app/settings/security/security.service.ts +++ b/console-webapp/src/app/settings/security/security.service.ts @@ -22,6 +22,13 @@ import { } from 'src/app/registrar/registrar.service'; import { BackendService } from 'src/app/shared/services/backend.service'; +export interface EppPasswordBackendModel { + registrarId: string; + oldPassword: string; + newPassword: string; + newPasswordRepeat: string; +} + export function apiToUiConverter( securitySettings: SecuritySettingsBackendModel = {} ): SecuritySettings { @@ -68,5 +75,11 @@ export class SecurityService { ); } - saveEppPassword() {} + saveEppPassword(data: EppPasswordBackendModel) { + return this.backend.postEppPasswordUpdate(data).pipe( + switchMap(() => { + return this.registrarService.loadRegistrars(); + }) + ); + } } diff --git a/console-webapp/src/app/shared/services/backend.service.ts b/console-webapp/src/app/shared/services/backend.service.ts index 9729952e1..f128ca7d9 100644 --- a/console-webapp/src/app/shared/services/backend.service.ts +++ b/console-webapp/src/app/shared/services/backend.service.ts @@ -17,12 +17,14 @@ import { Injectable } from '@angular/core'; import { Observable, catchError, of, throwError } from 'rxjs'; import { DomainListResult } from 'src/app/domains/domainList.service'; +import { environment } from 'src/environments/environment'; import { Registrar, SecuritySettingsBackendModel, WhoisRegistrarFields, } from '../../registrar/registrar.service'; import { Contact } from '../../settings/contact/contact.service'; +import { EppPasswordBackendModel } from '../../settings/security/security.service'; import { UserData } from './userData.service'; @Injectable() @@ -35,7 +37,11 @@ export class BackendService { ): Observable { // This is a temporary redirect to the old console untill the new console // is fully released and enabled - if (error.url && window.location.href.indexOf(error.url) < 0) { + if ( + environment.production && + error.url && + window.location.href.indexOf(error.url) < 0 + ) { window.location.href = error.url; } if (error.error instanceof Error) { @@ -139,6 +145,15 @@ export class BackendService { ); } + postEppPasswordUpdate( + data: EppPasswordBackendModel + ): Observable { + return this.http.post( + `/console-api/eppPassword`, + data + ); + } + getUserData(): Observable { return this.http .get('/console-api/userdata') diff --git a/console-webapp/src/app/shared/services/globalLoader.service.ts b/console-webapp/src/app/shared/services/globalLoader.service.ts index ed5354c39..3c38882be 100644 --- a/console-webapp/src/app/shared/services/globalLoader.service.ts +++ b/console-webapp/src/app/shared/services/globalLoader.service.ts @@ -30,7 +30,7 @@ export interface GlobalLoader { providedIn: 'root', }) export class GlobalLoaderService { - private static readonly TIMEOUT_MS = 3000; + private static readonly TIMEOUT_MS = 10000; private loaders = new Map(); public isLoading: boolean = false;