Skip to content

Commit

Permalink
Merge branch 'staging' into preview/aggregate-ui
Browse files Browse the repository at this point in the history
  • Loading branch information
JulianWielga authored Oct 24, 2024
2 parents c110f56 + 0d8c7da commit 14d3bff
Show file tree
Hide file tree
Showing 29 changed files with 1,041 additions and 448 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,16 @@ 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
}

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)
}
2 changes: 2 additions & 0 deletions designer/server/src/main/resources/defaultDesignerConfig.conf
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ db {
minimumIdle: 1
#has to be lower <= maxConnections
numThreads: 5
registerMbeans: true
poolName: "Nussknacker"
properties: {
# PostgreSQL specific
"ApplicationName": "Nussknacker"
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,18 @@ import pl.touk.nussknacker.security.Permission
import pl.touk.nussknacker.security.Permission.Permission
import pl.touk.nussknacker.ui.api.description.scenarioActivity.Dtos.ScenarioActivityError.{
NoActivity,
NoAttachment,
NoComment,
NoPermission,
NoScenario
}
import pl.touk.nussknacker.ui.api.description.scenarioActivity.Dtos._
import pl.touk.nussknacker.ui.api.description.scenarioActivity.{Dtos, Endpoints}
import pl.touk.nussknacker.ui.process.ProcessService.GetScenarioWithDetailsOptions
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 All @@ -29,6 +32,7 @@ import sttp.model.MediaType

import java.io.ByteArrayInputStream
import java.net.URLConnection
import java.time.ZoneId
import scala.concurrent.{ExecutionContext, Future}

class ScenarioActivityApiHttpService(
Expand All @@ -44,9 +48,11 @@ class ScenarioActivityApiHttpService(
extends BaseHttpService(authManager)
with LazyLogging {

private implicit val zoneId: ZoneId = ZoneId.systemDefault()

private val securityInput = authManager.authenticationEndpointInput()

private val endpoints = new Endpoints(securityInput, streamEndpointProvider)
private val endpoints = new Endpoints(securityInput, streamEndpointProvider, zoneId)

expose {
endpoints.deprecatedScenarioActivityEndpoint
Expand Down Expand Up @@ -96,6 +102,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 @@ -140,7 +158,14 @@ class ScenarioActivityApiHttpService(
for {
scenarioId <- getScenarioIdByName(scenarioName)
_ <- isAuthorized(scenarioId, Permission.Read)
metadata = ScenarioActivitiesMetadata.default
scenarioWithDetails <- EitherT.right(
scenarioService.getLatestProcessWithDetails(
ProcessIdWithName(scenarioId, scenarioName),
GetScenarioWithDetailsOptions.detailsOnly
)
)
scenarioType = if (scenarioWithDetails.isFragment) ScenarioType.Fragment else ScenarioType.Scenario
metadata = ScenarioActivitiesMetadata.default(scenarioType)
} yield metadata
}
}
Expand Down Expand Up @@ -246,21 +271,19 @@ class ScenarioActivityApiHttpService(
} yield sortedResult
}

private def toDto(scenarioComment: ScenarioComment): Dtos.ScenarioActivityComment = {
scenarioComment match {
case ScenarioComment.Available(comment, lastModifiedByUserName, lastModifiedAt) =>
Dtos.ScenarioActivityComment(
content = Dtos.ScenarioActivityCommentContent.Available(comment),
lastModifiedBy = lastModifiedByUserName.value,
lastModifiedAt = lastModifiedAt,
)
case ScenarioComment.Deleted(deletedByUserName, deletedAt) =>
Dtos.ScenarioActivityComment(
content = Dtos.ScenarioActivityCommentContent.Deleted,
lastModifiedBy = deletedByUserName.value,
lastModifiedAt = deletedAt,
)
}
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 @@ -558,6 +581,15 @@ class ScenarioActivityApiHttpService(
)
}

private def markAttachmentAsDeleted(request: DeleteAttachmentRequest, scenarioId: ProcessId)(
implicit loggedUser: LoggedUser
): EitherT[Future, ScenarioActivityError, Unit] =
EitherT(
dbioActionRunner.run(
scenarioActivityRepository.markAttachmentAsDeleted(scenarioId, request.attachmentId)
)
).leftMap { case DeleteAttachmentError.CouldNotDeleteAttachment => NoAttachment(request.attachmentId) }

private def buildResponse(maybeAttachment: Option[(String, Array[Byte])]): GetAttachmentResponse =
maybeAttachment match {
case Some((fileName, content)) =>
Expand Down
Loading

0 comments on commit 14d3bff

Please sign in to comment.