diff --git a/src/app/shared/modal/abstract-base-modal/abstract-base-modal.component.ts b/src/app/shared/modal/abstract-base-modal/abstract-base-modal.component.ts index 6a05109455..77810f2642 100644 --- a/src/app/shared/modal/abstract-base-modal/abstract-base-modal.component.ts +++ b/src/app/shared/modal/abstract-base-modal/abstract-base-modal.component.ts @@ -14,7 +14,6 @@ export abstract class AbstractBaseModalComponent { } async hide(): Promise { - console.log('close modal abstract') this.modalService.hide(this.modalId) //Fix when calling hide and show form within a modal -- if it is called directly after another the new modal won't open @@ -29,8 +28,7 @@ export abstract class AbstractBaseModalComponent { const bsModalRef: BsModalRef = this.modalService.show(modalType, { initialState }) this.bsModalRef = bsModalRef bsModalRef.setClass('modal-lg') - this.modalId = bsModalRef.id - console.log(`new id ${this.modalId}`) + this.modalId = bsModalRef.id return bsModalRef.content.event } diff --git a/src/app/shared/shared_modules/public-key/generate-public-key-modal/generate-public-key-modal.component.html b/src/app/shared/shared_modules/public-key/generate-public-key-modal/generate-public-key-modal.component.html new file mode 100644 index 0000000000..7f3107d7e4 --- /dev/null +++ b/src/app/shared/shared_modules/public-key/generate-public-key-modal/generate-public-key-modal.component.html @@ -0,0 +1,55 @@ + + + + + diff --git a/src/app/shared/shared_modules/public-key/generate-public-key-modal/generate-public-key-modal.component.scss b/src/app/shared/shared_modules/public-key/generate-public-key-modal/generate-public-key-modal.component.scss new file mode 100644 index 0000000000..e69de29bb2 diff --git a/src/app/shared/shared_modules/public-key/generate-public-key-modal/generate-public-key-modal.component.spec.ts b/src/app/shared/shared_modules/public-key/generate-public-key-modal/generate-public-key-modal.component.spec.ts new file mode 100644 index 0000000000..883f9cbe67 --- /dev/null +++ b/src/app/shared/shared_modules/public-key/generate-public-key-modal/generate-public-key-modal.component.spec.ts @@ -0,0 +1,23 @@ +import { ComponentFixture, TestBed } from '@angular/core/testing'; + +import { GeneratePublicKeyModalComponent } from './generate-public-key-modal.component'; + +describe('GeneratePublicKeyModalComponent', () => { + let component: GeneratePublicKeyModalComponent; + let fixture: ComponentFixture; + + beforeEach(async () => { + await TestBed.configureTestingModule({ + imports: [GeneratePublicKeyModalComponent] + }) + .compileComponents(); + + fixture = TestBed.createComponent(GeneratePublicKeyModalComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/src/app/shared/shared_modules/public-key/generate-public-key-modal/generate-public-key-modal.component.ts b/src/app/shared/shared_modules/public-key/generate-public-key-modal/generate-public-key-modal.component.ts new file mode 100644 index 0000000000..f5457773e7 --- /dev/null +++ b/src/app/shared/shared_modules/public-key/generate-public-key-modal/generate-public-key-modal.component.ts @@ -0,0 +1,48 @@ +import { Component, EventEmitter, Injectable, Output } from '@angular/core'; +import { KeyService } from 'app/api-connector/key.service'; +import { AbstractBaseModalComponent } from 'app/shared/modal/abstract-base-modal/abstract-base-modal.component'; +import { BsModalService } from 'ngx-bootstrap/modal'; +import { saveAs } from 'file-saver' + +@Injectable({ providedIn: 'root' }) +@Component({ + selector: 'app-generate-public-key-modal', + templateUrl: './generate-public-key-modal.component.html', + styleUrl: './generate-public-key-modal.component.scss' +}) +export class GeneratePublicKeyModalComponent extends AbstractBaseModalComponent { + userlogin:string; + acknowledgement_given:boolean=false + + constructor( + protected modalService: BsModalService, + private keyService:KeyService + ) { + super(modalService) + + } + showGeneratePublicKeyModal( + userlogin:string + + ): EventEmitter { + const initialState = { + userlogin + } + + return this.showBaseModal(GeneratePublicKeyModalComponent, initialState) + } + + downloadPem(data: string): void { + const blob: Blob = new Blob([data], { type: 'pem' }) + const url: string = window.URL.createObjectURL(blob) + saveAs(url, `${this.userlogin}_ecdsa`) + } + + + generateKey(): void { + this.keyService.generateKey().subscribe((res: any): void => { + this.event.emit() + this.downloadPem(res['private_key']) + }) + } +} diff --git a/src/app/shared/shared_modules/public-key/public-key.component.html b/src/app/shared/shared_modules/public-key/public-key.component.html index a2ca53fbbf..fd5247ac7a 100644 --- a/src/app/shared/shared_modules/public-key/public-key.component.html +++ b/src/app/shared/shared_modules/public-key/public-key.component.html @@ -17,7 +17,7 @@ class="btn btn-primary" style="float: left; margin: 2px" type="button" - (click)="unsetAcknowledgment();generateKeyModal.show()" + (click)="showGeneratePublicKeyModal()" id="generateSShKey" data-test-id="generateSShKey" > @@ -27,7 +27,7 @@ class="btn btn-primary" style="float: left; margin: 2px" type="button" - (click)="public_key = '';unsetAcknowledgment(); pubKeyModal.show()" + (click)="showSetPublicKeyModal()" id="setPublicKeyButton" data-test-id="setPublicKeyButton" > @@ -71,229 +71,3 @@ - - - - - - - diff --git a/src/app/shared/shared_modules/public-key/public-key.component.ts b/src/app/shared/shared_modules/public-key/public-key.component.ts index 13a6d859da..5d6cf119e2 100644 --- a/src/app/shared/shared_modules/public-key/public-key.component.ts +++ b/src/app/shared/shared_modules/public-key/public-key.component.ts @@ -10,6 +10,8 @@ import { AbstractBaseClass } from '../baseClass/abstract-base-class' import { WIKI_GENERATE_KEYS, CLOUD_PORTAL_SUPPORT_MAIL } from '../../../../links/links' import { NotificationModalComponent } from '../../modal/notification-modal' import { BlacklistedResponse } from '../../../api-connector/response-interfaces' +import { GeneratePublicKeyModalComponent } from './generate-public-key-modal/generate-public-key-modal.component' +import { SetPublicKeyModalComponent } from './set-public-key-modal/set-public-key-modal.component' /** * Public Key component. @@ -34,7 +36,8 @@ export class PublicKeyComponent extends AbstractBaseClass implements OnInit { constructor( private keyService: KeyService, private clipboardService: ClipboardService, - private modalService: BsModalService + private generatePublicKeyModal:GeneratePublicKeyModalComponent, + private setPublicKeyModalComponent:SetPublicKeyModalComponent ) { super() } @@ -45,25 +48,30 @@ export class PublicKeyComponent extends AbstractBaseClass implements OnInit { } } - unsetAcknowledgment():void{ - this.acknowledgement_given=false; - } + showSetPublicKeyModal():void{ + this.setPublicKeyModalComponent.showSetPublicKeyModal(this.userinfo.PublicKey).subscribe(() =>{ + console.log("event submitted") + this.getUserPublicKey() + }) - downloadPem(data: string): void { - const blob: Blob = new Blob([data], { type: 'pem' }) - const url: string = window.URL.createObjectURL(blob) - saveAs(url, `${this.userinfo.UserLogin}_ecdsa`) } - generateKey(): void { - this.keyService.generateKey().subscribe((res: any): void => { + showGeneratePublicKeyModal():void{ + this.generatePublicKeyModal.showGeneratePublicKeyModal(this.userinfo.UserLogin).subscribe(() =>{ + console.log("event submitted") this.getUserPublicKey() - this.downloadPem(res['private_key']) }) } + unsetAcknowledgment():void{ + this.acknowledgement_given=false; + } + + + + isKeyBlocked(): void { - this.keyService.isBlocked(this.public_key.trim()).subscribe((res: BlacklistedResponse) => { + this.keyService.isBlocked(this.userinfo.PublicKey.trim()).subscribe((res: BlacklistedResponse) => { this.blocked_key = res.blacklisted }) } @@ -75,41 +83,7 @@ export class PublicKeyComponent extends AbstractBaseClass implements OnInit { }) } - validateKey(): void { - this.keyService.validateKey(this.public_key.trim()).subscribe( - (res: any) => { - this.validated_key = res['status'] === 'valid' - }, - () => { - this.validated_key = false - } - ) - } - importKey(): void { - const re: RegExp = /\+/gi - - this.keyService.postKey(this.public_key.replace(re, '%2B').trim()).subscribe({ - next: (): void => { - this.getUserPublicKey() - const initialState = { - notificationModalTitle: 'Success', - notificationModalType: 'info', - notificationModalMessage: 'The new public key got successfully set' - } - this.modalService.show(NotificationModalComponent, { initialState }) - }, - error: (): any => { - const initialState = { - notificationModalTitle: 'Error', - notificationModalType: 'danger', - notificationModalMessage: - 'We were not able successfully set a new public key. Please enter a valid public key!' - } - this.modalService.show(NotificationModalComponent, { initialState }) - } - }) - } copyToClipboard(text: string): void { if (this.clipboardService.isSupported) { diff --git a/src/app/shared/shared_modules/public-key/public-key.module.ts b/src/app/shared/shared_modules/public-key/public-key.module.ts index 1bd631f55b..720e875114 100644 --- a/src/app/shared/shared_modules/public-key/public-key.module.ts +++ b/src/app/shared/shared_modules/public-key/public-key.module.ts @@ -8,6 +8,8 @@ import { AlertModule } from 'ngx-bootstrap/alert' import { NgbModule } from '@ng-bootstrap/ng-bootstrap' import { PublicKeyComponent } from './public-key.component' import { PipeModuleModule } from '../../../pipe-module/pipe-module.module' +import { GeneratePublicKeyModalComponent } from './generate-public-key-modal/generate-public-key-modal.component' +import { SetPublicKeyModalComponent } from './set-public-key-modal/set-public-key-modal.component' /** * Public key module. @@ -23,7 +25,7 @@ import { PipeModuleModule } from '../../../pipe-module/pipe-module.module' PipeModuleModule ], - declarations: [PublicKeyComponent], + declarations: [PublicKeyComponent,GeneratePublicKeyModalComponent,SetPublicKeyModalComponent], exports: [PublicKeyComponent, AlertModule, FormsModule, ModalModule, CommonModule, TabsModule] }) export class PublicKeyModule {} diff --git a/src/app/shared/shared_modules/public-key/set-public-key-modal/set-public-key-modal.component.html b/src/app/shared/shared_modules/public-key/set-public-key-modal/set-public-key-modal.component.html new file mode 100644 index 0000000000..469c201282 --- /dev/null +++ b/src/app/shared/shared_modules/public-key/set-public-key-modal/set-public-key-modal.component.html @@ -0,0 +1,67 @@ + + + + + diff --git a/src/app/shared/shared_modules/public-key/set-public-key-modal/set-public-key-modal.component.scss b/src/app/shared/shared_modules/public-key/set-public-key-modal/set-public-key-modal.component.scss new file mode 100644 index 0000000000..e69de29bb2 diff --git a/src/app/shared/shared_modules/public-key/set-public-key-modal/set-public-key-modal.component.spec.ts b/src/app/shared/shared_modules/public-key/set-public-key-modal/set-public-key-modal.component.spec.ts new file mode 100644 index 0000000000..5222159674 --- /dev/null +++ b/src/app/shared/shared_modules/public-key/set-public-key-modal/set-public-key-modal.component.spec.ts @@ -0,0 +1,23 @@ +import { ComponentFixture, TestBed } from '@angular/core/testing'; + +import { SetPublicKeyModalComponent } from './set-public-key-modal.component'; + +describe('SetPublicKeyModalComponent', () => { + let component: SetPublicKeyModalComponent; + let fixture: ComponentFixture; + + beforeEach(async () => { + await TestBed.configureTestingModule({ + imports: [SetPublicKeyModalComponent] + }) + .compileComponents(); + + fixture = TestBed.createComponent(SetPublicKeyModalComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/src/app/shared/shared_modules/public-key/set-public-key-modal/set-public-key-modal.component.ts b/src/app/shared/shared_modules/public-key/set-public-key-modal/set-public-key-modal.component.ts new file mode 100644 index 0000000000..416cdc5171 --- /dev/null +++ b/src/app/shared/shared_modules/public-key/set-public-key-modal/set-public-key-modal.component.ts @@ -0,0 +1,80 @@ +import { Component, EventEmitter, Injectable } from '@angular/core'; +import { KeyService } from 'app/api-connector/key.service'; +import { BlacklistedResponse } from 'app/api-connector/response-interfaces'; +import { AbstractBaseModalComponent } from 'app/shared/modal/abstract-base-modal/abstract-base-modal.component'; +import { NotificationModalComponent } from 'app/shared/modal/notification-modal'; +import { BsModalService } from 'ngx-bootstrap/modal'; + +@Injectable({ providedIn: 'root' }) +@Component({ + selector: 'app-set-public-key-modal', + templateUrl: './set-public-key-modal.component.html', + styleUrl: './set-public-key-modal.component.scss' +}) +export class SetPublicKeyModalComponent extends AbstractBaseModalComponent { + + acknowledgement_given:boolean=false + public_key:string; + validated_key: boolean = false + blocked_key: boolean = false + current_key_blocked: boolean = false + + constructor( + protected modalService: BsModalService, + private keyService:KeyService + ) { + super(modalService) + + } + showSetPublicKeyModal( + userlogin:string + + ): EventEmitter { + const initialState = { + userlogin + } + + return this.showBaseModal(SetPublicKeyModalComponent, initialState) + } + isKeyBlocked(): void { + this.keyService.isBlocked(this.public_key.trim()).subscribe((res: BlacklistedResponse) => { + this.blocked_key = res.blacklisted + }) + } + +validateKey(): void { + this.keyService.validateKey(this.public_key.trim()).subscribe( + (res: any) => { + this.validated_key = res['status'] === 'valid' + }, + () => { + this.validated_key = false + } + ) + } + + importKey(): void { + const re: RegExp = /\+/gi + + this.keyService.postKey(this.public_key.replace(re, '%2B').trim()).subscribe({ + next: (): void => { + this.event.emit() + const initialState = { + notificationModalTitle: 'Success', + notificationModalType: 'info', + notificationModalMessage: 'The new public key got successfully set' + } + this.modalService.show(NotificationModalComponent, { initialState }) + }, + error: (): any => { + const initialState = { + notificationModalTitle: 'Error', + notificationModalType: 'danger', + notificationModalMessage: + 'We were not able successfully set a new public key. Please enter a valid public key!' + } + this.modalService.show(NotificationModalComponent, { initialState }) + } + }) + } +}