From 05ed96b2cc54abfd580362990aded43454226e83 Mon Sep 17 00:00:00 2001 From: eikek Date: Mon, 14 Nov 2022 11:07:14 +0100 Subject: [PATCH] Fix querying shares without a name Fixes: #1840 --- .../src/main/scala/docspell/common/syntax/StringSyntax.scala | 5 +++++ .../main/scala/docspell/restserver/routes/ShareRoutes.scala | 3 ++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/modules/common/src/main/scala/docspell/common/syntax/StringSyntax.scala b/modules/common/src/main/scala/docspell/common/syntax/StringSyntax.scala index d1e27c4b..df704e1c 100644 --- a/modules/common/src/main/scala/docspell/common/syntax/StringSyntax.scala +++ b/modules/common/src/main/scala/docspell/common/syntax/StringSyntax.scala @@ -17,6 +17,11 @@ trait StringSyntax { def parseJsonAs[A](implicit d: Decoder[A]): Either[Throwable, A] = parser.decode[A](s) } + + implicit class OptionStringOpts(s: Option[String]) { + def asNonBlank: Option[String] = + s.filter(_.trim.nonEmpty) + } } object StringSyntax extends StringSyntax diff --git a/modules/restserver/src/main/scala/docspell/restserver/routes/ShareRoutes.scala b/modules/restserver/src/main/scala/docspell/restserver/routes/ShareRoutes.scala index a8fd11da..d40b766f 100644 --- a/modules/restserver/src/main/scala/docspell/restserver/routes/ShareRoutes.scala +++ b/modules/restserver/src/main/scala/docspell/restserver/routes/ShareRoutes.scala @@ -14,6 +14,7 @@ import docspell.backend.BackendApp import docspell.backend.auth.AuthToken import docspell.backend.ops.OShare import docspell.backend.ops.OShare.{SendResult, ShareMail, VerifyResult} +import docspell.common.syntax.string._ import docspell.common.{Ident, Timestamp} import docspell.restapi.model._ import docspell.restserver.Config @@ -37,7 +38,7 @@ object ShareRoutes { case GET -> Root :? QP.Query(q) :? QP.OwningFlag(owning) => val login = if (owning) Some(user.account.login) else None for { - all <- backend.share.findAll(user.account.collectiveId, login, q) + all <- backend.share.findAll(user.account.collectiveId, login, q.asNonBlank) now <- Timestamp.current[F] res <- Ok(ShareList(all.map(mkShareDetail(now)))) } yield res