Skip to content

Commit 2162dc4

Browse files
ddey2lmarini
andauthored
Fix to send notifications to all the admins in one email (#360)
* Fix to send notifications to all the admins in one email Issue: 330 Signed-off-by: Dipannita Dey <[email protected]> * Fixed recipients info on email while submit/accept/reject access to a space Signed-off-by: Dipannita Dey <[email protected]> Co-authored-by: Luigi Marini <[email protected]>
1 parent b971c44 commit 2162dc4

File tree

3 files changed

+31
-7
lines changed

3 files changed

+31
-7
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](http://keepachangelog.com/)
66
and this project adheres to [Semantic Versioning](http://semver.org/).
77

8+
9+
## Unreleased
10+
11+
### Fixed
12+
- Send email to all admins in a single email when a user submits 'Request access' for a space
13+
- Send email to all admins and request user in a single email when any admin accepts/rejects 'Request access' for a space [#330](https://github.com/clowder-framework/clowder/issues/330)
14+
815
## 1.20.3 - 2022-06-10
916

1017
### Fixed
@@ -13,6 +20,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1320
### Changed
1421
- docker builds images for amd64 and arm64 [#322](https://github.com/clowder-framework/clowder/issues/322)
1522

23+
1624
## 1.20.2 - 2022-04-30
1725

1826
### Fixed

app/api/Spaces.scala

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import util.Mail
1313

1414
import java.util.Date
1515
import javax.inject.Inject
16+
import scala.collection.mutable.ListBuffer
1617

1718
/**
1819
* Spaces allow users to partition the data into realms only accessible to users with the right permissions.
@@ -687,9 +688,8 @@ class Spaces @Inject()(spaces: SpaceService,
687688
}
688689
if(requestUser.email.isDefined) {
689690
val subject: String = "Authorization Request from " + AppConfiguration.getDisplayName + " Accepted"
690-
val recipient: String = requestUser.email.get.toString
691691
val body = views.html.spaces.requestresponseemail(user.get, id.toString, s.name, "accepted your request and assigned you as " + role + " to")
692-
Mail.sendEmail(subject, request.user, recipient, body)
692+
Mail.sendEmail(subject, request.user, getRecipientsList(s, requestUser), body)
693693
}
694694
Ok(Json.obj("status" -> "success"))
695695
}
@@ -700,6 +700,22 @@ class Spaces @Inject()(spaces: SpaceService,
700700
}
701701
}
702702

703+
def getRecipientsList(s: ProjectSpace, requestUser: User): List[String] = {
704+
val recipients = new ListBuffer[String]()
705+
recipients += requestUser.email.get.toString
706+
707+
for (requestReceiver <- spaces.getUsersInSpace(s.id, None)) {
708+
spaces.getRoleForUserInSpace(s.id, requestReceiver.id) match {
709+
case Some(aRole) => {
710+
if (aRole.permissions.contains(Permission.EditSpace.toString) && requestReceiver.id != requestUser.id) {
711+
recipients += requestReceiver.toString
712+
}
713+
}
714+
}
715+
}
716+
return recipients.toList
717+
}
718+
703719
def rejectRequest(id:UUID, requestuser:String) = PermissionAction(Permission.EditSpace, Some(ResourceRef(ResourceRef.space, id))) { implicit request =>
704720
implicit val user = request.user
705721
spaces.get(id) match {
@@ -711,9 +727,8 @@ class Spaces @Inject()(spaces: SpaceService,
711727
spaces.removeRequest(id, requestUser.id)
712728
if(requestUser.email.isDefined) {
713729
val subject: String = "Authorization Request from " + AppConfiguration.getDisplayName + " Rejected"
714-
val recipient: String = requestUser.email.get.toString
715730
val body = views.html.spaces.requestresponseemail(user.get, id.toString, s.name, "rejected your request to")
716-
Mail.sendEmail(subject, request.user, recipient, body)
731+
Mail.sendEmail(subject, request.user, getRecipientsList(s, requestUser), body)
717732
}
718733
Ok(Json.obj("status" -> "success"))
719734
}

app/controllers/Spaces.scala

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ class Spaces @Inject() (spaces: SpaceService, users: UserService, events: EventS
354354
def addRequest(id: UUID) = AuthenticatedAction { implicit request =>
355355
implicit val requestuser = request.user
356356
requestuser match {
357-
case Some(user) => {
357+
case Some(user) =>
358358
spaces.get(id) match {
359359
case Some(s) => {
360360
// when permission is public, user can reach the authorization request button, so we check if the request is
@@ -367,24 +367,25 @@ class Spaces @Inject() (spaces: SpaceService, users: UserService, events: EventS
367367
Logger.debug("Request submitted in controller.Space.addRequest ")
368368
val subject: String = "Request for access from " + AppConfiguration.getDisplayName
369369
val body = views.html.spaces.requestemail(user, id.toString, s.name)
370+
val spaceAdminRecipients = new ListBuffer[String]
370371

371372
for (requestReceiver <- spaces.getUsersInSpace(s.id, None)) {
372373
spaces.getRoleForUserInSpace(s.id, requestReceiver.id) match {
373374
case Some(aRole) => {
374375
if (aRole.permissions.contains(Permission.EditSpace.toString)) {
375376
events.addRequestEvent(Some(user), requestReceiver, id, s.name, "postrequest_space")
376-
Mail.sendEmail(subject, request.user, requestReceiver, body)
377+
spaceAdminRecipients += requestReceiver.toString
377378
}
378379
}
379380
}
380381
}
382+
Mail.sendEmail(subject, request.user, spaceAdminRecipients.toList, body)
381383
spaces.addRequest(id, user.id, user.fullName)
382384
Ok(views.html.authorizationMessage("Request submitted for " + spaceTitle + " " + s.name, s))
383385
}
384386
}
385387
case None => InternalServerError(spaceTitle + " not found")
386388
}
387-
}
388389

389390
case None => InternalServerError("User not found")
390391
}

0 commit comments

Comments
 (0)