Merge pull request #1139 from eikek/fixup/share

Don't allow shares with fulltext queries
This commit is contained in:
mergify[bot] 2021-10-25 19:46:30 +00:00 committed by GitHub
commit a41558642e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 28 additions and 2 deletions

View File

@ -16,9 +16,9 @@ import docspell.backend.ops.OItemSearch._
import docspell.backend.ops.OShare._ import docspell.backend.ops.OShare._
import docspell.backend.ops.OSimpleSearch.StringSearchResult import docspell.backend.ops.OSimpleSearch.StringSearchResult
import docspell.common._ import docspell.common._
import docspell.query.ItemQuery
import docspell.query.ItemQuery.Expr import docspell.query.ItemQuery.Expr
import docspell.query.ItemQuery.Expr.AttachId import docspell.query.ItemQuery.Expr.AttachId
import docspell.query.{FulltextExtract, ItemQuery}
import docspell.store.Store import docspell.store.Store
import docspell.store.queries.SearchSummary import docspell.store.queries.SearchSummary
import docspell.store.records._ import docspell.store.records._
@ -133,10 +133,12 @@ object OShare {
final case class Success(id: Ident) extends ChangeResult final case class Success(id: Ident) extends ChangeResult
case object PublishUntilInPast extends ChangeResult case object PublishUntilInPast extends ChangeResult
case object NotFound extends ChangeResult case object NotFound extends ChangeResult
case object QueryWithFulltext extends ChangeResult
def success(id: Ident): ChangeResult = Success(id) def success(id: Ident): ChangeResult = Success(id)
def publishUntilInPast: ChangeResult = PublishUntilInPast def publishUntilInPast: ChangeResult = PublishUntilInPast
def notFound: ChangeResult = NotFound def notFound: ChangeResult = NotFound
def queryWithFulltext: ChangeResult = QueryWithFulltext
} }
final case class ShareData(share: RShare, user: RUser) final case class ShareData(share: RShare, user: RUser)
@ -182,12 +184,13 @@ object OShare {
) )
res <- res <-
if (share.publishUntil < curTime) ChangeResult.publishUntilInPast.pure[F] if (share.publishUntil < curTime) ChangeResult.publishUntilInPast.pure[F]
else if (hasFulltext(share.query)) ChangeResult.queryWithFulltext.pure[F]
else store.transact(RShare.insert(record)).map(_ => ChangeResult.success(id)) else store.transact(RShare.insert(record)).map(_ => ChangeResult.success(id))
} yield res } yield res
def update( def update(
id: Ident, id: Ident,
share: OShare.NewShare, share: NewShare,
removePassword: Boolean removePassword: Boolean
): F[ChangeResult] = ): F[ChangeResult] =
for { for {
@ -207,12 +210,19 @@ object OShare {
) )
res <- res <-
if (share.publishUntil < curTime) ChangeResult.publishUntilInPast.pure[F] if (share.publishUntil < curTime) ChangeResult.publishUntilInPast.pure[F]
else if (hasFulltext(share.query)) ChangeResult.queryWithFulltext.pure[F]
else else
store store
.transact(RShare.updateData(record, removePassword)) .transact(RShare.updateData(record, removePassword))
.map(n => if (n > 0) ChangeResult.success(id) else ChangeResult.notFound) .map(n => if (n > 0) ChangeResult.success(id) else ChangeResult.notFound)
} yield res } yield res
private def hasFulltext(iq: ItemQuery): Boolean =
iq.findFulltext match {
case FulltextExtract.Result.SuccessNoFulltext(_) => false
case _ => true
}
def findOne(id: Ident, collective: Ident): OptionT[F, ShareData] = def findOne(id: Ident, collective: Ident): OptionT[F, ShareData] =
RShare RShare
.findOne(id, collective) .findOne(id, collective)

View File

@ -130,6 +130,12 @@ object ShareRoutes {
"Share not found or not owner. Only the owner can update a share.", "Share not found or not owner. Only the owner can update a share.",
Ident.unsafe("") Ident.unsafe("")
) )
case OShare.ChangeResult.QueryWithFulltext =>
IdResult(
false,
"Sorry, shares with fulltext queries are currently not supported.",
Ident.unsafe("")
)
} }
def mkBasicResult(r: OShare.ChangeResult, msg: => String): BasicResult = def mkBasicResult(r: OShare.ChangeResult, msg: => String): BasicResult =
@ -142,6 +148,11 @@ object ShareRoutes {
false, false,
"Share not found or not owner. Only the owner can update a share." "Share not found or not owner. Only the owner can update a share."
) )
case OShare.ChangeResult.QueryWithFulltext =>
BasicResult(
false,
"Sorry, shares with fulltext queries are currently not supported."
)
} }
def mkShareDetail(now: Timestamp)(r: OShare.ShareData): ShareDetail = def mkShareDetail(now: Timestamp)(r: OShare.ShareData): ShareDetail =

View File

@ -61,6 +61,11 @@ needs access to it, for example if you want to share all your tax
documents with the company/person who helps you with doing you tax documents with the company/person who helps you with doing you tax
submission. submission.
## Limitations
Currently, shares that contain fulltext search queries are not
supported. The query for a share must not use any fulltext search.
# Creating shares # Creating shares
There are the following ways to create a share: There are the following ways to create a share: