Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/staging' into preview/NU-1778-ac…
Browse files Browse the repository at this point in the history
…tivities
  • Loading branch information
mgoworko committed Oct 22, 2024
2 parents e0fc274 + a7fc664 commit 4639cf3
Show file tree
Hide file tree
Showing 26 changed files with 382 additions and 250 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package pl.touk.nussknacker.engine.api

import io.circe.{Decoder, Encoder}

final case class Comment(content: String) extends AnyVal {
final case class Comment private (content: String) extends AnyVal {
override def toString: String = content
}

Expand All @@ -14,6 +14,11 @@ object NonEmptyComment {
}

object Comment {

def from(content: String): Option[Comment] = {
if (content.isEmpty) None else Some(Comment(content))
}

implicit val encoder: Encoder[Comment] = Encoder.encodeString.contramap(_.content)
implicit val decoder: Decoder[Comment] = Decoder.decodeString.map(Comment.apply)
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import pl.touk.nussknacker.ui.process.ProcessService.GetScenarioWithDetailsOptio
import pl.touk.nussknacker.ui.process.deployment.DeploymentManagerDispatcher
import pl.touk.nussknacker.ui.process.repository.DBIOActionRunner
import pl.touk.nussknacker.ui.process.repository.activities.ScenarioActivityRepository
import pl.touk.nussknacker.ui.process.repository.activities.ScenarioActivityRepository.DeleteAttachmentError
import pl.touk.nussknacker.ui.process.{ProcessService, ScenarioAttachmentService}
import pl.touk.nussknacker.ui.security.api.{AuthManager, LoggedUser}
import pl.touk.nussknacker.ui.server.HeadersSupport.ContentDisposition
Expand Down Expand Up @@ -110,6 +111,18 @@ class ScenarioActivityApiHttpService(
}
}

expose {
endpoints.deleteAttachmentEndpoint
.serverSecurityLogic(authorizeKnownUser[ScenarioActivityError])
.serverLogicEitherT { implicit loggedUser => request: DeleteAttachmentRequest =>
for {
scenarioId <- getScenarioIdByName(request.scenarioName)
_ <- isAuthorized(scenarioId, Permission.Write)
_ <- markAttachmentAsDeleted(request, scenarioId)
} yield ()
}
}

expose {
endpoints.downloadAttachmentEndpoint
.serverSecurityLogic(authorizeKnownUser[ScenarioActivityError])
Expand Down Expand Up @@ -267,18 +280,19 @@ class ScenarioActivityApiHttpService(
} yield sortedResult
}

private def toDto(scenarioComment: ScenarioComment): Dtos.ScenarioActivityComment = {
val content = scenarioComment match {
case ScenarioComment.Available(comment, _, _) if comment.nonEmpty =>
Dtos.ScenarioActivityCommentContent.Available(comment)
case ScenarioComment.NotAvailable(_, _) | ScenarioComment.Available(_, _, _) =>
Dtos.ScenarioActivityCommentContent.NotAvailable
}
Dtos.ScenarioActivityComment(
content = content,
lastModifiedBy = scenarioComment.lastModifiedByUserName.value,
lastModifiedAt = scenarioComment.lastModifiedAt,
)
private def toDto(scenarioComment: ScenarioComment): Dtos.ScenarioActivityComment = scenarioComment match {
case ScenarioComment.WithContent(comment, _, _) =>
Dtos.ScenarioActivityComment(
content = Dtos.ScenarioActivityCommentContent.Available(comment),
lastModifiedBy = scenarioComment.lastModifiedByUserName.value,
lastModifiedAt = scenarioComment.lastModifiedAt,
)
case ScenarioComment.WithoutContent(_, _) =>
Dtos.ScenarioActivityComment(
content = Dtos.ScenarioActivityCommentContent.NotAvailable,
lastModifiedBy = scenarioComment.lastModifiedByUserName.value,
lastModifiedAt = scenarioComment.lastModifiedAt,
)
}

private def toDto(attachment: ScenarioAttachment): Dtos.ScenarioActivityAttachment = {
Expand Down Expand Up @@ -583,7 +597,7 @@ class ScenarioActivityApiHttpService(
dbioActionRunner.run(
scenarioActivityRepository.markAttachmentAsDeleted(scenarioId, request.attachmentId)
)
).leftMap(_ => NoAttachment(request.attachmentId))
).leftMap { case DeleteAttachmentError.CouldNotDeleteAttachment => NoAttachment(request.attachmentId) }

private def buildResponse(maybeAttachment: Option[(String, Array[Byte])]): GetAttachmentResponse =
maybeAttachment match {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package pl.touk.nussknacker.ui.api.description.scenarioActivity

import derevo.circe.{decoder, encoder}
import derevo.derive
import enumeratum.EnumEntry.{CapitalWords, UpperSnakecase}
import enumeratum.EnumEntry.UpperSnakecase
import enumeratum.{Enum, EnumEntry}
import io.circe
import io.circe.generic.extras
Expand All @@ -28,7 +28,7 @@ import scala.collection.immutable

object Dtos {

sealed trait ScenarioType extends EnumEntry with CapitalWords
sealed trait ScenarioType extends EnumEntry

object ScenarioType extends Enum[ScenarioType] {
case object Scenario extends ScenarioType
Expand Down Expand Up @@ -98,15 +98,19 @@ object Dtos {
def from(scenarioType: ScenarioType)(scenarioActivityType: ScenarioActivityType): ScenarioActivityMetadata =
ScenarioActivityMetadata(
`type` = scenarioActivityType.entryName,
displayableName = scenarioActivityType.displayableName(scenarioType),
displayableName = scenarioType match {
case ScenarioType.Scenario => scenarioActivityType.displayableNameForScenario
case ScenarioType.Fragment => scenarioActivityType.displayableNameForFragment
},
icon = scenarioActivityType.icon,
supportedActions = scenarioActivityType.supportedActions,
)

}

sealed trait ScenarioActivityType extends EnumEntry with UpperSnakecase {
def displayableName(scenarioType: ScenarioType): String
def displayableNameForScenario: String
def displayableNameForFragment: String
def icon: String
def supportedActions: List[String]
}
Expand All @@ -116,105 +120,134 @@ object Dtos {
private val commentRelatedActions = List("delete_comment", "edit_comment")

case object ScenarioCreated extends ScenarioActivityType {
override def displayableName(scenarioType: ScenarioType): String = s"${scenarioType.entryName} created"
override def icon: String = "/assets/activities/scenarioModified.svg"
override def supportedActions: List[String] = List.empty
override def displayableNameForScenario: String = s"Scenario created"
override def displayableNameForFragment: String = s"Fragment created"
override def icon: String = "/assets/activities/scenarioModified.svg"
override def supportedActions: List[String] = List.empty
}

case object ScenarioArchived extends ScenarioActivityType {
override def displayableName(scenarioType: ScenarioType): String = s"${scenarioType.entryName} archived"
override def icon: String = "/assets/activities/archived.svg"
override def supportedActions: List[String] = List.empty
override def displayableNameForScenario: String = s"Scenario archived"
override def displayableNameForFragment: String = s"Fragment archived"
override def icon: String = "/assets/activities/archived.svg"
override def supportedActions: List[String] = List.empty
}

case object ScenarioUnarchived extends ScenarioActivityType {
override def displayableName(scenarioType: ScenarioType): String = s"${scenarioType.entryName} unarchived"
override def icon: String = "/assets/activities/unarchived.svg"
override def supportedActions: List[String] = List.empty
override def displayableNameForScenario: String = s"Scenario unarchived"
override def displayableNameForFragment: String = s"Fragment unarchived"
override def icon: String = "/assets/activities/unarchived.svg"
override def supportedActions: List[String] = List.empty
}

case object ScenarioDeployed extends ScenarioActivityType {
override def displayableName(scenarioType: ScenarioType): String = "Deployment"
override def icon: String = "/assets/activities/deployed.svg"
override def supportedActions: List[String] = commentRelatedActions
private val displayableName: String = "Deployment"
override def displayableNameForScenario: String = displayableName
override def displayableNameForFragment: String = displayableName
override def icon: String = "/assets/activities/deployed.svg"
override def supportedActions: List[String] = commentRelatedActions
}

case object ScenarioPaused extends ScenarioActivityType {
override def displayableName(scenarioType: ScenarioType): String = "Pause"
override def icon: String = "/assets/activities/pause.svg"
override def supportedActions: List[String] = commentRelatedActions
private val displayableName: String = "Pause"
override def displayableNameForScenario: String = displayableName
override def displayableNameForFragment: String = displayableName
override def icon: String = "/assets/activities/pause.svg"
override def supportedActions: List[String] = commentRelatedActions
}

case object ScenarioCanceled extends ScenarioActivityType {
override def displayableName(scenarioType: ScenarioType): String = "Cancel"
override def icon: String = "/assets/activities/cancel.svg"
override def supportedActions: List[String] = commentRelatedActions
private val displayableName: String = "Cancel"
override def displayableNameForScenario: String = displayableName
override def displayableNameForFragment: String = displayableName
override def icon: String = "/assets/activities/cancel.svg"
override def supportedActions: List[String] = commentRelatedActions
}

case object ScenarioModified extends ScenarioActivityType {
override def displayableName(scenarioType: ScenarioType): String = s"${scenarioType.entryName} modified"
override def icon: String = "/assets/activities/scenarioModified.svg"
override def supportedActions: List[String] = commentRelatedActions ::: "compare" :: Nil
override def displayableNameForScenario: String = s"Scenario modified"
override def displayableNameForFragment: String = s"Fragment modified"
override def icon: String = "/assets/activities/scenarioModified.svg"
override def supportedActions: List[String] = commentRelatedActions ::: "compare" :: Nil
}

case object ScenarioNameChanged extends ScenarioActivityType {
override def displayableName(scenarioType: ScenarioType): String = s"${scenarioType.entryName} name changed"
override def icon: String = "/assets/activities/scenarioModified.svg"
override def supportedActions: List[String] = List.empty
override def displayableNameForScenario: String = s"Scenario name changed"
override def displayableNameForFragment: String = s"Fragment name changed"
override def icon: String = "/assets/activities/scenarioModified.svg"
override def supportedActions: List[String] = List.empty
}

case object CommentAdded extends ScenarioActivityType {
override def displayableName(scenarioType: ScenarioType): String = "Comment"
override def icon: String = "/assets/activities/comment.svg"
override def supportedActions: List[String] = commentRelatedActions
private val displayableName: String = "Comment"
override def displayableNameForScenario: String = displayableName
override def displayableNameForFragment: String = displayableName
override def icon: String = "/assets/activities/comment.svg"
override def supportedActions: List[String] = commentRelatedActions
}

case object AttachmentAdded extends ScenarioActivityType {
override def displayableName(scenarioType: ScenarioType): String = "Attachment"
override def icon: String = "/assets/activities/attachment.svg"
override def supportedActions: List[String] = List("download_attachment", "delete_attachment")
private val displayableName: String = "Attachment"
override def displayableNameForScenario: String = displayableName
override def displayableNameForFragment: String = displayableName
override def icon: String = "/assets/activities/attachment.svg"
override def supportedActions: List[String] = List("download_attachment", "delete_attachment")
}

case object ChangedProcessingMode extends ScenarioActivityType {
override def displayableName(scenarioType: ScenarioType): String = "Processing mode change"
override def icon: String = "/assets/activities/processingModeChange.svg"
override def supportedActions: List[String] = List.empty
private val displayableName: String = "Processing mode change"
override def displayableNameForScenario: String = displayableName
override def displayableNameForFragment: String = displayableName
override def icon: String = "/assets/activities/processingModeChange.svg"
override def supportedActions: List[String] = List.empty
}

case object IncomingMigration extends ScenarioActivityType {
override def displayableName(scenarioType: ScenarioType): String = "Incoming migration"
override def icon: String = "/assets/activities/migration.svg"
override def supportedActions: List[String] = List("compare")
private val displayableName: String = "Incoming migration"
override def displayableNameForScenario: String = displayableName
override def displayableNameForFragment: String = displayableName
override def icon: String = "/assets/activities/migration.svg"
override def supportedActions: List[String] = List("compare")
}

case object OutgoingMigration extends ScenarioActivityType {
override def displayableName(scenarioType: ScenarioType): String = "Outgoing migration"
override def icon: String = "/assets/activities/migration.svg"
override def supportedActions: List[String] = commentRelatedActions
private val displayableName: String = "Outgoing migration"
override def displayableNameForScenario: String = displayableName
override def displayableNameForFragment: String = displayableName
override def icon: String = "/assets/activities/migration.svg"
override def supportedActions: List[String] = commentRelatedActions
}

case object PerformedSingleExecution extends ScenarioActivityType {
override def displayableName(scenarioType: ScenarioType): String = "Processing data"
override def icon: String = "/assets/activities/processingData.svg"
override def supportedActions: List[String] = commentRelatedActions
private val displayableName: String = "Processing data"
override def displayableNameForScenario: String = displayableName
override def displayableNameForFragment: String = displayableName
override def icon: String = "/assets/activities/processingData.svg"
override def supportedActions: List[String] = commentRelatedActions
}

case object PerformedScheduledExecution extends ScenarioActivityType {
override def displayableName(scenarioType: ScenarioType): String = "Processing data"
override def icon: String = "/assets/activities/processingData.svg"
override def supportedActions: List[String] = List.empty
private val displayableName: String = "Processing data"
override def displayableNameForScenario: String = displayableName
override def displayableNameForFragment: String = displayableName
override def icon: String = "/assets/activities/processingData.svg"
override def supportedActions: List[String] = List.empty
}

case object AutomaticUpdate extends ScenarioActivityType {
override def displayableName(scenarioType: ScenarioType): String = "Automatic update"
override def icon: String = "/assets/activities/automaticUpdate.svg"
override def supportedActions: List[String] = List("compare")
private val displayableName: String = "Automatic update"
override def displayableNameForScenario: String = displayableName
override def displayableNameForFragment: String = displayableName
override def icon: String = "/assets/activities/automaticUpdate.svg"
override def supportedActions: List[String] = List("compare")
}

case object CustomAction extends ScenarioActivityType {
override def displayableName(scenarioType: ScenarioType): String = "Custom action"
override def icon: String = "/assets/activities/customAction.svg"
override def supportedActions: List[String] = List.empty
private val displayableName: String = "Custom action"
override def displayableNameForScenario: String = displayableName
override def displayableNameForFragment: String = displayableName
override def icon: String = "/assets/activities/customAction.svg"
override def supportedActions: List[String] = List.empty
}

override def values: immutable.IndexedSeq[ScenarioActivityType] = findValues
Expand Down
Loading

0 comments on commit 4639cf3

Please sign in to comment.