mirror of
https://github.com/TheAnachronism/docspell.git
synced 2025-03-30 21:05:08 +00:00
Make item queries depend on the account-id
Now the user is required, too, to list items.
This commit is contained in:
parent
e66c501056
commit
5b95fddf3d
@ -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,
|
||||
|
@ -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
|
||||
|
@ -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,
|
||||
|
@ -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))
|
||||
|
@ -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")
|
||||
|
Loading…
x
Reference in New Issue
Block a user