Skip to content
This repository has been archived by the owner on Oct 24, 2022. It is now read-only.

Commit

Permalink
Refactor to use email templates
Browse files Browse the repository at this point in the history
- This came up in Code Review
- Also fixes bug where admins were notified instead of the User when
approved/denied.
  • Loading branch information
JPrevost committed May 13, 2015
1 parent 8073a81 commit 55ad9e9
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 19 deletions.
26 changes: 7 additions & 19 deletions app/controllers/Application.scala
Expand Up @@ -790,14 +790,7 @@ object Application extends Controller with Security {
subscriber.linkUser(identity.id)
val adminEmails = subscriber.adminList.map {user => user.email}.mkString(",")
val subject = "SCOAP3Hub Request to Join Subscriber"
val msg = s"""
The following person has requested to join a Subscriber you are an administrator for.
Subscriber Group: ${subscriber.name}
User: ${identity.email}

You can approve this user on the Subscriber User List:
${routes.Application.subscriberUsers(subscriber.id).absoluteURL()}
"""
val msg = views.txt.email.subscriber_join_request(subscriber, identity).body
if ( !play.api.Play.isTest(play.api.Play.current) ) {
Emailer.subscriberEmails(adminEmails, subject, msg)
}
Expand All @@ -811,25 +804,20 @@ ${routes.Application.subscriberUsers(subscriber.id).absoluteURL()}
subscriberMember(identity, sub, Ok(views.html.subscriber.users(sub)))
}

def subscriberResolveUser(id: Int, user: Int, res: String) = isAuthenticated { identity => implicit request =>
def subscriberResolveUser(id: Int, userid: Int, res: String) = isAuthenticated { identity => implicit request =>
val sub = Subscriber.findById(id).get
val adminEmails = sub.adminList.map {user => user.email}.mkString(",")
val subject = s"SCOAP3Hub Request to Join Subscriber ${res}"
val msg = s"""
Your request to join Subscriber Group: ${sub.name} has been ${res}.

You may visit SCOAP3Hub at:
${routes.Application.index.absoluteURL()}
"""
val user = User.findById(userid).get
val msg = views.txt.email.subscriber_resolve(sub, res).body

if (sub.adminList.contains(identity)) {
if (res == "approved") {
sub.approveUser(user)
sub.approveUser(userid)
} else {
sub.denyUser(user)
sub.denyUser(userid)
}
if ( !play.api.Play.isTest(play.api.Play.current) ) {
Emailer.subscriberEmails(adminEmails, subject, msg)
Emailer.subscriberEmails(user.email, subject, msg)
}
Redirect(routes.Application.subscriberUsers(sub.id)).flashing(
"success" -> s"User was ${res} membership to this Subscriber Group."
Expand Down
12 changes: 12 additions & 0 deletions app/views/email/subscriber_join_request.scala.txt
@@ -0,0 +1,12 @@
@*****************************************************************************
* Email template to notify Subscriber admins a User requested to join *
* Copyright (c) 2015 MIT Libraries *
*****************************************************************************@
@(subscriber: Subscriber, identity: User)(implicit request: play.api.mvc.RequestHeader)

The following person has requested to join a Subscriber you are an administrator for.
Subscriber Group: @subscriber.name
User: @identity.email

You can approve this user on the Subscriber User List:
@routes.Application.subscriberUsers(subscriber.id).absoluteURL()
10 changes: 10 additions & 0 deletions app/views/email/subscriber_resolve.scala.txt
@@ -0,0 +1,10 @@
@*****************************************************************************
* Email template to notify Subscriber when admin responds to join request *
* Copyright (c) 2015 MIT Libraries *
*****************************************************************************@
@(subscriber: Subscriber, resolution: String)(implicit request: play.api.mvc.RequestHeader)

Your request to join Subscriber Group: @subscriber.name has been @resolution.

You may visit SCOAP3Hub at:
@routes.Application.index.absoluteURL()

0 comments on commit 55ad9e9

Please sign in to comment.