Skip to content

Commit

Permalink
Merge pull request #64 from SwissDataScienceCenter/role-filter
Browse files Browse the repository at this point in the history
feat: Add a role filter to user defined query
  • Loading branch information
eikek authored Mar 19, 2024
2 parents f45bc0c + 38f998e commit 7f0acfa
Show file tree
Hide file tree
Showing 21 changed files with 237 additions and 360 deletions.
3 changes: 1 addition & 2 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,7 @@ lazy val commons = project
Dependencies.catsEffect ++
Dependencies.ducktape ++
Dependencies.fs2Core ++
Dependencies.scodecBits ++
Dependencies.scribe,
Dependencies.scodecBits,
Test / sourceGenerators += Def.task {
val sourceDir =
(LocalRootProject / baseDirectory).value / "project"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,21 +46,25 @@ final case class MessageHeader(
)

object MessageHeader:
def apply(
def apply[F[_]: Clock: Functor](
source: MessageSource,
payloadSchema: Schema,
dataContentType: DataContentType,
schemaVersion: SchemaVersion,
requestId: RequestId
): MessageHeader =
MessageHeader(
source,
payloadSchema,
dataContentType,
schemaVersion,
CreationTime.now,
requestId
)
): F[MessageHeader] =
CreationTime
.now[F]
.map(now =>
MessageHeader(
source,
payloadSchema,
dataContentType,
schemaVersion,
now,
requestId
)
)

opaque type MessageSource = String
object MessageSource:
Expand All @@ -76,8 +80,7 @@ object SchemaVersion:
opaque type CreationTime = Instant
object CreationTime:
def apply(v: Instant): CreationTime = v
def now: CreationTime = Instant.now().truncatedTo(ChronoUnit.MILLIS)
def nowF[F[_]: Clock: Functor]: F[CreationTime] =
def now[F[_]: Clock: Functor]: F[CreationTime] =
Clock[F].realTimeInstant.map(_.truncatedTo(ChronoUnit.MILLIS))

extension (self: CreationTime) def value: Instant = self
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,20 @@ package io.renku.queue.client

import org.apache.avro.Schema
import org.scalacheck.Gen
import java.time.Instant

object Generators:

val requestIdGen: Gen[RequestId] = Gen.uuid.map(_.toString).map(RequestId(_))

val creationTimeGen: Gen[CreationTime] =
Gen
.choose(
Instant.parse("2020-01-01T01:00:00Z").toEpochMilli(),
Instant.now().toEpochMilli()
)
.map(millis => CreationTime(Instant.ofEpochMilli(millis)))

def messageHeaderGen(schema: Schema, contentType: DataContentType): Gen[MessageHeader] =
messageHeaderGen(schema, Gen.const(contentType))

Expand All @@ -36,10 +45,12 @@ object Generators:
contentType <- ctGen
schemaVersion <- Gen.choose(1, 100).map(v => SchemaVersion(s"v$v"))
requestId <- requestIdGen
creationTime <- creationTimeGen
yield MessageHeader(
MessageSource("test"),
schema,
contentType,
schemaVersion,
creationTime,
requestId
)
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@
package io.renku.search.api.data

import io.renku.search.query.Query
import io.bullet.borer.Encoder
import io.bullet.borer.derivation.MapBasedCodecs.{deriveDecoder, deriveEncoder}
import io.bullet.borer.Decoder
import cats.Show

final case class QueryInput(
Expand All @@ -30,9 +27,6 @@ final case class QueryInput(
)

object QueryInput:
given Encoder[QueryInput] = deriveEncoder
given Decoder[QueryInput] = deriveDecoder

given Show[QueryInput] = Show.show(i => s"(${i.query.render}, ${i.page})")

def pageOne(query: Query): QueryInput =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,11 @@ object PushToRedis:
)

def createHeader(requestId: RequestId): F[MessageHeader] =
CreationTime.nowF.map { now =>
MessageHeader(
MessageSource(clientId.value),
ProjectAuthorizationRemoved.SCHEMA$,
DataContentType.Binary,
SchemaVersion.V1,
now,
requestId
)
}
MessageHeader[F](
MessageSource(clientId.value),
ProjectAuthorizationRemoved.SCHEMA$,
DataContentType.Binary,
SchemaVersion.V1,
requestId
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ enum Field:
case Created
case CreatedBy
case Type
case Role

val name: String = Strings.lowerFirst(productPrefix)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ package io.renku.search.query
import cats.data.NonEmptyList
import io.renku.search.model.EntityType
import io.renku.search.model.projects.Visibility
import io.renku.search.model.projects.MemberRole

enum FieldTerm(val field: Field, val cmp: Comparison):
case TypeIs(values: NonEmptyList[EntityType])
Expand All @@ -34,6 +35,8 @@ enum FieldTerm(val field: Field, val cmp: Comparison):
extends FieldTerm(Field.Created, cmp)
case CreatedByIs(values: NonEmptyList[String])
extends FieldTerm(Field.CreatedBy, Comparison.Is)
case RoleIs(values: NonEmptyList[MemberRole])
extends FieldTerm(Field.Role, Comparison.Is)

private[query] def asString =
val value = this match
Expand All @@ -48,6 +51,7 @@ enum FieldTerm(val field: Field, val cmp: Comparison):
vis.mkString(",")
case Created(_, values) => FieldTerm.nelToString(values.map(_.asString))
case CreatedByIs(values) => FieldTerm.nelToString(values)
case RoleIs(values) => FieldTerm.nelToString(values.map(_.name))

s"${field.name}${cmp.asString}${value}"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,10 @@ package io.renku.search.query
import cats.data.NonEmptyList
import cats.kernel.Monoid
import cats.syntax.all.*
import io.bullet.borer.{Decoder, Encoder}
import io.renku.search.model.EntityType
import io.renku.search.model.projects.Visibility
import io.renku.search.query.FieldTerm.Created
import io.renku.search.query.Query.Segment
import io.renku.search.query.json.QueryJsonCodec
import io.renku.search.query.parse.{QueryParser, QueryUtil}

final case class Query(
Expand All @@ -44,9 +42,6 @@ final case class Query(
def isEmpty: Boolean = segments.isEmpty

object Query:
given Encoder[Query] = QueryJsonCodec.encoder.contramap(_.segments)
given Decoder[Query] = QueryJsonCodec.decoder.map(Query.apply)

def parse(str: String): Either[String, Query] =
val trimmed = str.trim
if (trimmed.isEmpty) Right(empty)
Expand Down

This file was deleted.

Loading

0 comments on commit 7f0acfa

Please sign in to comment.