Skip to content

Commit

Permalink
Hide the web profile PeerAdmin/ChannelAdmin system ID card (hyperledg…
Browse files Browse the repository at this point in the history
…er-archives#2043)

There is no way to interact with the card (connect, export or even
delete) so it is confusing to have it in the wallet

Completes #2009

Signed-off-by: James Taylor <[email protected]>
  • Loading branch information
jt-nti authored and Simon Stone committed Aug 30, 2017
1 parent 06281f7 commit 4f394d5
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ <h1>My Wallet</h1>
<section *ngIf="!showSubScreen" class="main-view">
<div class="connection-profile" *ngFor="let connectionProfileRef of connectionProfileRefs;">
<span class="connection-profile-title">
<h2>Identities for {{this.connectionProfileNames.get(connectionProfileRef) === '$default' ? 'Web Browser' : this.connectionProfileNames.get(connectionProfileRef) }}</h2>
<h2>Identities for {{this.connectionProfileRef === 'web-$default' ? 'Web Browser' : this.connectionProfileNames.get(connectionProfileRef) }}</h2>
<tutorial-link *ngIf="idCards.size == 1"></tutorial-link>
</span>
<div class="identities">
Expand Down
58 changes: 40 additions & 18 deletions packages/composer-playground/src/app/login/login.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,31 +224,24 @@ describe(`LoginComponent`, () => {
});

describe('loadIdentityCards', () => {
let mockIdCard1;
let mockIdCard2;
let mockIdCard3;
let mockIdCard4;
let mockIdCard5;
let mockIdCards: Map<string, IdCard>;

beforeEach(() => {
mockIdCard1 = sinon.createStubInstance(IdCard);
it('should load identity cards and sort the profiles', fakeAsync(() => {
let mockIdCard1 = sinon.createStubInstance(IdCard);
mockIdCard1.getName.returns('card1');
mockIdCard1.getConnectionProfile.returns({name: 'myProfile1'});
mockIdCard2 = sinon.createStubInstance(IdCard);
let mockIdCard2 = sinon.createStubInstance(IdCard);
mockIdCard2.getName.returns('card2');
mockIdCard2.getConnectionProfile.returns({name: 'myProfile2'});
mockIdCard3 = sinon.createStubInstance(IdCard);
let mockIdCard3 = sinon.createStubInstance(IdCard);
mockIdCard3.getName.returns('card3');
mockIdCard3.getConnectionProfile.returns({name: 'myProfile1'});
mockIdCard4 = sinon.createStubInstance(IdCard);
mockIdCard4.getName.returns('web');
let mockIdCard4 = sinon.createStubInstance(IdCard);
mockIdCard4.getName.returns('card4');
mockIdCard4.getConnectionProfile.returns({name: '$default'});
mockIdCard5 = sinon.createStubInstance(IdCard);
mockIdCard5.getName.returns('card4');
let mockIdCard5 = sinon.createStubInstance(IdCard);
mockIdCard5.getName.returns('card5');
mockIdCard5.getConnectionProfile.returns({name: 'bobProfile'});

mockIdCards = new Map<string, IdCard>();
let mockIdCards = new Map<string, IdCard>();
mockIdCards.set('myCardRef1', mockIdCard1);
mockIdCards.set('myCardRef2', mockIdCard2);
mockIdCards.set('myCardRef3', mockIdCard3);
Expand All @@ -259,9 +252,7 @@ describe(`LoginComponent`, () => {
mockIdentityCardService.getQualifiedProfileName.withArgs({name: 'myProfile2'}).returns('xxx-myProfile2');
mockIdentityCardService.getQualifiedProfileName.withArgs({name: 'bobProfile'}).returns('xxx-bobProfile');
mockIdentityCardService.getQualifiedProfileName.withArgs({name: '$default'}).returns('web-$default');
});

it('should load identity cards and sort the profiles', fakeAsync(() => {
mockIdentityCardService.getIdentityCards.returns(Promise.resolve(mockIdCards));
mockIdentityCardService.getIndestructibleIdentityCards.returns(['myCardRef4']);
let sortCards = sinon.stub(component, 'sortIdCards');
Expand All @@ -288,6 +279,37 @@ describe(`LoginComponent`, () => {
component['indestructibleCards'].should.deep.equal(['myCardRef4']);
}));

it('should load identity cards and ensure there is always a web connection profile', fakeAsync(() => {
let mockIdCard1 = sinon.createStubInstance(IdCard);
mockIdCard1.getName.returns('PeerAdmin');
mockIdCard1.getConnectionProfile.returns({name: '$default', type: 'web'});
let mockIdCard2 = sinon.createStubInstance(IdCard);
mockIdCard2.getName.returns('bob');
mockIdCard2.getConnectionProfile.returns({name: 'bobProfile'});

let mockIdCards = new Map<string, IdCard>();
mockIdCards.set('myCardRef1', mockIdCard1);
mockIdCards.set('myCardRef2', mockIdCard2);

mockIdentityCardService.getQualifiedProfileName.withArgs({name: 'bobProfile'}).returns('xxx-bobProfile');
mockIdentityCardService.getQualifiedProfileName.withArgs({name: '$default'}).returns('web-$default');

mockIdentityCardService.getIdentityCards.returns(Promise.resolve(mockIdCards));
mockIdentityCardService.getIndestructibleIdentityCards.returns(['myCardRef1']);
let sortCards = sinon.stub(component, 'sortIdCards');

component.loadIdentityCards();

tick();

component['connectionProfileRefs'].should.deep.equal(['web-$default', 'xxx-bobProfile']);
component['connectionProfileNames'].size.should.equal(1);
component['connectionProfileNames'].get('xxx-bobProfile').should.equal('bobProfile');
component['idCardRefs'].size.should.equal(1);
component['idCardRefs'].get('xxx-bobProfile').should.deep.equal(['myCardRef2']);
component['indestructibleCards'].should.deep.equal(['myCardRef1']);
}));

it('should handle error', fakeAsync(() => {
mockIdentityCardService.getIdentityCards.returns(Promise.reject('some error'));

Expand Down
23 changes: 18 additions & 5 deletions packages/composer-playground/src/app/login/login.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,12 @@ export class LoginComponent implements OnInit {

let newCardRefs = Array.from(cards.keys())
.map((cardRef) => {
let connectionProfile = cards.get(cardRef).getConnectionProfile();
let card = cards.get(cardRef);
let connectionProfile = card.getConnectionProfile();
if (connectionProfile.type === 'web' && (this.indestructibleCards.indexOf(cardRef) > -1)) {
return;
}

let connectionProfileRef: string = this.identityCardService.getQualifiedProfileName(connectionProfile);
if (!this.connectionProfileNames.has(connectionProfileRef)) {
this.connectionProfileNames.set(connectionProfileRef, connectionProfile.name);
Expand All @@ -76,6 +81,10 @@ export class LoginComponent implements OnInit {
return [connectionProfileRef, cardRef];
})
.reduce((prev, cur) => {
if (!cur) {
return prev;
}

let curCardRefs: string[] = prev.get(cur[0]) || [];
let cardRef: string = <string> cur[1];
return prev.set(cur[0], [...curCardRefs, cardRef]);
Expand All @@ -86,10 +95,14 @@ export class LoginComponent implements OnInit {
});

this.idCardRefs = newCardRefs;
// sort connection profile names and make sure there is always
// a web connection profile at the start, even when there are
// no identity cards
let unsortedConnectionProfiles = Array.from(this.connectionProfileNames.keys());
let indexOfWeb = unsortedConnectionProfiles.indexOf('web-$default');
let webProfile = unsortedConnectionProfiles[indexOfWeb];
unsortedConnectionProfiles.splice(indexOfWeb, 1);
let indexOfWebProfile = unsortedConnectionProfiles.indexOf('web-$default');
if (indexOfWebProfile > -1) {
unsortedConnectionProfiles.splice(indexOfWebProfile, 1);
}
unsortedConnectionProfiles.sort((a: string, b: string): number => {
let aName = this.connectionProfileNames.get(a);
let bName = this.connectionProfileNames.get(b);
Expand All @@ -101,7 +114,7 @@ export class LoginComponent implements OnInit {
return 1;
}
});
unsortedConnectionProfiles.unshift(webProfile);
unsortedConnectionProfiles.unshift('web-$default');
this.connectionProfileRefs = unsortedConnectionProfiles;

}).catch((error) => {
Expand Down

0 comments on commit 4f394d5

Please sign in to comment.