Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Désactive les emails pour les utilisateurs inactifs #2097

Merged
merged 1 commit into from
Oct 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 40 additions & 20 deletions app/services/NotificationService.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import cats.syntax.all._
import constants.Constants
import controllers.routes
import helper.EmailHelper.quoteEmailPhrase
import java.time.ZoneId
import java.time.{Instant, ZoneId}
import java.util.UUID
import javax.inject.{Inject, Singleton}
import models._
Expand Down Expand Up @@ -70,9 +70,18 @@ class NotificationService @Inject() (
.byIds(application.invitedGroupIdsAtCreation)
.filter(_.email.nonEmpty)

users
.map(generateInvitationEmail(application))
.foreach(email => emailsService.sendBlocking(email, EmailPriority.Normal))
eventService.lastActivity(users.map(_.id)).foreach { lastActivityResult =>
val lastActivity: Map[UUID, Instant] = lastActivityResult.getOrElse(Nil).toMap
users
.filter(user =>
lastActivity
.get(user.id)
.map(_.isAfter(Instant.now().minusSeconds(365 * 24 * 60 * 60)))
.getOrElse(false)
)
.map(generateInvitationEmail(application))
.foreach(email => emailsService.sendBlocking(email, EmailPriority.Normal))
}

groups
.map(generateNotificationBALEmail(application, None, users))
Expand All @@ -97,23 +106,32 @@ class NotificationService @Inject() (
}

// Send emails to users
users
.flatMap { user =>
if (user.id === answer.creatorUserID) {
None
} else if (
!Authorization.canSeeAnswer(answer, application)(Authorization.readUserRights(user))
) {
None
} else if (!user.instructor) { // Temporary case
None
} else if (answer.invitedUsers.contains(user.id)) {
Some(generateInvitationEmail(application, Some(answer))(user))
} else {
Some(generateAnswerEmail(application, answer)(user))
eventService.lastActivity(users.map(_.id)).foreach { lastActivityResult =>
val lastActivity: Map[UUID, Instant] = lastActivityResult.getOrElse(Nil).toMap
users
.filter(user =>
lastActivity
.get(user.id)
.map(_.isAfter(Instant.now().minusSeconds(365 * 24 * 60 * 60)))
.getOrElse(false)
)
.flatMap { user =>
if (user.id === answer.creatorUserID) {
None
} else if (
!Authorization.canSeeAnswer(answer, application)(Authorization.readUserRights(user))
) {
None
} else if (!user.instructor) { // Temporary case
None
} else if (answer.invitedUsers.contains(user.id)) {
Some(generateInvitationEmail(application, Some(answer))(user))
} else {
Some(generateAnswerEmail(application, answer)(user))
}
}
}
.foreach(email => emailsService.sendBlocking(email, EmailPriority.Normal))
.foreach(email => emailsService.sendBlocking(email, EmailPriority.Normal))
}

val usersEmails: Set[String] = users.map(_.email).toSet

Expand All @@ -130,10 +148,12 @@ class NotificationService @Inject() (
.foreach(email => emailsService.sendBlocking(email, EmailPriority.Normal))

if (answer.visibleByHelpers && answer.creatorUserID =!= application.creatorUserId) {
/* This is a temporary comment
userService
.byId(application.creatorUserId)
.map(generateAnswerEmail(application, answer))
.foreach(email => emailsService.sendBlocking(email, EmailPriority.Normal))
*/
}
}
}
Expand Down