Add expired flag to share details

This commit is contained in:
eikek 2021-10-02 23:05:19 +02:00
parent c7d587bea4
commit 4ef9d6c3ff
3 changed files with 16 additions and 7 deletions

View File

@ -4226,6 +4226,7 @@ components:
- publishUntil
- password
- views
- expired
properties:
id:
type: string
@ -4243,6 +4244,8 @@ components:
publishUntil:
type: integer
format: date-time
expired:
type: boolean
password:
type: boolean
views:

View File

@ -9,15 +9,13 @@ package docspell.restserver.routes
import cats.data.OptionT
import cats.effect._
import cats.implicits._
import docspell.backend.BackendApp
import docspell.backend.auth.AuthToken
import docspell.backend.ops.OShare
import docspell.common.Ident
import docspell.common.{Ident, Timestamp}
import docspell.restapi.model._
import docspell.restserver.http4s.ResponseGenerator
import docspell.store.records.RShare
import org.http4s.HttpRoutes
import org.http4s.circe.CirceEntityDecoder._
import org.http4s.circe.CirceEntityEncoder._
@ -33,7 +31,8 @@ object ShareRoutes {
case GET -> Root =>
for {
all <- backend.share.findAll(user.account.collective)
res <- Ok(ShareList(all.map(mkShareDetail)))
now <- Timestamp.current[F]
res <- Ok(ShareList(all.map(mkShareDetail(now))))
} yield res
case req @ POST -> Root =>
@ -47,7 +46,8 @@ object ShareRoutes {
case GET -> Root / Ident(id) =>
(for {
share <- backend.share.findOne(id, user.account.collective)
resp <- OptionT.liftF(Ok(mkShareDetail(share)))
now <- OptionT.liftF(Timestamp.current[F])
resp <- OptionT.liftF(Ok(mkShareDetail(now)(share)))
} yield resp).getOrElseF(NotFound())
case req @ PUT -> Root / Ident(id) =>
@ -90,7 +90,7 @@ object ShareRoutes {
BasicResult(false, "Until date must not be in the past")
}
def mkShareDetail(r: RShare): ShareDetail =
def mkShareDetail(now: Timestamp)(r: RShare): ShareDetail =
ShareDetail(
r.id,
r.query,
@ -98,8 +98,10 @@ object ShareRoutes {
r.enabled,
r.publishAt,
r.publishUntil,
now > r.publishUntil,
r.password.isDefined,
r.views,
r.lastAccess
)
}

View File

@ -102,7 +102,11 @@ object RShare {
)
def findAllByCollective(cid: Ident): ConnectionIO[List[RShare]] =
Select(select(T.all), from(T), T.cid === cid).build.query[RShare].to[List]
Select(select(T.all), from(T), T.cid === cid)
.orderBy(T.publishedAt.desc)
.build
.query[RShare]
.to[List]
def deleteByIdAndCid(id: Ident, cid: Ident): ConnectionIO[Int] =
DML.delete(T, T.id === id && T.cid === cid)