From 5b95fddf3d47d525a47c0f44b3e3e1283ff664cf Mon Sep 17 00:00:00 2001 From: Eike Kettner Date: Sat, 11 Jul 2020 21:54:51 +0200 Subject: [PATCH] Make item queries depend on the account-id Now the user is required, too, to list items. --- .../docspell/backend/ops/OFulltext.scala | 12 +++++------ .../docspell/backend/ops/OItemSearch.scala | 2 +- .../restserver/conv/Conversions.scala | 4 ++-- .../restserver/routes/ItemRoutes.scala | 6 +++--- .../scala/docspell/store/queries/QItem.scala | 20 +++++++++---------- 5 files changed, 22 insertions(+), 22 deletions(-) diff --git a/modules/backend/src/main/scala/docspell/backend/ops/OFulltext.scala b/modules/backend/src/main/scala/docspell/backend/ops/OFulltext.scala index 77f9fab4..5e32ad5d 100644 --- a/modules/backend/src/main/scala/docspell/backend/ops/OFulltext.scala +++ b/modules/backend/src/main/scala/docspell/backend/ops/OFulltext.scala @@ -30,7 +30,7 @@ trait OFulltext[F[_]] { def findIndexOnly( fts: OFulltext.FtsInput, - collective: Ident, + account: AccountId, batch: Batch ): F[Vector[OFulltext.FtsItemWithTags]] @@ -94,12 +94,12 @@ object OFulltext { def findIndexOnly( ftsQ: OFulltext.FtsInput, - collective: Ident, + account: AccountId, batch: Batch ): F[Vector[OFulltext.FtsItemWithTags]] = { val fq = FtsQuery( ftsQ.query, - collective, + account.collective, Set.empty, batch.limit, batch.offset, @@ -113,8 +113,8 @@ object OFulltext { store .transact( QItem.findItemsWithTags( - collective, - QItem.findSelectedItems(QItem.Query.empty(collective), select) + account.collective, + QItem.findSelectedItems(QItem.Query.empty(account), select) ) ) .take(batch.limit.toLong) @@ -182,7 +182,7 @@ object OFulltext { val sqlResult = search(q, batch) val fq = FtsQuery( ftsQ.query, - q.collective, + q.account.collective, Set.empty, 0, 0, diff --git a/modules/backend/src/main/scala/docspell/backend/ops/OItemSearch.scala b/modules/backend/src/main/scala/docspell/backend/ops/OItemSearch.scala index de517fb5..e4b42b24 100644 --- a/modules/backend/src/main/scala/docspell/backend/ops/OItemSearch.scala +++ b/modules/backend/src/main/scala/docspell/backend/ops/OItemSearch.scala @@ -107,7 +107,7 @@ object OItemSearch { val search = QItem.findItems(q, batch) store .transact( - QItem.findItemsWithTags(q.collective, search).take(batch.limit.toLong) + QItem.findItemsWithTags(q.account.collective, search).take(batch.limit.toLong) ) .compile .toVector diff --git a/modules/restserver/src/main/scala/docspell/restserver/conv/Conversions.scala b/modules/restserver/src/main/scala/docspell/restserver/conv/Conversions.scala index d899ea06..fa94c30b 100644 --- a/modules/restserver/src/main/scala/docspell/restserver/conv/Conversions.scala +++ b/modules/restserver/src/main/scala/docspell/restserver/conv/Conversions.scala @@ -110,9 +110,9 @@ trait Conversions { // item list - def mkQuery(m: ItemSearch, coll: Ident): OItemSearch.Query = + def mkQuery(m: ItemSearch, account: AccountId): OItemSearch.Query = OItemSearch.Query( - coll, + account, m.name, if (m.inbox) Seq(ItemState.Created) else ItemState.validStates.toList, 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 d32ba6b8..02eabd9c 100644 --- a/modules/restserver/src/main/scala/docspell/restserver/routes/ItemRoutes.scala +++ b/modules/restserver/src/main/scala/docspell/restserver/routes/ItemRoutes.scala @@ -35,7 +35,7 @@ object ItemRoutes { for { mask <- req.as[ItemSearch] _ <- logger.ftrace(s"Got search mask: $mask") - query = Conversions.mkQuery(mask, user.account.collective) + query = Conversions.mkQuery(mask, user.account) _ <- logger.ftrace(s"Running query: $query") resp <- mask.fullText match { case Some(fq) if cfg.fullTextSearch.enabled => @@ -62,7 +62,7 @@ object ItemRoutes { for { mask <- req.as[ItemSearch] _ <- logger.ftrace(s"Got search mask: $mask") - query = Conversions.mkQuery(mask, user.account.collective) + query = Conversions.mkQuery(mask, user.account) _ <- logger.ftrace(s"Running query: $query") resp <- mask.fullText match { case Some(fq) if cfg.fullTextSearch.enabled => @@ -94,7 +94,7 @@ object ItemRoutes { for { items <- backend.fulltext.findIndexOnly( ftsIn, - user.account.collective, + user.account, Batch(mask.offset, mask.limit).restrictLimitTo(cfg.maxItemPageSize) ) ok <- Ok(Conversions.mkItemListWithTagsFtsPlain(items)) diff --git a/modules/store/src/main/scala/docspell/store/queries/QItem.scala b/modules/store/src/main/scala/docspell/store/queries/QItem.scala index a40f11d2..e4618772 100644 --- a/modules/store/src/main/scala/docspell/store/queries/QItem.scala +++ b/modules/store/src/main/scala/docspell/store/queries/QItem.scala @@ -160,7 +160,7 @@ object QItem { ) case class Query( - collective: Ident, + account: AccountId, name: Option[String], states: Seq[ItemState], direction: Option[Direction], @@ -181,9 +181,9 @@ object QItem { ) object Query { - def empty(collective: Ident): Query = + def empty(account: AccountId): Query = Query( - collective, + account, None, Seq.empty, None, @@ -273,12 +273,12 @@ object QItem { ) ++ moreCols ) - val withItem = selectSimple(itemCols, RItem.table, IC.cid.is(q.collective)) - val withPerson = selectSimple(personCols, RPerson.table, PC.cid.is(q.collective)) - val withOrgs = selectSimple(orgCols, ROrganization.table, OC.cid.is(q.collective)) - val withEquips = selectSimple(equipCols, REquipment.table, EC.cid.is(q.collective)) + val withItem = selectSimple(itemCols, RItem.table, IC.cid.is(q.account.collective)) + val withPerson = selectSimple(personCols, RPerson.table, PC.cid.is(q.account.collective)) + val withOrgs = selectSimple(orgCols, ROrganization.table, OC.cid.is(q.account.collective)) + val withEquips = selectSimple(equipCols, REquipment.table, EC.cid.is(q.account.collective)) val withFolder = - selectSimple(folderCols, RFolder.table, FC.collective.is(q.collective)) + selectSimple(folderCols, RFolder.table, FC.collective.is(q.account.collective)) val withAttach = fr"SELECT COUNT(" ++ AC.id.f ++ fr") as num, " ++ AC.itemId.f ++ fr"from" ++ RAttachment.table ++ fr"GROUP BY (" ++ AC.itemId.f ++ fr")" @@ -337,7 +337,7 @@ object QItem { val name = q.name.map(_.toLowerCase).map(queryWildcard) val allNames = q.allNames.map(_.toLowerCase).map(queryWildcard) val cond = and( - IC.cid.prefix("i").is(q.collective), + IC.cid.prefix("i").is(q.account.collective), IC.state.prefix("i").isOneOf(q.states), IC.incoming.prefix("i").isOrDiscard(q.direction), name @@ -476,7 +476,7 @@ object QItem { n <- store.transact(RItem.deleteByIdAndCollective(itemId, collective)) } yield tn + rn + n + mn - private def findByFileIdsQuery(fileMetaIds: NonEmptyList[Ident], limit: Option[Int]) = { + private def findByFileIdsQuery(fileMetaIds: NonEmptyList[Ident], limit: Option[Int]): Fragment = { val IC = RItem.Columns.all.map(_.prefix("i")) val aItem = RAttachment.Columns.itemId.prefix("a") val aId = RAttachment.Columns.id.prefix("a")