Skip to content
This repository has been archived by the owner on Mar 25, 2023. It is now read-only.

Commit

Permalink
fix(ssh-keys-sidebar): SSH keys sidebar loads invalid key if there ar…
Browse files Browse the repository at this point in the history
…e duplicate names for different accounts - review fixes 1
  • Loading branch information
HeyRoach committed Nov 8, 2017
1 parent 97df1d4 commit 9110eec
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 31 deletions.
2 changes: 1 addition & 1 deletion src/app/shared/components/sidebar/sidebar.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export abstract class SidebarComponent<M extends BaseModel> implements OnInit {
return (tabId === pathLastChild)
}

protected pluckId(): Observable<string> {
private pluckId(): Observable<string> {
return this.route.params.pluck('id').filter(id => !!id) as Observable<string>;
}

Expand Down
14 changes: 3 additions & 11 deletions src/app/shared/services/ssh-keypair.service.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { ActivatedRoute, Params } from '@angular/router';
import { ActivatedRoute } from '@angular/router';
import { Observable } from 'rxjs/Observable';
import { VirtualMachine } from '../../vm/shared/vm.model';
import { BackendResource } from '../decorators';
Expand All @@ -21,20 +21,12 @@ export interface SshKeyCreationData {
entityModel: SSHKeyPair
})
export class SSHKeyPairService extends BaseBackendCachedService<SSHKeyPair> {
protected account: string;

constructor(private asyncJobService: AsyncJobService,
protected http: HttpClient,
protected activatedRoute: ActivatedRoute) {
protected http: HttpClient) {
super(http);

this.activatedRoute.queryParams.subscribe((params: Params) => {
this.account = params['account'];
});
}

public getByName(name: string, account?: string): Observable<SSHKeyPair> {
const params = account ? { name, account } : { name };
public getByParams(params): Observable<SSHKeyPair> {
return this.getList(params).map(sshKeys => sshKeys[0]);
}

Expand Down
27 changes: 8 additions & 19 deletions src/app/ssh-keys/ssh-key-sidebar/ssh-key-sidebar.component.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Component, OnInit } from '@angular/core';
import { ActivatedRoute, Params, Router } from '@angular/router';
import { Component } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';
import { Observable } from 'rxjs/Observable';
import { SidebarComponent } from '../../shared/components/sidebar/sidebar.component';
import { SSHKeyPair } from '../../shared/models/ssh-keypair.model';
Expand All @@ -13,7 +13,7 @@ import { EntityDoesNotExistError } from '../../shared/components/sidebar/entity-
selector: 'cs-ssh-key-sidebar',
templateUrl: 'ssh-key-sidebar.component.html'
})
export class SshKeySidebarComponent extends SidebarComponent<SSHKeyPair> implements OnInit {
export class SshKeySidebarComponent extends SidebarComponent<SSHKeyPair> {
public description: string;
public account: string;

Expand All @@ -25,21 +25,16 @@ export class SshKeySidebarComponent extends SidebarComponent<SSHKeyPair> impleme
super(entityService, notificationService, route, router);
}

public ngOnInit() {
this.getEntityAccount();

this.pluckId()
.switchMap(id => this.loadEntity(id, this.account))
.subscribe(entity => this.entity = entity);
}

public onDescriptionChange(description: string): void {
this.description = description;
this.userTagService.setSshKeyDescription(this.entity, this.description).subscribe();
}

protected loadEntity(name: string, account?: string): Observable<SSHKeyPair> {
return this.entityService.getByName(name, account)
protected loadEntity(name: string): Observable<SSHKeyPair> {
const account = this.route.snapshot.queryParams['account'];
const params = account ? { name, account } : { name };

return this.entityService.getByParams(params)
.switchMap(sshKeyPair => {
if (sshKeyPair) {
return Observable.of(sshKeyPair);
Expand All @@ -58,10 +53,4 @@ export class SshKeySidebarComponent extends SidebarComponent<SSHKeyPair> impleme
return sshKeyPair;
});
}

private getEntityAccount() {
this.route.queryParams.subscribe((params: Params) => {
this.account = params['account'];
});
}
}

0 comments on commit 9110eec

Please sign in to comment.