Fix sending notification mails from background tasks

When looking up the mail settings, a valid user id must be given.
This commit is contained in:
eikek
2021-12-22 17:57:26 +01:00
parent 50e4c31872
commit 3a642ee01e
4 changed files with 61 additions and 27 deletions

View File

@ -7,6 +7,7 @@
package docspell.joex.notify
import cats.data.NonEmptyList
import cats.data.OptionT
import cats.effect._
import cats.implicits._
@ -23,6 +24,7 @@ import docspell.query.ItemQueryDsl._
import docspell.store.qb.Batch
import docspell.store.queries.ListItem
import docspell.store.queries.{QItem, Query}
import docspell.store.records.RUser
object PeriodicDueItemsTask {
val taskName = PeriodicDueItemsArgs.taskName
@ -49,7 +51,11 @@ object PeriodicDueItemsTask {
def withChannel[F[_]: Sync](ctx: Context[F, Args], ops: ONotification[F])(
cont: Vector[NotificationChannel] => F[Unit]
): F[Unit] =
TaskOperations.withChannel(ctx.logger, ctx.args.channel, ops)(cont)
OptionT(ctx.store.transact(RUser.findIdByAccount(ctx.args.account)))
.semiflatMap(userId =>
TaskOperations.withChannel(ctx.logger, ctx.args.channel, userId, ops)(cont)
)
.getOrElse(())
def withItems[F[_]: Sync](ctx: Context[F, Args], limit: Int, now: Timestamp)(
cont: Vector[ListItem] => F[Unit]

View File

@ -6,6 +6,7 @@
package docspell.joex.notify
import cats.data.OptionT
import cats.effect._
import cats.implicits._
@ -20,6 +21,7 @@ import docspell.query.ItemQueryParser
import docspell.store.qb.Batch
import docspell.store.queries.ListItem
import docspell.store.queries.{QItem, Query}
import docspell.store.records.RUser
object PeriodicQueryTask {
val taskName = PeriodicQueryArgs.taskName
@ -46,7 +48,11 @@ object PeriodicQueryTask {
def withChannel[F[_]: Sync](ctx: Context[F, Args], ops: ONotification[F])(
cont: Vector[NotificationChannel] => F[Unit]
): F[Unit] =
TaskOperations.withChannel(ctx.logger, ctx.args.channel, ops)(cont)
OptionT(ctx.store.transact(RUser.findIdByAccount(ctx.args.account)))
.semiflatMap(userId =>
TaskOperations.withChannel(ctx.logger, ctx.args.channel, userId, ops)(cont)
)
.getOrElse(())
def withItems[F[_]: Sync](ctx: Context[F, Args], limit: Int, now: Timestamp)(
cont: Vector[ListItem] => F[Unit]

View File

@ -24,12 +24,13 @@ trait TaskOperations {
def withChannel[F[_]: Sync](
logger: Logger[F],
channel: ChannelOrRef,
userId: Ident,
ops: ONotification[F]
)(
cont: Vector[NotificationChannel] => F[Unit]
): F[Unit] = {
val channels = channel match {
case Right(ch) => ops.mkNotificationChannel(ch)
case Right(ch) => ops.mkNotificationChannel(ch, userId)
case Left(ref) => ops.findNotificationChannel(ref)
}
channels.flatMap { ch =>