diff --git a/src/app/appmarket/bulkDeployment/bulk-view/bulk-view.component.html b/src/app/appmarket/bulkDeployment/bulk-view/bulk-view.component.html index 8e5ad7d9d0919d32fa42f3764fdc9235477e90cc..9c870590051db4025f7b3d0dffbaeee499a71785 100644 --- a/src/app/appmarket/bulkDeployment/bulk-view/bulk-view.component.html +++ b/src/app/appmarket/bulkDeployment/bulk-view/bulk-view.component.html @@ -160,6 +160,15 @@ </div> </div> + <div class="" style="padding-bottom: 5rem;"> + <label for="id" class="col-sm-2 control-label text-right mt-2">{{ 'BULK.LIST.APP_NAME' | translate }}</label> + <div class="col-sm-10"> + <input type="text" class="form-control" id="id" name="id" [disabled]="true" + [(ngModel)]="bulk.details['appName']" #name="ngModel"> + </div> + + </div> + <div class="" style="padding-bottom: 5rem"> <label for="creator" class="col-sm-2 control-label text-right mt-2">{{ 'BULK.LIST.CREATOR' | translate }}</label> @@ -196,14 +205,7 @@ </div> </div> - <div class="" style="padding-bottom: 5rem;"> - <label for="id" class="col-sm-2 control-label text-right mt-2">{{ 'BULK.LIST.APP_NAME' | translate }}</label> - <div class="col-sm-10"> - <input type="text" class="form-control" id="id" name="id" [disabled]="true" - [(ngModel)]="bulk.details['appName']" #name="ngModel"> - </div> - - </div> + <div *ngIf="bulk.state !== 'REMOVED'" class="flex justify-content-end" style="padding-right: 1.5rem"> <button class="btn btn-primary mr-2" (click)="refreshStates()">{{'BULK.APP.REFRESH' | translate}}</button> diff --git a/src/app/appmarket/users/userdetails/userdetails.component.html b/src/app/appmarket/users/userdetails/userdetails.component.html index 6baf5888a19174411af0589f1fcfed73cbcb78e1..f728a79ce158c48bcbe6db89c05d4452d03a47c3 100644 --- a/src/app/appmarket/users/userdetails/userdetails.component.html +++ b/src/app/appmarket/users/userdetails/userdetails.component.html @@ -7,5 +7,6 @@ <div> <nmaas-userdetails [user]="user" [(userDetailsMode)]="userDetailsMode" [allowedModes]="[ComponentMode.VIEW, ComponentMode.EDIT]" [(errorMessage)]="errorMessage" (onSave)="onSave($event)" (refresh)="onRefresh()"></nmaas-userdetails> <nmaas-userprivileges [allowedModes]="[ComponentMode.VIEW, ComponentMode.CREATE]" [user]="user"></nmaas-userprivileges> + <nmaas-ssh-keys *roles="['ROLE_SYSTEM_ADMIN']" [userMode]="true" [userId]="user?.id"></nmaas-ssh-keys> </div> </div> diff --git a/src/app/service/sshkey.service.ts b/src/app/service/sshkey.service.ts index f6b47b7245f782a9190f9bae5b6d1347cd398bdf..32424f472417e56ad29d71c83ff42cb5959f862b 100644 --- a/src/app/service/sshkey.service.ts +++ b/src/app/service/sshkey.service.ts @@ -26,4 +26,17 @@ export class SSHKeyService extends GenericDataService { public invalidate(id: number): Observable<any> { return this.delete(this.appConfig.getApiUrl() + '/user/keys/' + id); } + + public getAllByUserId(userId: number): Observable<SSHKeyView[]> { + return this.get<SSHKeyView[]>(this.appConfig.getApiUrl() + '/user/keys/view/' + userId); + } + + public createKeyForUser(request: SSHKeyRequest, userId: number ): Observable<any> { + return this.put<SSHKeyRequest, any>(this.appConfig.getApiUrl() + '/user/keys/view/' + userId, request); + } + + public invalidateUserKey(keyId: number, userId: number): Observable<any> { + return this.delete(this.appConfig.getApiUrl() + '/user/keys/view/' + userId + "/" + keyId); + } + } diff --git a/src/app/shared/users/new-ssh-key/new-ssh-key.component.ts b/src/app/shared/users/new-ssh-key/new-ssh-key.component.ts index 619104369b0f33a17d8f96fb4aaa925f0d1a573a..191b25ae717054a9c62fa618cadd1568f2fb31db 100644 --- a/src/app/shared/users/new-ssh-key/new-ssh-key.component.ts +++ b/src/app/shared/users/new-ssh-key/new-ssh-key.component.ts @@ -1,4 +1,4 @@ -import {Component, EventEmitter, OnInit, Output, ViewChild} from '@angular/core'; +import {Component, EventEmitter, Input, OnInit, Output, ViewChild} from '@angular/core'; import {SSHKeyService} from '../../../service/sshkey.service'; import {SSHKeyRequest} from '../../../model/sshkey-request'; import {UntypedFormBuilder, UntypedFormGroup, Validators} from '@angular/forms'; @@ -17,6 +17,12 @@ export class NewSshKeyComponent implements OnInit { @Output() public out: EventEmitter<any> = new EventEmitter<any>(); + @Input() + public userMode = false; + + @Input() + public userId : number; + public error: string = undefined; public requestForm: UntypedFormGroup = undefined; @@ -38,17 +44,34 @@ export class NewSshKeyComponent implements OnInit { console.log(this.requestForm); request.name = this.requestForm.value.name.trim(); request.key = this.requestForm.value.key.trim(); + if(this.userMode) { + if(this.userId !== null) { + this.keyService.createKeyForUser(request, this.userId).subscribe( + data => { + this.error = undefined; + this.requestForm.reset(); + this.modal.hide(); + this.out.emit(); + }, + error => { + this.error = error.message; + } + ); + } + } else { // profile view this.keyService.createKey(request).subscribe( - data => { - this.error = undefined; - this.requestForm.reset(); - this.modal.hide(); - this.out.emit(); - }, - error => { - this.error = error.message; - } - ); + data => { + this.error = undefined; + this.requestForm.reset(); + this.modal.hide(); + this.out.emit(); + }, + error => { + this.error = error.message; + } + ); + } + } get name() { diff --git a/src/app/shared/users/ssh-keys/ssh-keys.component.html b/src/app/shared/users/ssh-keys/ssh-keys.component.html index fb8a78f932a3717b843e0dde2f803a767d88399e..e9025bddb5cd7796a569b04f68bb8cd26b94c772 100644 --- a/src/app/shared/users/ssh-keys/ssh-keys.component.html +++ b/src/app/shared/users/ssh-keys/ssh-keys.component.html @@ -2,7 +2,7 @@ <div class="panel-heading">{{'SSH_KEYS.HEADER' | translate}}</div> <div class="panel-body"> <div class="flex justify-content-end mb-4"> - <app-new-ssh-key (out)="getData()"></app-new-ssh-key> + <app-new-ssh-key [userMode]="userMode" [userId]="userId" (out)="getData()"></app-new-ssh-key> </div> <table class="table table-hover" aria-describedby="User ssh keys table"> <thead> diff --git a/src/app/shared/users/ssh-keys/ssh-keys.component.ts b/src/app/shared/users/ssh-keys/ssh-keys.component.ts index 8bee8e6e677c36590e4fcd6a4b9a71725f0ec2c9..7def6034efd3074b784ac160800ff63b92dc70c5 100644 --- a/src/app/shared/users/ssh-keys/ssh-keys.component.ts +++ b/src/app/shared/users/ssh-keys/ssh-keys.component.ts @@ -1,4 +1,4 @@ -import {Component, OnInit} from '@angular/core'; +import {Component, Input, OnChanges, OnInit, SimpleChanges} from '@angular/core'; import {SSHKeyService} from '../../../service/sshkey.service'; import {Observable} from 'rxjs'; import {SSHKeyView} from '../../../model/sshkey-view'; @@ -8,16 +8,37 @@ import {SSHKeyView} from '../../../model/sshkey-view'; templateUrl: './ssh-keys.component.html', styleUrls: ['./ssh-keys.component.css'] }) -export class SshKeysComponent implements OnInit { +export class SshKeysComponent implements OnInit, OnChanges { public keys: Observable<SSHKeyView[]> = undefined; public keysList: SSHKeyView[] = []; + @Input() + public userMode = false; + + @Input() + public userId : number; + constructor(private keyService: SSHKeyService) { } ngOnInit() { - this.keys = this.keyService.getAll(); - this.getData(); + if(this.userMode) { + if(this.userId !== null) { + this.keys = this.keyService.getAllByUserId(this.userId); + this.getData(); + } + } else { // profile view + this.keys = this.keyService.getAll(); + this.getData(); + } + + } + + ngOnChanges(changes: SimpleChanges) { + if (changes['userId']) { + this.ngOnInit(); + console.log('Nowa wartość userId:', this.userId); + } } getData() { @@ -33,15 +54,28 @@ export class SshKeysComponent implements OnInit { } invalidate(id: number) { - this.keyService.invalidate(id).subscribe( - data => { - console.log('invalidating ssh key id: ' + id + ' success'); - this.getData(); - }, - error => { - console.error(error); - } - ); + if(this.userMode) { + this.keyService.invalidateUserKey(id, this.userId).subscribe( + data => { + console.log('invalidating ssh key id: ' + id + ' success'); + this.getData(); + }, + error => { + console.error(error); + } + ); + } else { + this.keyService.invalidate(id).subscribe( + data => { + console.log('invalidating ssh key id: ' + id + ' success'); + this.getData(); + }, + error => { + console.error(error); + } + ); + } + } }