mirror of
https://github.com/TheAnachronism/docspell.git
synced 2025-06-04 14:15:59 +00:00
Merge pull request #218 from eikek/upload-check
Fail early when source id is wrong
This commit is contained in:
commit
795b8edb51
@ -8,7 +8,7 @@ import docspell.backend.PasswordCrypt
|
|||||||
import docspell.backend.ops.OCollective._
|
import docspell.backend.ops.OCollective._
|
||||||
import docspell.common._
|
import docspell.common._
|
||||||
import docspell.store.queries.QCollective
|
import docspell.store.queries.QCollective
|
||||||
import docspell.store.records.{RCollective, RContact, RUser}
|
import docspell.store.records._
|
||||||
import docspell.store.{AddResult, Store}
|
import docspell.store.{AddResult, Store}
|
||||||
|
|
||||||
trait OCollective[F[_]] {
|
trait OCollective[F[_]] {
|
||||||
@ -41,6 +41,8 @@ trait OCollective[F[_]] {
|
|||||||
kind: Option[ContactKind]
|
kind: Option[ContactKind]
|
||||||
): Stream[F, RContact]
|
): Stream[F, RContact]
|
||||||
|
|
||||||
|
def findSource(sourceId: Ident): F[Option[RSource]]
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
object OCollective {
|
object OCollective {
|
||||||
@ -156,5 +158,7 @@ object OCollective {
|
|||||||
): Stream[F, RContact] =
|
): Stream[F, RContact] =
|
||||||
store.transact(QCollective.getContacts(collective, query, kind))
|
store.transact(QCollective.getContacts(collective, query, kind))
|
||||||
|
|
||||||
|
def findSource(sourceId: Ident): F[Option[RSource]] =
|
||||||
|
store.transact(RSource.find(sourceId))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package docspell.restserver.routes
|
package docspell.restserver.routes
|
||||||
|
|
||||||
|
import cats.data.OptionT
|
||||||
import cats.effect._
|
import cats.effect._
|
||||||
import cats.implicits._
|
import cats.implicits._
|
||||||
|
|
||||||
@ -43,11 +44,21 @@ object UploadRoutes {
|
|||||||
import dsl._
|
import dsl._
|
||||||
|
|
||||||
HttpRoutes.of {
|
HttpRoutes.of {
|
||||||
case req @ POST -> Root / "item" / Ident(id) =>
|
case req @ POST -> Root / "item" / Ident(srcId) =>
|
||||||
submitFiles(backend, cfg, Left(id))(req, None, Priority.Low, dsl)
|
(for {
|
||||||
|
_ <- OptionT(backend.collective.findSource(srcId))
|
||||||
|
res <- OptionT.liftF(
|
||||||
|
submitFiles(backend, cfg, Left(srcId))(req, None, Priority.Low, dsl)
|
||||||
|
)
|
||||||
|
} yield res).getOrElseF(NotFound())
|
||||||
|
|
||||||
case req @ POST -> Root / "item" / Ident(itemId) / Ident(id) =>
|
case req @ POST -> Root / "item" / Ident(itemId) / Ident(srcId) =>
|
||||||
submitFiles(backend, cfg, Left(id))(req, Some(itemId), Priority.Low, dsl)
|
(for {
|
||||||
|
_ <- OptionT(backend.collective.findSource(srcId))
|
||||||
|
res <- OptionT.liftF(
|
||||||
|
submitFiles(backend, cfg, Left(srcId))(req, Some(itemId), Priority.Low, dsl)
|
||||||
|
)
|
||||||
|
} yield res).getOrElseF(NotFound())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user