From 0fbee5101ba70b32efadf4bb6d07f61d7c7b3573 Mon Sep 17 00:00:00 2001 From: Michael Bryzek Date: Thu, 6 Jun 2024 15:45:44 -0400 Subject: [PATCH] Debug email sending for different versions (#928) --- api/app/{actors => lib}/Emails.scala | 20 +++++++++---------- .../processor/CheckInvariantsProcessor.scala | 1 - api/app/processor/DiffVersionProcessor.scala | 3 +-- api/app/processor/EmailProcessor.scala | 3 +-- api/test/{actors => lib}/EmailsSpec.scala | 3 +-- api/test/util/Daos.scala | 7 +++---- 6 files changed, 16 insertions(+), 21 deletions(-) rename api/app/{actors => lib}/Emails.scala (91%) rename api/test/{actors => lib}/EmailsSpec.scala (98%) diff --git a/api/app/actors/Emails.scala b/api/app/lib/Emails.scala similarity index 91% rename from api/app/actors/Emails.scala rename to api/app/lib/Emails.scala index 153209729..39bb3d9b1 100644 --- a/api/app/actors/Emails.scala +++ b/api/app/lib/Emails.scala @@ -1,8 +1,8 @@ -package actors +package lib import db.{ApplicationsDao, Authorization, MembershipsDao, SubscriptionsDao} import io.apibuilder.api.v0.models._ -import lib._ +import org.joda.time.DateTime import play.api.Logging import javax.inject.{Inject, Singleton} @@ -46,13 +46,13 @@ class Emails @Inject() ( implicit filter: Subscription => Boolean = { _ => true } ): Unit = { eachSubscription(context, org, publication, { subscription => - if (filter(subscription)) { - email.sendHtml( - to = Person(subscription.user), - subject = subject, - body = body - ) - } + val result = filter(subscription) + println(s"[${DateTime.now} DEBUG_FILTER] result: $result") + email.sendHtml( + to = Person(subscription.user), + subject = subject, + body = body + ) }) } @@ -80,7 +80,7 @@ class Emails @Inject() ( } } - private[actors] def isAuthorized( + private[lib] def isAuthorized( context: Emails.Context, organization: Organization, user: User diff --git a/api/app/processor/CheckInvariantsProcessor.scala b/api/app/processor/CheckInvariantsProcessor.scala index a88b4dcb4..f4aabe062 100644 --- a/api/app/processor/CheckInvariantsProcessor.scala +++ b/api/app/processor/CheckInvariantsProcessor.scala @@ -34,7 +34,6 @@ class CheckInvariantsProcessor @Inject()( private[this] def sendResults(results: Seq[InvariantResult]): Unit = { val (noErrors, withErrors) = results.partition(_.count == 0) - println(s"# Invariants checked with no errors: ${noErrors.length}") if (withErrors.nonEmpty) { lazy val subject = if (withErrors.length == 1) { "1 Error" diff --git a/api/app/processor/DiffVersionProcessor.scala b/api/app/processor/DiffVersionProcessor.scala index 9f03a334e..fb65c8e34 100644 --- a/api/app/processor/DiffVersionProcessor.scala +++ b/api/app/processor/DiffVersionProcessor.scala @@ -1,13 +1,12 @@ package processor -import actors.Emails import cats.data.ValidatedNec import cats.implicits._ import db._ import io.apibuilder.api.v0.models._ import io.apibuilder.task.v0.models.json._ import io.apibuilder.task.v0.models.{DiffVersionData, TaskType} -import lib.{AppConfig, ServiceDiff} +import lib.{AppConfig, ServiceDiff, Emails} import play.twirl.api.Html import java.util.UUID diff --git a/api/app/processor/EmailProcessor.scala b/api/app/processor/EmailProcessor.scala index 59ed14fe0..5567b4ae1 100644 --- a/api/app/processor/EmailProcessor.scala +++ b/api/app/processor/EmailProcessor.scala @@ -1,13 +1,12 @@ package processor -import actors.Emails import cats.data.ValidatedNec import cats.implicits._ import db.{Authorization, InternalTasksDao, OrganizationsDao, UsersDao} import io.apibuilder.api.v0.models.Publication import io.apibuilder.task.v0.models._ import io.apibuilder.task.v0.models.json._ -import lib.{AppConfig, EmailUtil, Person, Role} +import lib.{AppConfig, EmailUtil, Person, Emails, Role} import play.api.libs.json.Json import java.sql.Connection diff --git a/api/test/actors/EmailsSpec.scala b/api/test/lib/EmailsSpec.scala similarity index 98% rename from api/test/actors/EmailsSpec.scala rename to api/test/lib/EmailsSpec.scala index ca64477ff..8a4b71487 100644 --- a/api/test/actors/EmailsSpec.scala +++ b/api/test/lib/EmailsSpec.scala @@ -1,7 +1,6 @@ -package actors +package lib import io.apibuilder.api.v0.models.Visibility -import lib.Role import org.scalatestplus.play.PlaySpec import org.scalatestplus.play.guice.GuiceOneAppPerSuite diff --git a/api/test/util/Daos.scala b/api/test/util/Daos.scala index 537b3caae..76bdc1eed 100644 --- a/api/test/util/Daos.scala +++ b/api/test/util/Daos.scala @@ -1,10 +1,9 @@ package util -import actors.Emails +import db._ import db.generated.SessionsDao import db.generators.{GeneratorsDao, ServicesDao} -import db._ -import lib.DatabaseServiceFetcher +import lib.{DatabaseServiceFetcher, Emails} import play.api.Application import play.api.inject.Injector @@ -38,7 +37,7 @@ trait Daos { def servicesDao: ServicesDao = injector.instanceOf[db.generators.ServicesDao] def generatorsDao: GeneratorsDao = injector.instanceOf[db.generators.GeneratorsDao] - def emails: Emails = injector.instanceOf[actors.Emails] + def emails: Emails = injector.instanceOf[Emails] def sessionHelper: SessionHelper = injector.instanceOf[SessionHelper] }