Skip to content

Commit

Permalink
Send notifications to all "admin" status users of project when a "get…
Browse files Browse the repository at this point in the history
… in touch" challenge comment is added (#1062)

* changed createChallengeMentionNotifications to loop through all project managers if applicable. Need to troubleshoot control flow

* refactored control flow for retrieving and looping through project managers

* Changed createChallengeMentionNotifications to check for managers and manager role when sending notifications

* fix formatting
  • Loading branch information
AndrewPhilbin authored Sep 5, 2023
1 parent 2a2a335 commit bf463bf
Showing 1 changed file with 53 additions and 17 deletions.
70 changes: 53 additions & 17 deletions app/org/maproulette/framework/service/NotificationService.scala
Original file line number Diff line number Diff line change
Expand Up @@ -190,26 +190,62 @@ class NotificationService @Inject() (
challenge: Challenge
): Unit = {
// match [@username] (username may contain spaces) or @username (no spaces allowed)
val mentionRegex = """\[@([^\]]+)\]|@([\w\d_-]+)""".r.unanchored

val mentionRegex = """\[@([^\]]+)\]|@([\w\d_-]+)""".r.unanchored
val challengeOwner = this.serviceManager.user.retrieveByOSMId(challenge.general.owner).get

// Challenge owners should be notified everytime a challenge comment is posted unless its their comment
if (fromUser.id != challengeOwner.id) {
this.addNotification(
UserNotification(
-1,
userId = challengeOwner.id,
notificationType = UserNotification.NOTIFICATION_TYPE_CHALLENGE_COMMENT,
fromUsername = Some(fromUser.osmProfile.displayName),
taskId = None,
challengeId = Some(challenge.id),
targetId = Some(comment.id),
extra = Some(comment.comment)
),
User.superUser
val buildNotification = (userId: Long) => {
UserNotification(
-1,
userId = userId,
notificationType = UserNotification.NOTIFICATION_TYPE_CHALLENGE_COMMENT,
fromUsername = Some(fromUser.osmProfile.displayName),
taskId = None,
challengeId = Some(challenge.id),
targetId = Some(comment.id),
extra = Some(comment.comment)
)
}
// Challenge owners and any parent project managers should be notified everytime
// a challenge comment is posted unless its their comment
this.serviceManager.project.retrieve(challenge.general.parent) match {
case Some(parentProject) =>
this.serviceManager.user
.getUsersManagingProject(parentProject.id, None, User.superUser) match {
case Nil =>
if (fromUser.id != challengeOwner.id) {
this.addNotification(
buildNotification(challengeOwner.id),
User.superUser
)
}
case managers =>
managers.foreach { manager =>
if (manager.userId != fromUser.id && manager.roles.contains(1)) {
this.addNotification(
UserNotification(
-1,
userId = manager.userId,
notificationType = UserNotification.NOTIFICATION_TYPE_CHALLENGE_COMMENT,
fromUsername = Some(fromUser.osmProfile.displayName),
taskId = None,
challengeId = Some(challenge.id),
targetId = Some(comment.id),
extra = Some(comment.comment)
),
User.superUser
)
}
}
}

// If no parent project found and therefore no managers extracted, notify only challenge owner
case None =>
if (fromUser.id != challengeOwner.id) {
this.addNotification(
buildNotification(challengeOwner.id),
User.superUser
)
}
}

for (m <- mentionRegex.findAllMatchIn(comment.comment)) {
// use first non-null group
Expand Down

0 comments on commit bf463bf

Please sign in to comment.