Skip to content

Commit

Permalink
Send email as part of the project invite process
Browse files Browse the repository at this point in the history
  • Loading branch information
Josh Reed committed Feb 28, 2012
1 parent 057d678 commit 2d920fe
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 3 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -12,3 +12,4 @@ env
*.ser
stacktrace.log
**/grails-app/views/_git.gsp
secret.properties
17 changes: 15 additions & 2 deletions common/grails-app/services/coreref/common/ProjectService.groovy
Expand Up @@ -2,6 +2,7 @@ package coreref.common

class ProjectService {
static transactional = false
def mailService

def pending(project) {
ProjectInvite.findAllInstances(projectId: project.id, blocked: false)
Expand Down Expand Up @@ -37,7 +38,7 @@ class ProjectService {

// request access
invite = new ProjectInvite(email: user.email, projectId: project.id)
ProjectInvite.mongoCollection.add(invite)
sendInvite(invite)
return 'Your join request was sent to the project admin'
}

Expand Down Expand Up @@ -74,7 +75,8 @@ class ProjectService {
}
} else {
// add a new invite
ProjectInvite.mongoCollection.add(email: email, projectId: project.id, invited: true, blocked: false)
invite = new ProjectInvite(email: email, projectId: project.id, invited: true, blocked: false)
sendInvite(invite)
}
}
}
Expand Down Expand Up @@ -130,6 +132,17 @@ class ProjectService {
}
}

private sendInvite(invite) {
ProjectInvite.mongoCollection.add(invite)

// email user
mailService.sendMail {
to invite.email
subject "You've been invited to a project on CoreRef"
body(view: '/email/invite', model: [invite: invite, project: Project.getInstance(invite.projectId)])
}
}

private void save(user) {
User.mongoCollection.update(user.mongoObject, user)
}
Expand Down
10 changes: 10 additions & 0 deletions common/test/unit/coreref/common/ProjectServiceTests.groovy
Expand Up @@ -72,7 +72,12 @@ class ProjectServiceTests {
}

void testJoinRequest() {
boolean sent = false
projectService.mailService = [
sendMail: { Closure c -> sent = true }
]
'Your join request was sent to the project admin' == projectService.join(project, user)
assert sent
assert !user.isMember(project)
assert 1 == ProjectInvite.mongoCollection.count()
}
Expand Down Expand Up @@ -137,7 +142,12 @@ class ProjectServiceTests {
ProjectInvite.mongoCollection.add(email: 'foo@bar.com', projectId: project.id, invited: false)
assert 1 == ProjectInvite.mongoCollection.count()

boolean sent = false
projectService.mailService = [
sendMail: { Closure c -> sent = true }
]
projectService.invite(project, ['test@test.com', 'foo@bar.com', 'bar@baz.com'])
assert sent
user = User.getInstance(user.id)
assert user.isMember(project)
assert 2 == ProjectInvite.mongoCollection.count()
Expand Down
3 changes: 2 additions & 1 deletion coreref/application.properties
@@ -1,10 +1,11 @@
#Grails Metadata file
#Sun Jan 29 20:18:29 CST 2012
#Mon Jan 30 20:45:23 CST 2012
app.grails.version=2.0.0
app.name=coreref
app.servlet.version=2.4
app.version=0.1
plugins.code-coverage=1.2.4
plugins.jquery=1.6.1.1
plugins.mail=1.0
plugins.pretty-time=0.3
plugins.tomcat=2.0.0
18 changes: 18 additions & 0 deletions coreref/grails-app/conf/Config.groovy
Expand Up @@ -10,6 +10,8 @@
// grails.config.locations << "file:" + System.properties["${appName}.config.location"]
// }

grails.config.locations = [ "classpath:secret.properties" ]

grails.project.groupId = appName // change this to alter the default package name and Maven publishing destination
grails.mime.file.extensions = true // enables the parsing of file extensions from URLs into the request format
grails.mime.use.accept.header = false
Expand Down Expand Up @@ -100,3 +102,19 @@ log4j = {

warn 'org.mortbay.log'
}

// mail settings
grails {
mail {
host = "smtp.gmail.com"
port = 465
username = "jareed@coreref.org"
password = "" // configure via secret.properties file
props = [
"mail.smtp.auth": "true",
"mail.smtp.socketFactory.port": "465",
"mail.smtp.socketFactory.class": "javax.net.ssl.SSLSocketFactory",
"mail.smtp.socketFactory.fallback": "false"
]
}
}
2 changes: 2 additions & 0 deletions coreref/grails-app/views/email/invite.gsp
@@ -0,0 +1,2 @@
Invite: ${invite}
Project: ${project}

0 comments on commit 2d920fe

Please sign in to comment.