Skip to content

Commit

Permalink
Remove the ability to tag ElasticSearch views (#4730)
Browse files Browse the repository at this point in the history
* Remove the ability to tag ElasticSearch views

* Remove the ability to tag Composite views
  • Loading branch information
dantb authored Feb 12, 2024
1 parent 9058232 commit b07db61
Show file tree
Hide file tree
Showing 29 changed files with 61 additions and 718 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,9 @@ import ch.epfl.bluebrain.nexus.delta.sdk.model.search.SearchResults.UnscoredSear
import ch.epfl.bluebrain.nexus.delta.sdk.projects.{FetchContext, Projects}
import ch.epfl.bluebrain.nexus.delta.sdk.resolvers.ResolverContextResolution
import ch.epfl.bluebrain.nexus.delta.sdk.views.IndexingRev
import ch.epfl.bluebrain.nexus.delta.sourcing.ScopedEntityDefinition.Tagger
import ch.epfl.bluebrain.nexus.delta.sourcing._
import ch.epfl.bluebrain.nexus.delta.sourcing.model.EntityDependency.DependsOn
import ch.epfl.bluebrain.nexus.delta.sourcing.model.Identity.Subject
import ch.epfl.bluebrain.nexus.delta.sourcing.model.Tag.UserTag
import ch.epfl.bluebrain.nexus.delta.sourcing.model._
import ch.epfl.bluebrain.nexus.delta.sourcing.offset.Offset
import ch.epfl.bluebrain.nexus.delta.sourcing.stream.Elem
Expand Down Expand Up @@ -162,36 +160,6 @@ final class CompositeViews private (
} yield res
}.span("updateCompositeView")

/**
* Applies a tag to an existing composite revision.
*
* @param id
* the view identifier
* @param project
* the view parent project
* @param tag
* the tag to apply
* @param tagRev
* the target revision of the tag
* @param rev
* the current view revision
* @param subject
* the subject that initiated the action
*/
def tag(
id: IdSegment,
project: ProjectRef,
tag: UserTag,
tagRev: Int,
rev: Int
)(implicit subject: Subject): IO[ViewResource] = {
for {
pc <- fetchContext.onModify(project)
iri <- expandIri(id, pc)
res <- eval(TagCompositeView(iri, project, tagRev, tag, rev, subject))
} yield res
}.span("tagCompositeView")

/**
* Deprecates an existing composite view.
*
Expand Down Expand Up @@ -278,10 +246,8 @@ final class CompositeViews private (
notFound = ViewNotFound(iri, project)
state <- id match {
case Latest(_) => log.stateOr(project, iri, notFound)
case Revision(_, rev) =>
log.stateOr(project, iri, rev, notFound, RevisionNotFound)
case Tag(_, tag) =>
log.stateOr(project, iri, tag, notFound, TagNotFound(tag))
case Revision(_, rev) => log.stateOr(project, iri, rev, notFound, RevisionNotFound)
case t: Tag => IO.raiseError(FetchByTagNotSupported(t))
}
} yield state
}.span("fetchCompositeView")
Expand Down Expand Up @@ -445,19 +411,6 @@ object CompositeViews {
} yield CompositeViewUpdated(c.id, c.project, s.uuid, value, c.source, newRev, t, c.subject)
}

def tag(c: TagCompositeView) = state match {
case None =>
IO.raiseError(ViewNotFound(c.id, c.project))
case Some(s) if s.rev != c.rev =>
IO.raiseError(IncorrectRev(c.rev, s.rev))
case Some(s) if c.targetRev <= 0 || c.targetRev > s.rev =>
IO.raiseError(RevisionNotFound(c.targetRev, s.rev))
case Some(s) =>
clock.realTimeInstant.map(
CompositeViewTagAdded(c.id, c.project, s.uuid, c.targetRev, c.tag, s.rev + 1, _, c.subject)
)
}

def deprecate(c: DeprecateCompositeView) = state match {
case None =>
IO.raiseError(ViewNotFound(c.id, c.project))
Expand All @@ -483,7 +436,6 @@ object CompositeViews {
cmd match {
case c: CreateCompositeView => create(c)
case c: UpdateCompositeView => update(c)
case c: TagCompositeView => tag(c)
case c: DeprecateCompositeView => deprecate(c)
case c: UndeprecateCompositeView => undeprecate(c)
}
Expand All @@ -492,20 +444,11 @@ object CompositeViews {
def definition(validate: ValidateCompositeView, clock: Clock[IO])(implicit
uuidF: UUIDF
): ScopedEntityDefinition[Iri, CompositeViewState, CompositeViewCommand, CompositeViewEvent, CompositeViewRejection] =
ScopedEntityDefinition(
ScopedEntityDefinition.untagged(
entityType,
StateMachine(None, evaluate(validate, clock)(_, _), next),
CompositeViewEvent.serializer,
CompositeViewState.serializer,
Tagger[CompositeViewEvent](
{
case r: CompositeViewTagAdded => Some(r.tag -> r.targetRev)
case _ => None
},
{ _ =>
None
}
),
state =>
Some(
state.value.sources.value.foldLeft(Set.empty[DependsOn]) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package ch.epfl.bluebrain.nexus.delta.plugins.compositeviews.model
import ch.epfl.bluebrain.nexus.delta.rdf.IriOrBNode.Iri
import ch.epfl.bluebrain.nexus.delta.sdk.projects.model.ProjectBase
import ch.epfl.bluebrain.nexus.delta.sourcing.model.Identity.Subject
import ch.epfl.bluebrain.nexus.delta.sourcing.model.Tag.UserTag
import ch.epfl.bluebrain.nexus.delta.sourcing.model.ProjectRef
import io.circe.Json

Expand Down Expand Up @@ -123,30 +122,4 @@ object CompositeViewCommand {
*/
final case class UndeprecateCompositeView(id: Iri, project: ProjectRef, rev: Int, subject: Subject)
extends CompositeViewCommand

/**
* Command for adding a tag to a composite view.
*
* @param id
* the view id
* @param project
* a reference to the parent project
* @param targetRev
* the revision that is being aliased with the provided ''tag''
* @param tag
* the tag label
* @param rev
* the last known revision of the view
* @param subject
* the identity associated with this command
*/
final case class TagCompositeView(
id: Iri,
project: ProjectRef,
targetRev: Int,
tag: UserTag,
rev: Int,
subject: Subject
) extends CompositeViewCommand

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import ch.epfl.bluebrain.nexus.delta.sdk.implicits._
import ch.epfl.bluebrain.nexus.delta.sdk.jsonld.JsonLdRejection
import ch.epfl.bluebrain.nexus.delta.sdk.jsonld.JsonLdRejection.UnexpectedId
import ch.epfl.bluebrain.nexus.delta.sdk.marshalling.HttpResponseFields
import ch.epfl.bluebrain.nexus.delta.sdk.model.BaseUri
import ch.epfl.bluebrain.nexus.delta.sdk.model.{BaseUri, IdSegmentRef}
import ch.epfl.bluebrain.nexus.delta.sdk.permissions.model.Permission
import ch.epfl.bluebrain.nexus.delta.sdk.views.ViewRef
import ch.epfl.bluebrain.nexus.delta.sourcing.model.ProjectRef
Expand Down Expand Up @@ -130,6 +130,11 @@ object CompositeViewRejection {
s"Incorrect revision '$provided' provided, expected '$expected', the view may have been updated since last seen."
)

final case class FetchByTagNotSupported(tag: IdSegmentRef.Tag)
extends CompositeViewRejection(
s"Fetching composite views by tag is no longer supported. Id ${tag.value.asString} and tag ${tag.tag.value}"
)

/**
* Rejection returned when a subject intends to retrieve a view at a specific revision, but the provided revision
* does not exist.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import ch.epfl.bluebrain.nexus.delta.sdk.identities.Identities
import ch.epfl.bluebrain.nexus.delta.sdk.implicits._
import ch.epfl.bluebrain.nexus.delta.sdk.marshalling.RdfMarshalling
import ch.epfl.bluebrain.nexus.delta.sdk.model.BaseUri
import ch.epfl.bluebrain.nexus.delta.sdk.model.routes.Tag
import io.circe.{Json, JsonObject}

/**
Expand Down Expand Up @@ -58,9 +57,6 @@ class CompositeViewsRoutes(
private def emitFetch(io: IO[ViewResource]) =
emit(io.attemptNarrow[CompositeViewRejection].rejectOn[ViewNotFound])

private def emitTags(io: IO[ViewResource]) =
emit(io.map(_.value.tags).attemptNarrow[CompositeViewRejection].rejectOn[ViewNotFound])

private def emitSource(io: IO[ViewResource]) =
emit(io.map(_.value.source).attemptNarrow[CompositeViewRejection].rejectOn[ViewNotFound])

Expand Down Expand Up @@ -121,22 +117,6 @@ class CompositeViewsRoutes(
emitMetadata(views.undeprecate(viewId, project, rev))
}
},
(pathPrefix("tags") & pathEndOrSingleSlash) {
concat(
// Fetch tags for a view
(get & idSegmentRef(viewId) & authorizeFor(project, Read)) { id =>
emitTags(views.fetch(id, project))
},
// Tag a view
(post & parameter("rev".as[Int])) { rev =>
authorizeFor(project, Write).apply {
entity(as[Tag]) { case Tag(tagRev, tag) =>
emitMetadata(Created, views.tag(viewId, project, tag, tagRev, rev))
}
}
}
)
},
// Fetch a view original source
(pathPrefix("source") & get & pathEndOrSingleSlash & idSegmentRef(viewId)) { id =>
authorizeFor(project, Read).apply {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ class CompositeViewsSpec
createdBy: Subject = alice.subject,
updatedAt: Instant = Instant.EPOCH,
updatedBy: Subject = alice.subject,
tags: Tags = Tags.empty,
source: Json
): ViewResource = CompositeViewsGen.resourceFor(
projectRef,
Expand All @@ -85,7 +84,6 @@ class CompositeViewsSpec
createdBy = createdBy,
updatedAt = updatedAt,
updatedBy = updatedBy,
tags = tags,
source = source
)

Expand Down Expand Up @@ -180,40 +178,13 @@ class CompositeViewsSpec
}
}

"tag a view" when {
val tag = UserTag.unsafe("mytag")
"view is not deprecated" in {
compositeViews.tag(viewId, projectRef, tag, 1, 2).accepted
}

"view is deprecated" in {
compositeViews.tag(otherViewId, projectRef, tag, 1, 3).accepted
}
}

"reject tagging a view" when {
"incorrect revision is provided" in {
val tag = UserTag.unsafe("mytag2")
compositeViews.tag(viewId, projectRef, tag, 1, 2).rejectedWith[IncorrectRev]
}
"view is deprecated" in {
val tag = UserTag.unsafe("mytag3")
compositeViews.tag(otherViewId, projectRef, tag, 1, 2).rejectedWith[IncorrectRev]
}
"target view is not found" in {
val tag = UserTag.unsafe("mytag3")
compositeViews.tag(iri"http://example.com/wrong", projectRef, tag, 1, 2).rejectedWith[ViewNotFound]
}
}

"fetch a view" when {
"no tag or rev is provided" in {
compositeViews.fetch(viewId, projectRef).accepted shouldEqual resourceFor(
viewId,
updatedValue,
source = viewSourceUpdated.removeAllKeys("token"),
rev = 3,
tags = Tags(UserTag.unsafe("mytag") -> 1)
rev = 2
)
}
"rev is provided" in {
Expand All @@ -223,11 +194,6 @@ class CompositeViewsSpec
source = viewSource.removeAllKeys("token")
)
}
"tag is provided" in {
val tag = UserTag.unsafe("mytag")
compositeViews.fetch(IdSegmentRef(viewId, tag), projectRef).accepted shouldEqual
resourceFor(viewId, viewValue, source = viewSource.removeAllKeys("token"))
}
}

"reject fetching a view" when {
Expand All @@ -238,9 +204,9 @@ class CompositeViewsSpec
compositeViews.fetch(IdSegmentRef(viewId, 42), projectRef).rejectedWith[RevisionNotFound]
}

"tag doesn't exist" in {
val tag = UserTag.unsafe("wrongtag")
compositeViews.fetch(IdSegmentRef(viewId, tag), projectRef).rejectedWith[TagNotFound]
"attempting any lookup by tag" in {
val tag = UserTag.unsafe("mytag")
compositeViews.fetch(IdSegmentRef(viewId, tag), projectRef).rejectedWith[FetchByTagNotSupported]
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,28 +88,6 @@ class CompositeViewsStmSpec extends CatsEffectSpec with CompositeViewsFixture {
}
}

"evaluating the TagCompositeView command" should {
val tag = UserTag.unsafe("tag")
val cmd = TagCompositeView(id, project.ref, 1, tag, 1, subject)
"emit an CompositeViewTagAdded" in {
val expected = CompositeViewTagAdded(id, project.ref, uuid, 1, tag, 2, epoch, subject)
eval(Some(current()), cmd).accepted shouldEqual expected
}
"raise a ViewNotFound rejection" in {
eval(None, cmd).rejectedWith[ViewNotFound]
}
"raise a IncorrectRev rejection" in {
eval(Some(current()), cmd.copy(rev = 2)).rejectedWith[IncorrectRev]
}
"emit an CompositeViewTagAdded when deprecated" in {
val expected = CompositeViewTagAdded(id, project.ref, uuid, 1, tag, 2, epoch, subject)
eval(Some(current(deprecated = true)), cmd).accepted shouldEqual expected
}
"raise a RevisionNotFound rejection for revisions higher that the current" in {
eval(Some(current()), cmd.copy(targetRev = 2)).rejectedWith[RevisionNotFound]
}
}

"evaluating the DeprecateCompositeView command" should {
val cmd = DeprecateCompositeView(id, project.ref, 1, subject)
"emit an CompositeViewDeprecated" in {
Expand Down
Loading

0 comments on commit b07db61

Please sign in to comment.