From 76ad708111c2d53f10d8bb812265c4df9f556470 Mon Sep 17 00:00:00 2001 From: eikek Date: Mon, 17 Jan 2022 17:53:31 +0100 Subject: [PATCH] Update sbt-openapi-schema plugin to 0.9.0 --- .../src/main/resources/docspell-openapi.yml | 6 +-- .../restserver/conv/NonEmptyListSupport.scala | 20 +++++++++ .../routes/AttachmentMultiRoutes.scala | 6 +-- .../restserver/routes/CollectiveRoutes.scala | 4 +- .../restserver/routes/ItemMultiRoutes.scala | 44 +++++++++---------- .../restserver/routes/ItemRoutes.scala | 3 +- .../restserver/routes/MailSendRoutes.scala | 3 +- .../restserver/routes/UserRoutes.scala | 2 +- project/plugins.sbt | 2 +- 9 files changed, 53 insertions(+), 37 deletions(-) create mode 100644 modules/restserver/src/main/scala/docspell/restserver/conv/NonEmptyListSupport.scala diff --git a/modules/restapi/src/main/resources/docspell-openapi.yml b/modules/restapi/src/main/resources/docspell-openapi.yml index 3a0716d4..db9cf7ec 100644 --- a/modules/restapi/src/main/resources/docspell-openapi.yml +++ b/modules/restapi/src/main/resources/docspell-openapi.yml @@ -5567,7 +5567,6 @@ components: type: array items: type: string - format: ident ShareSecret: description: | @@ -5811,8 +5810,8 @@ components: ItemsAndRefs: description: | - Holds a list of item ids and a list of ids of some other - related entity (e.g. tags). + Holds a list of item ids and a list of names or ids of some + other related entity (e.g. tags). required: - items - refs @@ -5826,7 +5825,6 @@ components: type: array items: type: string - format: ident ItemsAndRef: description: | Holds a list of item ids and a single optional id of some diff --git a/modules/restserver/src/main/scala/docspell/restserver/conv/NonEmptyListSupport.scala b/modules/restserver/src/main/scala/docspell/restserver/conv/NonEmptyListSupport.scala new file mode 100644 index 00000000..ca64a378 --- /dev/null +++ b/modules/restserver/src/main/scala/docspell/restserver/conv/NonEmptyListSupport.scala @@ -0,0 +1,20 @@ +/* + * Copyright 2020 Eike K. & Contributors + * + * SPDX-License-Identifier: AGPL-3.0-or-later + */ + +package docspell.restserver.conv + +import cats.data.NonEmptyList +import cats.effect._ + +trait NonEmptyListSupport { + + def requireNonEmpty[F[_]: Sync, A](list: List[A]): F[NonEmptyList[A]] = + NonEmptyList.fromList(list) match { + case Some(nel) => Sync[F].pure(nel) + case None => + Sync[F].raiseError(new IllegalArgumentException("Empty list not allowed")) + } +} diff --git a/modules/restserver/src/main/scala/docspell/restserver/routes/AttachmentMultiRoutes.scala b/modules/restserver/src/main/scala/docspell/restserver/routes/AttachmentMultiRoutes.scala index c6327b21..6a0baa9e 100644 --- a/modules/restserver/src/main/scala/docspell/restserver/routes/AttachmentMultiRoutes.scala +++ b/modules/restserver/src/main/scala/docspell/restserver/routes/AttachmentMultiRoutes.scala @@ -12,14 +12,14 @@ import cats.implicits._ import docspell.backend.BackendApp import docspell.backend.auth.AuthToken import docspell.restapi.model._ -import docspell.restserver.conv.MultiIdSupport +import docspell.restserver.conv.NonEmptyListSupport import org.http4s.HttpRoutes import org.http4s.circe.CirceEntityDecoder._ import org.http4s.circe.CirceEntityEncoder._ import org.http4s.dsl.Http4sDsl -object AttachmentMultiRoutes extends MultiIdSupport { +object AttachmentMultiRoutes extends NonEmptyListSupport { def apply[F[_]: Async]( backend: BackendApp[F], @@ -32,7 +32,7 @@ object AttachmentMultiRoutes extends MultiIdSupport { HttpRoutes.of { case req @ POST -> Root / "delete" => for { json <- req.as[IdList] - attachments <- readIds[F](json.ids) + attachments <- requireNonEmpty(json.ids) n <- backend.item.deleteAttachmentMultiple(attachments, user.account.collective) res = BasicResult( n > 0, diff --git a/modules/restserver/src/main/scala/docspell/restserver/routes/CollectiveRoutes.scala b/modules/restserver/src/main/scala/docspell/restserver/routes/CollectiveRoutes.scala index f1cd03d8..e4f99565 100644 --- a/modules/restserver/src/main/scala/docspell/restserver/routes/CollectiveRoutes.scala +++ b/modules/restserver/src/main/scala/docspell/restserver/routes/CollectiveRoutes.scala @@ -62,7 +62,7 @@ object CollectiveRoutes { settings.emptyTrash.minAge ) ), - settings.passwords.map(Password.apply) + settings.passwords ) res <- backend.collective @@ -90,7 +90,7 @@ object CollectiveRoutes { trash.schedule, trash.minAge ), - settDb.map(_.passwords).getOrElse(Nil).map(_.pass) + settDb.map(_.passwords).getOrElse(Nil) ) ) resp <- sett.toResponse() diff --git a/modules/restserver/src/main/scala/docspell/restserver/routes/ItemMultiRoutes.scala b/modules/restserver/src/main/scala/docspell/restserver/routes/ItemMultiRoutes.scala index bc2dafc0..7c2887fb 100644 --- a/modules/restserver/src/main/scala/docspell/restserver/routes/ItemMultiRoutes.scala +++ b/modules/restserver/src/main/scala/docspell/restserver/routes/ItemMultiRoutes.scala @@ -15,7 +15,7 @@ import docspell.backend.ops.OCustomFields.{RemoveValue, SetValue} import docspell.common._ import docspell.restapi.model._ import docspell.restserver.Config -import docspell.restserver.conv.{Conversions, MultiIdSupport} +import docspell.restserver.conv.{Conversions, MultiIdSupport, NonEmptyListSupport} import docspell.restserver.http4s.ClientRequestInfo import org.http4s.HttpRoutes @@ -24,7 +24,7 @@ import org.http4s.circe.CirceEntityEncoder._ import org.http4s.dsl.Http4sDsl import org.log4s.getLogger -object ItemMultiRoutes extends MultiIdSupport { +object ItemMultiRoutes extends NonEmptyListSupport with MultiIdSupport { private[this] val log4sLogger = getLogger def apply[F[_]: Async]( @@ -39,7 +39,7 @@ object ItemMultiRoutes extends MultiIdSupport { case req @ PUT -> Root / "confirm" => for { json <- req.as[IdList] - data <- readIds[F](json.ids) + data <- requireNonEmpty(json.ids) res <- backend.item.setStates( data, ItemState.Confirmed, @@ -51,7 +51,7 @@ object ItemMultiRoutes extends MultiIdSupport { case req @ PUT -> Root / "unconfirm" => for { json <- req.as[IdList] - data <- readIds[F](json.ids) + data <- requireNonEmpty(json.ids) res <- backend.item.setStates( data, ItemState.Created, @@ -63,7 +63,7 @@ object ItemMultiRoutes extends MultiIdSupport { case req @ PUT -> Root / "tags" => for { json <- req.as[ItemsAndRefs] - items <- readIds[F](json.items) + items <- requireNonEmpty(json.items) res <- backend.item.setTagsMultipleItems( items, json.refs, @@ -77,7 +77,7 @@ object ItemMultiRoutes extends MultiIdSupport { case req @ POST -> Root / "tags" => for { json <- req.as[ItemsAndRefs] - items <- readIds[F](json.items) + items <- requireNonEmpty(json.items) res <- backend.item.linkTagsMultipleItems( items, json.refs, @@ -91,7 +91,7 @@ object ItemMultiRoutes extends MultiIdSupport { case req @ POST -> Root / "tagsremove" => for { json <- req.as[ItemsAndRefs] - items <- readIds[F](json.items) + items <- requireNonEmpty(json.items) res <- backend.item.removeTagsMultipleItems( items, json.refs, @@ -105,7 +105,7 @@ object ItemMultiRoutes extends MultiIdSupport { case req @ PUT -> Root / "name" => for { json <- req.as[ItemsAndName] - items <- readIds[F](json.items) + items <- requireNonEmpty(json.items) res <- backend.item.setNameMultiple( items, json.name.notEmpty.getOrElse(""), @@ -117,7 +117,7 @@ object ItemMultiRoutes extends MultiIdSupport { case req @ PUT -> Root / "folder" => for { json <- req.as[ItemsAndRef] - items <- readIds[F](json.items) + items <- requireNonEmpty(json.items) res <- backend.item.setFolderMultiple(items, json.ref, user.account.collective) resp <- Ok(Conversions.basicResult(res, "Folder updated")) } yield resp @@ -125,7 +125,7 @@ object ItemMultiRoutes extends MultiIdSupport { case req @ PUT -> Root / "direction" => for { json <- req.as[ItemsAndDirection] - items <- readIds[F](json.items) + items <- requireNonEmpty(json.items) res <- backend.item.setDirection(items, json.direction, user.account.collective) resp <- Ok(Conversions.basicResult(res, "Direction updated")) } yield resp @@ -133,7 +133,7 @@ object ItemMultiRoutes extends MultiIdSupport { case req @ PUT -> Root / "date" => for { json <- req.as[ItemsAndDate] - items <- readIds[F](json.items) + items <- requireNonEmpty(json.items) res <- backend.item.setItemDate(items, json.date, user.account.collective) resp <- Ok(Conversions.basicResult(res, "Item date updated")) } yield resp @@ -141,7 +141,7 @@ object ItemMultiRoutes extends MultiIdSupport { case req @ PUT -> Root / "duedate" => for { json <- req.as[ItemsAndDate] - items <- readIds[F](json.items) + items <- requireNonEmpty(json.items) res <- backend.item.setItemDueDate(items, json.date, user.account.collective) resp <- Ok(Conversions.basicResult(res, "Item due date updated")) } yield resp @@ -149,7 +149,7 @@ object ItemMultiRoutes extends MultiIdSupport { case req @ PUT -> Root / "corrOrg" => for { json <- req.as[ItemsAndRef] - items <- readIds[F](json.items) + items <- requireNonEmpty(json.items) res <- backend.item.setCorrOrg(items, json.ref, user.account.collective) resp <- Ok(Conversions.basicResult(res, "Correspondent organization updated")) } yield resp @@ -157,7 +157,7 @@ object ItemMultiRoutes extends MultiIdSupport { case req @ PUT -> Root / "corrPerson" => for { json <- req.as[ItemsAndRef] - items <- readIds[F](json.items) + items <- requireNonEmpty(json.items) res <- backend.item.setCorrPerson(items, json.ref, user.account.collective) resp <- Ok(Conversions.basicResult(res, "Correspondent person updated")) } yield resp @@ -165,7 +165,7 @@ object ItemMultiRoutes extends MultiIdSupport { case req @ PUT -> Root / "concPerson" => for { json <- req.as[ItemsAndRef] - items <- readIds[F](json.items) + items <- requireNonEmpty(json.items) res <- backend.item.setConcPerson(items, json.ref, user.account.collective) resp <- Ok(Conversions.basicResult(res, "Concerned person updated")) } yield resp @@ -173,7 +173,7 @@ object ItemMultiRoutes extends MultiIdSupport { case req @ PUT -> Root / "concEquipment" => for { json <- req.as[ItemsAndRef] - items <- readIds[F](json.items) + items <- requireNonEmpty(json.items) res <- backend.item.setConcEquip(items, json.ref, user.account.collective) resp <- Ok(Conversions.basicResult(res, "Concerned equipment updated")) } yield resp @@ -181,7 +181,7 @@ object ItemMultiRoutes extends MultiIdSupport { case req @ POST -> Root / "reprocess" => for { json <- req.as[IdList] - items <- readIds[F](json.ids) + items <- requireNonEmpty(json.ids) res <- backend.item.reprocessAll(items, user.account, true) resp <- Ok(Conversions.basicResult(res, "Re-process task(s) submitted.")) } yield resp @@ -189,7 +189,7 @@ object ItemMultiRoutes extends MultiIdSupport { case req @ POST -> Root / "deleteAll" => for { json <- req.as[IdList] - items <- readIds[F](json.ids) + items <- requireNonEmpty(json.ids) n <- backend.item.setDeletedState(items, user.account.collective) res = BasicResult( n > 0, @@ -201,7 +201,7 @@ object ItemMultiRoutes extends MultiIdSupport { case req @ POST -> Root / "restoreAll" => for { json <- req.as[IdList] - items <- readIds[F](json.ids) + items <- requireNonEmpty(json.ids) res <- backend.item.restore(items, user.account.collective) resp <- Ok(Conversions.basicResult(res, "Item(s) deleted")) } yield resp @@ -209,7 +209,7 @@ object ItemMultiRoutes extends MultiIdSupport { case req @ PUT -> Root / "customfield" => for { json <- req.as[ItemsAndFieldValue] - items <- readIds[F](json.items) + items <- requireNonEmpty(json.items) res <- backend.customFields.setValueMultiple( items, SetValue(json.field.field, json.field.value, user.account.collective) @@ -222,7 +222,7 @@ object ItemMultiRoutes extends MultiIdSupport { case req @ POST -> Root / "customfieldremove" => for { json <- req.as[ItemsAndName] - items <- readIds[F](json.items) + items <- requireNonEmpty(json.items) field <- readId[F](json.name) res <- backend.customFields.deleteValue( RemoveValue(field, items, user.account.collective) @@ -235,7 +235,7 @@ object ItemMultiRoutes extends MultiIdSupport { case req @ POST -> Root / "merge" => for { json <- req.as[IdList] - items <- readIds[F](json.ids) + items <- requireNonEmpty(json.ids) logger = Logger.log4s(log4sLogger) res <- backend.item.merge(logger, items, user.account.collective) resp <- Ok(Conversions.basicResult(res, "Items merged")) diff --git a/modules/restserver/src/main/scala/docspell/restserver/routes/ItemRoutes.scala b/modules/restserver/src/main/scala/docspell/restserver/routes/ItemRoutes.scala index a2ff4ff9..b4b3c0f6 100644 --- a/modules/restserver/src/main/scala/docspell/restserver/routes/ItemRoutes.scala +++ b/modules/restserver/src/main/scala/docspell/restserver/routes/ItemRoutes.scala @@ -390,9 +390,8 @@ object ItemRoutes { case req @ POST -> Root / Ident(id) / "reprocess" => for { data <- req.as[IdList] - ids = data.ids.flatMap(s => Ident.fromString(s).toOption) _ <- logger.fdebug(s"Re-process item ${id.id}") - res <- backend.item.reprocess(id, ids, user.account, true) + res <- backend.item.reprocess(id, data.ids, user.account, true) resp <- Ok(Conversions.basicResult(res, "Re-process task submitted.")) } yield resp diff --git a/modules/restserver/src/main/scala/docspell/restserver/routes/MailSendRoutes.scala b/modules/restserver/src/main/scala/docspell/restserver/routes/MailSendRoutes.scala index 798dd719..f0e44909 100644 --- a/modules/restserver/src/main/scala/docspell/restserver/routes/MailSendRoutes.scala +++ b/modules/restserver/src/main/scala/docspell/restserver/routes/MailSendRoutes.scala @@ -46,10 +46,9 @@ object MailSendRoutes { rec <- s.recipients.traverse(MailAddress.parse) cc <- s.cc.traverse(MailAddress.parse) bcc <- s.bcc.traverse(MailAddress.parse) - fileIds <- s.attachmentIds.traverse(Ident.fromString) sel = if (s.addAllAttachments) AttachSelection.All - else AttachSelection.Selected(fileIds) + else AttachSelection.Selected(s.attachmentIds) } yield ItemMail(item, s.subject, rec, cc, bcc, s.body, sel) def convertOut(res: SendResult): BasicResult = diff --git a/modules/restserver/src/main/scala/docspell/restserver/routes/UserRoutes.scala b/modules/restserver/src/main/scala/docspell/restserver/routes/UserRoutes.scala index ef4d75d8..591c124b 100644 --- a/modules/restserver/src/main/scala/docspell/restserver/routes/UserRoutes.scala +++ b/modules/restserver/src/main/scala/docspell/restserver/routes/UserRoutes.scala @@ -73,7 +73,7 @@ object UserRoutes { AccountId(user.account.collective, username) ) resp <- Ok( - DeleteUserData(data.ownedFolders.map(_.id), data.sentMails, data.shares) + DeleteUserData(data.ownedFolders, data.sentMails, data.shares) ) } yield resp } diff --git a/project/plugins.sbt b/project/plugins.sbt index a6d3dbc7..c4006806 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -1,6 +1,6 @@ addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.9.34") addSbtPlugin("com.eed3si9n" % "sbt-buildinfo" % "0.10.0") -addSbtPlugin("com.github.eikek" % "sbt-openapi-schema" % "0.8.2") +addSbtPlugin("com.github.eikek" % "sbt-openapi-schema" % "0.9.0") addSbtPlugin("com.github.sbt" % "sbt-pgp" % "2.1.2") addSbtPlugin("com.github.sbt" % "sbt-release" % "1.1.0") addSbtPlugin("com.typesafe.sbt" % "sbt-git" % "1.0.2")