diff --git a/modules/backend/src/main/scala/docspell/backend/Config.scala b/modules/backend/src/main/scala/docspell/backend/Config.scala index ed0837bb..e87a4613 100644 --- a/modules/backend/src/main/scala/docspell/backend/Config.scala +++ b/modules/backend/src/main/scala/docspell/backend/Config.scala @@ -1,7 +1,7 @@ package docspell.backend import docspell.backend.signup.{Config => SignupConfig} -import docspell.common.MimeType +import docspell.common._ import docspell.store.JdbcConfig case class Config(jdbc: JdbcConfig, signup: SignupConfig, files: Config.Files) {} @@ -9,4 +9,5 @@ case class Config(jdbc: JdbcConfig, signup: SignupConfig, files: Config.Files) { object Config { case class Files(chunkSize: Int, validMimeTypes: Seq[MimeType]) + } diff --git a/modules/backend/src/main/scala/docspell/backend/ops/OUserTask.scala b/modules/backend/src/main/scala/docspell/backend/ops/OUserTask.scala index 3d5d6790..2a07b187 100644 --- a/modules/backend/src/main/scala/docspell/backend/ops/OUserTask.scala +++ b/modules/backend/src/main/scala/docspell/backend/ops/OUserTask.scala @@ -4,6 +4,7 @@ import cats.implicits._ import cats.effect._ import com.github.eikek.calev.CalEvent import io.circe.Encoder + import docspell.store.queue.JobQueue import docspell.store.usertask._ import docspell.common._ @@ -45,9 +46,9 @@ object OUserTask { ): F[Unit] = for { ptask <- task.encode.toPeriodicTask(account) - job <- ptask.toJob - _ <- queue.insert(job) - _ <- joex.notifyAllNodes + job <- ptask.toJob + _ <- queue.insert(job) + _ <- joex.notifyAllNodes } yield () def getNotifyDueItems(account: AccountId): F[UserTask[NotifyDueItemsArgs]] = @@ -76,8 +77,9 @@ object OUserTask { CalEvent.unsafe("*-*-1/7 12:00"), NotifyDueItemsArgs( account, - Ident.unsafe("none"), + Ident.unsafe(""), Nil, + None, 5, Nil, Nil diff --git a/modules/common/src/main/scala/docspell/common/NotifyDueItemsArgs.scala b/modules/common/src/main/scala/docspell/common/NotifyDueItemsArgs.scala index af86bce9..9e6c3264 100644 --- a/modules/common/src/main/scala/docspell/common/NotifyDueItemsArgs.scala +++ b/modules/common/src/main/scala/docspell/common/NotifyDueItemsArgs.scala @@ -15,6 +15,7 @@ case class NotifyDueItemsArgs( account: AccountId, smtpConnection: Ident, recipients: List[String], + itemDetailUrl: Option[LenientUri], remindDays: Int, tagsInclude: List[Ident], tagsExclude: List[Ident] diff --git a/modules/joex/src/main/scala/docspell/joex/notify/MailContext.scala b/modules/joex/src/main/scala/docspell/joex/notify/MailContext.scala index bf6f352d..d00d07a2 100644 --- a/modules/joex/src/main/scala/docspell/joex/notify/MailContext.scala +++ b/modules/joex/src/main/scala/docspell/joex/notify/MailContext.scala @@ -7,15 +7,26 @@ import docspell.common._ import docspell.store.queries.QItem import docspell.joex.notify.YamuscaConverter._ -case class MailContext(items: List[MailContext.ItemData], more: Boolean, account: AccountId) +case class MailContext( + items: List[MailContext.ItemData], + more: Boolean, + account: AccountId, + itemUri: Option[LenientUri] +) object MailContext { - def from(items: Vector[QItem.ListItem], max: Int, account: AccountId): MailContext = + def from( + items: Vector[QItem.ListItem], + max: Int, + account: AccountId, + itemBaseUri: Option[LenientUri] + ): MailContext = MailContext( items.take(max - 1).map(ItemData.apply).toList.sortBy(_.dueDate), items.sizeCompare(max) >= 0, - account + account, + itemBaseUri ) case class ItemData( @@ -35,7 +46,6 @@ object MailContext { ValueConverter.deriveConverter[ItemData] } - implicit val yamusca: ValueConverter[MailContext] = ValueConverter.deriveConverter[MailContext] diff --git a/modules/joex/src/main/scala/docspell/joex/notify/MailTemplate.scala b/modules/joex/src/main/scala/docspell/joex/notify/MailTemplate.scala index bb8cbe6e..7824f281 100644 --- a/modules/joex/src/main/scala/docspell/joex/notify/MailTemplate.scala +++ b/modules/joex/src/main/scala/docspell/joex/notify/MailTemplate.scala @@ -9,12 +9,20 @@ object MailTemplate { this is Docspell informing you about due items coming up. +{{#itemUri}} +{{#items}} +- [{{name}}]({{itemUri}}/{{id}}), due on *{{dueDate}}* + (received on {{date}} via {{source}}) +{{/items}} +{{/itemUri}} +{{^itemUri}} {{#items}} - *{{name}}*, due on *{{dueDate}}* (received on {{date}} via {{source}}) {{/items}} +{{/itemUri}} {{#more}} -- ... +- (There are more due items, left out for brevity) {{/more}} diff --git a/modules/joex/src/main/scala/docspell/joex/notify/NotifyDueItemsTask.scala b/modules/joex/src/main/scala/docspell/joex/notify/NotifyDueItemsTask.scala index 8ad7364c..de780e48 100644 --- a/modules/joex/src/main/scala/docspell/joex/notify/NotifyDueItemsTask.scala +++ b/modules/joex/src/main/scala/docspell/joex/notify/NotifyDueItemsTask.scala @@ -83,8 +83,9 @@ object NotifyDueItemsTask { args: Args, items: Vector[QItem.ListItem] ): F[Mail[F]] = Sync[F].delay { - val templateCtx = MailContext.from(items, maxItems.toInt - 1, args.account) - val md = MailTemplate.render(templateCtx) + val templateCtx = + MailContext.from(items, maxItems.toInt, args.account, args.itemDetailUrl) + val md = MailTemplate.render(templateCtx) val recp = args.recipients .map(MailAddress.parse) .map { diff --git a/modules/restserver/src/main/scala/docspell/restserver/Config.scala b/modules/restserver/src/main/scala/docspell/restserver/Config.scala index 12601095..95688331 100644 --- a/modules/restserver/src/main/scala/docspell/restserver/Config.scala +++ b/modules/restserver/src/main/scala/docspell/restserver/Config.scala @@ -1,11 +1,8 @@ package docspell.restserver import docspell.backend.auth.Login -import docspell.backend.signup.{Config => SignupConfig} -import docspell.store.JdbcConfig import docspell.backend.{Config => BackendConfig} import docspell.common._ -import scodec.bits.ByteVector case class Config( appName: String, @@ -17,33 +14,6 @@ case class Config( ) object Config { - val postgres = - JdbcConfig( - LenientUri.unsafe("jdbc:postgresql://localhost:5432/docspelldev"), - "dev", - "dev" - ) - val h2 = JdbcConfig( - LenientUri.unsafe( - "jdbc:h2:./target/docspelldev.db;MODE=PostgreSQL;DATABASE_TO_LOWER=TRUE" - ), - "sa", - "" - ) - - val default: Config = - Config( - "Docspell", - Ident.unsafe("restserver1"), - LenientUri.unsafe("http://localhost:7880"), - Config.Bind("localhost", 7880), - BackendConfig( - postgres, - SignupConfig(SignupConfig.invite, Password("testpass"), Duration.hours(5 * 24)), - BackendConfig.Files(512 * 1024, List(MimeType.pdf)) - ), - Login.Config(ByteVector.fromValidHex("caffee"), Duration.minutes(2)) - ) case class Bind(address: String, port: Int) } diff --git a/modules/restserver/src/main/scala/docspell/restserver/RestServer.scala b/modules/restserver/src/main/scala/docspell/restserver/RestServer.scala index 59e08582..53ee45e3 100644 --- a/modules/restserver/src/main/scala/docspell/restserver/RestServer.scala +++ b/modules/restserver/src/main/scala/docspell/restserver/RestServer.scala @@ -76,7 +76,7 @@ object RestServer { "email/send" -> MailSendRoutes(restApp.backend, token), "email/settings" -> MailSettingsRoutes(restApp.backend, token), "email/sent" -> SentMailRoutes(restApp.backend, token), - "usertask/notifydueitems" -> NotifyDueItemsRoutes(restApp.backend, token), + "usertask/notifydueitems" -> NotifyDueItemsRoutes(cfg, restApp.backend, token), "calevent/check" -> CalEventCheckRoutes() ) diff --git a/modules/restserver/src/main/scala/docspell/restserver/routes/NotifyDueItemsRoutes.scala b/modules/restserver/src/main/scala/docspell/restserver/routes/NotifyDueItemsRoutes.scala index ab955d03..fe654fdd 100644 --- a/modules/restserver/src/main/scala/docspell/restserver/routes/NotifyDueItemsRoutes.scala +++ b/modules/restserver/src/main/scala/docspell/restserver/routes/NotifyDueItemsRoutes.scala @@ -13,10 +13,15 @@ import docspell.common._ import docspell.restapi.model._ import docspell.store.usertask._ import docspell.restserver.conv.Conversions +import docspell.restserver.Config object NotifyDueItemsRoutes { - def apply[F[_]: Effect](backend: BackendApp[F], user: AuthToken): HttpRoutes[F] = { + def apply[F[_]: Effect]( + cfg: Config, + backend: BackendApp[F], + user: AuthToken + ): HttpRoutes[F] = { val dsl = new Http4sDsl[F] {} val ut = backend.userTask import dsl._ @@ -25,7 +30,7 @@ object NotifyDueItemsRoutes { case req @ POST -> Root / "startonce" => for { data <- req.as[NotificationSettings] - task = makeTask(user.account, data) + task = makeTask(cfg, user.account, data) res <- ut .executeNow(user.account, task) .attempt @@ -43,7 +48,7 @@ object NotifyDueItemsRoutes { case req @ POST -> Root => for { data <- req.as[NotificationSettings] - task = makeTask(user.account, data) + task = makeTask(cfg, user.account, data) res <- ut .submitNotifyDueItems(user.account, task) .attempt @@ -54,6 +59,7 @@ object NotifyDueItemsRoutes { } def makeTask( + cfg: Config, user: AccountId, settings: NotificationSettings ): UserTask[NotifyDueItemsArgs] = @@ -66,6 +72,7 @@ object NotifyDueItemsRoutes { user, settings.smtpConnection, settings.recipients, + Some(cfg.baseUrl / "app" / "item"), settings.remindDays, settings.tagsInclude.map(_.id), settings.tagsExclude.map(_.id)