Skip to content

Commit

Permalink
Merge branch 'master' into TDRD-598-update-guide-with-mfa-changes
Browse files Browse the repository at this point in the history
  • Loading branch information
thanhz authored Nov 19, 2024
2 parents cb4ac7d + b99e33b commit bbd124d
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 14 deletions.
5 changes: 5 additions & 0 deletions app/controllers/DraftMetadataUploadController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ import cats.effect.IO
import cats.effect.IO.fromOption
import cats.effect.unsafe.implicits.global
import configuration.{ApplicationConfig, KeycloakConfiguration}
import graphql.codegen.types.ConsignmentStatusInput
import org.pac4j.play.scala.SecurityComponents
import play.api._
import play.api.i18n.I18nSupport
import play.api.libs.Files.TemporaryFile
import play.api.mvc._
import services.Statuses.{DraftMetadataType, InProgressValue}
import services._
import viewsapi.Caching.preventCaching

Expand All @@ -26,6 +28,7 @@ class DraftMetadataUploadController @Inject() (
val consignmentService: ConsignmentService,
val uploadService: UploadService,
val draftMetadataService: DraftMetadataService,
val consignmentStatusService: ConsignmentStatusService,
val applicationConfig: ApplicationConfig
)(implicit val ec: ExecutionContext)
extends TokenSecurity
Expand Down Expand Up @@ -54,8 +57,10 @@ class DraftMetadataUploadController @Inject() (
val uploadFileName = applicationConfig.draftMetadataFileName
val uploadKey = s"$consignmentId/$uploadFileName"
val noDraftMetadataFileUploaded: String = "No meta data file provided"
val consignmentStatusInput = ConsignmentStatusInput(consignmentId, DraftMetadataType.id, Some(InProgressValue.value))

def uploadDraftMetadata: IO[Result] = for {
_ <- IO.fromFuture(IO(consignmentStatusService.updateConsignmentStatus(consignmentStatusInput, token.bearerAccessToken)))
firstFilePart <- fromOption(request.body.files.headOption)(new RuntimeException(noDraftMetadataFileUploaded))
file <- fromOption(request.body.file(firstFilePart.key))(new RuntimeException(noDraftMetadataFileUploaded))
draftMetadata <- fromOption(Using(scala.io.Source.fromFile(file.ref.getAbsoluteFile))(_.mkString).toOption)(new RuntimeException(noDraftMetadataFileUploaded))
Expand Down
22 changes: 11 additions & 11 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,17 @@ libraryDependencies ++= Seq(
"com.softwaremill.sttp.client" %% "core" % sttpVersion,
"com.softwaremill.sttp.client" %% "circe" % sttpVersion,
"com.softwaremill.sttp.client" %% "async-http-client-backend-future" % sttpVersion,
"uk.gov.nationalarchives" %% "tdr-graphql-client" % "0.0.190",
"uk.gov.nationalarchives" %% "tdr-auth-utils" % "0.0.217",
"uk.gov.nationalarchives" %% "tdr-generated-graphql" % "0.0.390",
"uk.gov.nationalarchives" %% "tdr-graphql-client" % "0.0.194",
"uk.gov.nationalarchives" %% "tdr-auth-utils" % "0.0.220",
"uk.gov.nationalarchives" %% "tdr-generated-graphql" % "0.0.391",
"uk.gov.nationalarchives" %% "tdr-metadata-validation" % "0.0.60",
"uk.gov.nationalarchives" %% "s3-utils" % "0.1.215",
"uk.gov.nationalarchives" %% "sns-utils" % "0.1.215",
"ch.qos.logback" % "logback-classic" % "1.5.11",
"uk.gov.nationalarchives" %% "s3-utils" % "0.1.221",
"uk.gov.nationalarchives" %% "sns-utils" % "0.1.221",
"ch.qos.logback" % "logback-classic" % "1.5.12",
ws,
"io.opentelemetry" % "opentelemetry-api" % "1.43.0",
"io.opentelemetry" % "opentelemetry-exporter-otlp" % "1.43.0",
"io.opentelemetry" % "opentelemetry-sdk" % "1.43.0",
"io.opentelemetry" % "opentelemetry-api" % "1.44.1",
"io.opentelemetry" % "opentelemetry-exporter-otlp" % "1.44.1",
"io.opentelemetry" % "opentelemetry-sdk" % "1.44.1",
"io.opentelemetry" % "opentelemetry-extension-aws" % "1.20.1",
"io.opentelemetry" % "opentelemetry-sdk-extension-aws" % "1.19.0",
"io.opentelemetry.contrib" % "opentelemetry-aws-xray" % "1.40.0",
Expand All @@ -48,8 +48,8 @@ libraryDependencies ++= Seq(
)
libraryDependencies += "org.scala-lang.modules" %% "scala-java8-compat" % "1.0.2"

dependencyOverrides += "com.fasterxml.jackson.core" % "jackson-databind" % "2.17.0"
dependencyOverrides += "com.fasterxml.jackson.core" % "jackson-core" % "2.17.0"
dependencyOverrides += "com.fasterxml.jackson.core" % "jackson-databind" % "2.17.3"
dependencyOverrides += "com.fasterxml.jackson.core" % "jackson-core" % "2.17.3"

disablePlugins(PlayLogback)
scalacOptions ++= Seq("-language:implicitConversions")
Expand Down
2 changes: 1 addition & 1 deletion project/build.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sbt.version=1.10.3
sbt.version=1.10.5
9 changes: 7 additions & 2 deletions test/controllers/DraftMetadataUploadControllerSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import play.api.mvc.{MultipartFormData, Result}
import play.api.test.CSRFTokenHelper._
import play.api.test.Helpers.{status => playStatus, _}
import play.api.test.{FakeHeaders, FakeRequest}
import services.{ConsignmentService, DraftMetadataService, FileError, UploadService}
import services.{ConsignmentService, ConsignmentStatusService, DraftMetadataService, FileError, UploadService}
import software.amazon.awssdk.services.s3.model.PutObjectResponse
import testUtils.FrontEndTestHelper

Expand All @@ -41,7 +41,7 @@ class DraftMetadataUploadControllerSpec extends FrontEndTestHelper {
wiremockServer.stop()
}

"DraftMetadataUploadControllerSpec GET" should {
"DraftMetadataUploadController GET" should {
"render 'draft metadata upload' page when 'blockDraftMetadataUpload' set to 'false'" in {

val controller = instantiateDraftMetadataUploadController(blockDraftMetadataUpload = false)
Expand Down Expand Up @@ -101,12 +101,15 @@ class DraftMetadataUploadControllerSpec extends FrontEndTestHelper {
.apply(FakeRequest(GET, "/draft-metadata/upload").withCSRFToken)
playStatus(draftMetadataUploadPage) mustBe FORBIDDEN
}
}

"DraftMetadataUploadController saveDraftMetadata" should {
"redirect to draft metadata checks page when upload successful" in {
val uploadServiceMock = mock[UploadService]
when(configuration.get[String]("draftMetadata.fileName")).thenReturn(uploadFilename)
val putObjectResponse = PutObjectResponse.builder().eTag("testEtag").build()
when(uploadServiceMock.uploadDraftMetadata(anyString, anyString, anyString)).thenReturn(Future.successful(putObjectResponse))
setUpdateConsignmentStatus(wiremockServer)

val draftMetadataServiceMock = mock[DraftMetadataService]
when(draftMetadataServiceMock.triggerDraftMetadataValidator(any[UUID], anyString, anyString)).thenReturn(Future.successful(true))
Expand Down Expand Up @@ -163,6 +166,7 @@ class DraftMetadataUploadControllerSpec extends FrontEndTestHelper {
val applicationConfig: ApplicationConfig = new ApplicationConfig(configuration)
val graphQLConfiguration = new GraphQLConfiguration(app.configuration)
val consignmentService = new ConsignmentService(graphQLConfiguration)
val consignmentStatusService = new ConsignmentStatusService(graphQLConfiguration)

new DraftMetadataUploadController(
securityComponents,
Expand All @@ -171,6 +175,7 @@ class DraftMetadataUploadControllerSpec extends FrontEndTestHelper {
consignmentService,
uploadService,
draftMetadataService,
consignmentStatusService,
applicationConfig
)
}
Expand Down

0 comments on commit bbd124d

Please sign in to comment.