Skip to content

Commit

Permalink
Filter out results that have non-resolvable namespaces
Browse files Browse the repository at this point in the history
A namespace is a reference to another entity. If this doesn't exist,
the results are not valid and are therefore not selected to be
returned from a user query
  • Loading branch information
eikek committed Oct 30, 2024
1 parent 7a80ae0 commit d0fde7a
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class SearchApiSpec extends CatsEffectSuite with SearchSolrSuite:
for {
client <- IO(searchSolrClient())
searchApi = new SearchApiImpl[IO](client)
_ <- client.upsert((project1 :: project2 :: Nil).map(_.widen))
_ <- client.upsert((project1 :: project2 :: user :: Nil).map(_.widen))
results <- searchApi
.query(AuthContext.anonymous)(mkQuery("matching"))
.map(_.fold(err => fail(s"Calling Search API failed with $err"), identity))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ object RenkuEntityQuery:
.addFilter(
SolrToken.kindIs(DocumentKind.FullEntity).value,
SolrToken.namespaceExists.value,
SolrToken.createdByExists.value
SolrToken.createdByExists.value,
"{!join from=namespace to=namespace}(_type:User OR _type:Group)"
)
.addFilter(constrainRole(role).map(_.value)*)
.withSort(sq.sort)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,34 +43,35 @@ class SearchSolrClientSpec extends CatsEffectSuite with SearchSolrSuite:
override def munitFixtures: Seq[munit.AnyFixture[?]] =
List(solrServer, searchSolrClient)

// test("ignore entities with non-resolvable namespace"):
// val user = userDocumentGen.generateOne
// val group = groupDocumentGen.generateOne
// val project0 = projectDocumentGen(
// "project-test0",
// "project-test0 description",
// Gen.const(None),
// Gen.const(None)
// ).generateOne.copy(createdBy = user.id, namespace = group.namespace.some)
// val project1 = projectDocumentGen(
// "project-test1",
// "project-test1 description",
// Gen.const(None),
// Gen.const(None)
// ).generateOne.copy(createdBy = user.id, namespace = group.namespace.some)
test("ignore entities with non-resolvable namespace"):
val user = userDocumentGen.generateOne
val group = groupDocumentGen.generateOne
val randomNs = ModelGenerators.namespaceGen.generateOne
val project0 = projectDocumentGenForInsert.generateOne.copy(
createdBy = user.id,
namespace = group.namespace.some
)
val project1 = projectDocumentGenForInsert.generateOne.copy(
createdBy = user.id,
namespace = randomNs.some
)

// for
// client <- IO(searchSolrClient())
// _ <- client.upsert(Seq(project0.widen, project1.widen, user.widen, group.widen))
for
client <- IO(searchSolrClient())
_ <- client.upsert(Seq(project0.widen, project1.widen, user.widen, group.widen))

// qr <- client.queryEntity(
// SearchRole.admin(Id("admin")),
// Query.parse("test0").toOption.get,
// 10,
// 0
// )
// _ = assertEquals(qr.responseBody.docs.size, 1)
// yield ()
qr <- client.queryEntity(
SearchRole.admin(Id("admin")),
Query.empty,
10,
0
)
_ = assert(
!qr.responseBody.docs.map(_.id).contains(project1.id),
"project with non-existing namespace was in the result set"
)
_ = assertEquals(qr.responseBody.docs.size, 3)
yield ()

test("ignore entities with non-existing namespace"):
val user = userDocumentGen.generateOne
Expand Down Expand Up @@ -227,7 +228,7 @@ class SearchSolrClientSpec extends CatsEffectSuite with SearchSolrSuite:
.generateOne
.copy(createdBy = user.id, namespace = user.namespace)
)
_ <- client.upsertSuccess(Seq(project))
_ <- client.upsertSuccess(Seq(project, user))
member = entityMembers.allIds.head
nonMember <- IO(ModelGenerators.idGen.generateOne)
query = Query(Query.Segment.idIs(project.id.value))
Expand Down

0 comments on commit d0fde7a

Please sign in to comment.