-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Display Request Access button and Contact Author button * Add tests, moved functions to separate service
- Loading branch information
Showing
7 changed files
with
176 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { DockstoreService } from './../shared/dockstore.service'; | ||
import { sampleTool1 } from '../test/mocked-objects'; | ||
import { DockstoreTool } from './../shared/swagger/model/dockstoreTool'; | ||
import { ExtendedDockstoreTool } from './../shared/models/ExtendedDockstoreTool'; | ||
/* tslint:disable:no-unused-variable */ | ||
|
||
import { TestBed, async, inject } from '@angular/core/testing'; | ||
import { EmailService } from './email.service'; | ||
|
||
describe('Service: Email', () => { | ||
beforeEach(() => { | ||
TestBed.configureTestingModule({ | ||
providers: [EmailService, DockstoreService] | ||
}); | ||
}); | ||
|
||
const tool: ExtendedDockstoreTool = sampleTool1; | ||
tool.tool_maintainer_email = 'fake@maintainer.email.ca'; | ||
tool.email = 'fake@email.ca'; | ||
tool.path = 'registry.hub.docker.com/postgres/postgres'; | ||
tool.registry = DockstoreTool.RegistryEnum.DOCKERHUB; | ||
tool.imgProvider = 'Docker Hub'; | ||
|
||
it('should get the right request access email href', inject([EmailService], (service: EmailService) => { | ||
expect(service).toBeTruthy(); | ||
expect(service.composeRequestAccessEmail(tool)).toEqual('mailto:fake@maintainer.email.ca' + | ||
'?subject=Dockstore%20Request%20for%20Access%20to%20registry.hub.docker.com/postgres/postgres' + | ||
'&body=I%20would%20like%20to%20request%20access%20to%20your%20Docker%20image%20registry.hub.docker.com/postgres/postgres.%20' + | ||
'My%20user%20name%20on%20Docker%20Hub%20is%20%3Cusername%3E'); | ||
})); | ||
|
||
it('should get the right contact author email href', inject([EmailService], (service: EmailService) => { | ||
expect(service).toBeTruthy(); | ||
expect(service.composeContactAuthorEmail(tool)).toEqual('mailto:fake@email.ca' + | ||
'?subject=Dockstore%20registry.hub.docker.com/postgres/postgres%20inquiry' + | ||
'&body='); | ||
})); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
import { ExtendedDockstoreTool } from './../shared/models/ExtendedDockstoreTool'; | ||
import { DockstoreService } from './../shared/dockstore.service'; | ||
import { Injectable } from '@angular/core'; | ||
|
||
@Injectable() | ||
export class EmailService { | ||
|
||
constructor(private dockstoreService: DockstoreService) { } | ||
/** | ||
* Compose the href for an email | ||
* @param email The mailto address | ||
* @param subject The subject of the email | ||
* @param body The body of the the email | ||
*/ | ||
private composeEmail(email: string, subject: string, body: string): string { | ||
return `mailto:${email}?subject=${subject}&body=${body}`; | ||
} | ||
|
||
/** | ||
* Composes the href for the Request Access email | ||
* @param tool The tool to request access for | ||
*/ | ||
public composeRequestAccessEmail(tool: ExtendedDockstoreTool): string { | ||
const email = this.getRequestEmailMailTo(tool.tool_maintainer_email, tool.email); | ||
const subject = this.getRequestEmailSubject(tool.path); | ||
const body = this.getRequestEmailBody(tool.path, tool.imgProvider); | ||
return this.composeEmail(email, subject, body); | ||
} | ||
|
||
/** | ||
* Composes the href for the Contact Author email | ||
* @param tool The tool to contact author for | ||
*/ | ||
public composeContactAuthorEmail(tool: ExtendedDockstoreTool): string { | ||
const email = this.getInquiryEmailMailTo(tool.email); | ||
const subject = this.getInquiryEmailSubject(tool.path); | ||
const body = this.getInquiryEmailBody(); | ||
return this.composeEmail(email, subject, body); | ||
} | ||
|
||
// Request Access button methods | ||
/** | ||
* This gets the mailto address when the Request Access button is clicked | ||
* @param maintainerEmail The maintainer email | ||
* @param email The tool author's email address | ||
*/ | ||
private getRequestEmailMailTo(maintainerEmail: string, email: string): string { | ||
return this.dockstoreService.getRequestAccessEmail(maintainerEmail, email); | ||
} | ||
|
||
/** | ||
* This gets the email subject when the Request Access button is clicked | ||
* @param path The path of the tool whose access is being requested | ||
*/ | ||
private getRequestEmailSubject(path: string): string { | ||
return encodeURI(`Dockstore Request for Access to ${path}`); | ||
} | ||
|
||
/** | ||
* This gets the email body when the Request Access button is clicked | ||
* @param path The path of the tool whose access is being requested | ||
* @param toolRegistry The tool registry (Quay.io, GitLab, etc) of the tool whose access is being requested | ||
*/ | ||
private getRequestEmailBody(path: string, toolRegistry: string): string { | ||
return encodeURI(`I would like to request access to your Docker image ${path}. ` + | ||
`My user name on ${toolRegistry} is <username>`); | ||
} | ||
|
||
// Contact Author button methods | ||
/** | ||
* This gets the mailto address when the Contact Author button is clicked. console.log(tool); | ||
* This method is mostly redundant, but keeping it to mirror the Request Access button methods and in case modifications are needed | ||
* @param email The tool author's email address | ||
*/ | ||
private getInquiryEmailMailTo(email): string { | ||
return email; | ||
} | ||
|
||
/** | ||
* This gets the email subject when the Contact Author button is clicked | ||
* @param path The path of the tool whose access is being requested | ||
*/ | ||
private getInquiryEmailSubject(path: string): string { | ||
return encodeURI(`Dockstore ${path} inquiry`); | ||
} | ||
|
||
/** | ||
* This gets the email body when the Contact Author button is clicked | ||
* This method is mostly redundant, but keeping it to mirror the Request Access button methods and in case modifications are needed | ||
*/ | ||
private getInquiryEmailBody(): string { | ||
return ''; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters