mirror of
https://github.com/TheAnachronism/docspell.git
synced 2025-06-02 13:32:51 +00:00
Include links to items into mail template
This commit is contained in:
parent
52800a51d8
commit
e1f9ae2629
@ -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])
|
||||
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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]
|
||||
|
@ -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]
|
||||
|
||||
|
@ -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}}
|
||||
|
||||
|
||||
|
@ -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 {
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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()
|
||||
)
|
||||
|
||||
|
@ -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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user