Skip to content

Commit

Permalink
Merge pull request #4039 from nationalarchives/TDRD-226-DTA-Review-Page
Browse files Browse the repository at this point in the history
Tdrd 226 dta review page
  • Loading branch information
Tom-Hallett authored Jul 23, 2024
2 parents fcd8dd1 + d6edaea commit 625e79a
Show file tree
Hide file tree
Showing 15 changed files with 590 additions and 145 deletions.
63 changes: 63 additions & 0 deletions app/controllers/MetadataReviewStatusController.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package controllers

import auth.TokenSecurity
import configuration.{ApplicationConfig, KeycloakConfiguration}
import graphql.codegen.types.ConsignmentStatusInput
import org.pac4j.play.scala.SecurityComponents
import play.api.mvc.{Action, AnyContent, Request}
import services.{ConsignmentService, ConsignmentStatusService}
import services.Statuses._

import java.util.UUID
import javax.inject.Inject
import scala.concurrent.Future

class MetadataReviewStatusController @Inject() (
val controllerComponents: SecurityComponents,
val consignmentService: ConsignmentService,
val consignmentStatusService: ConsignmentStatusService,
val keycloakConfiguration: KeycloakConfiguration,
val applicationConfig: ApplicationConfig
) extends TokenSecurity {

def metadataReviewStatusPage(consignmentId: UUID): Action[AnyContent] = standardTypeAction(consignmentId) { implicit request: Request[AnyContent] =>
if (applicationConfig.blockMetadataReview) {
Future(Ok(views.html.notFoundError(name = request.token.name, isLoggedIn = true, isJudgmentUser = false)))
} else {
for {
consignmentStatus <- consignmentStatusService.consignmentStatusSeries(consignmentId, request.token.bearerAccessToken)
reviewStatus = consignmentStatus.flatMap(s => consignmentStatusService.getStatusValues(s.consignmentStatuses, MetadataReviewType).values.headOption.flatten)
reference <- consignmentService.getConsignmentRef(consignmentId, request.token.bearerAccessToken)
result <- reviewStatus match {
case Some(InProgressValue.value) | Some(CompletedValue.value) | Some(CompletedWithIssuesValue.value) =>
Future(
Ok(views.html.standard.metadataReviewStatus(consignmentId, reference, request.token.name, request.token.email, reviewStatus.get))
)
case None =>
Future(Ok(views.html.notFoundError(name = request.token.name, isLoggedIn = true, isJudgmentUser = false)))
case _ =>
throw new IllegalStateException(s"Unexpected review status: $reviewStatus for consignment $consignmentId")
}
} yield result
}
}

def metadataReviewActionRequired(consignmentId: UUID): Action[AnyContent] = standardTypeAction(consignmentId) { implicit request: Request[AnyContent] =>
for {
_ <- consignmentStatusService.updateConsignmentStatus(
ConsignmentStatusInput(consignmentId, DescriptiveMetadataType.id, Some(InProgressValue.value)),
request.token.bearerAccessToken
)
_ <- consignmentStatusService.updateConsignmentStatus(
ConsignmentStatusInput(consignmentId, ClosureMetadataType.id, Some(InProgressValue.value)),
request.token.bearerAccessToken
)
_ <- consignmentStatusService.updateConsignmentStatus(
ConsignmentStatusInput(consignmentId, DraftMetadataType.id, Some(InProgressValue.value)),
request.token.bearerAccessToken
)
} yield {
Redirect(routes.AdditionalMetadataController.start(consignmentId))
}
}
}
16 changes: 13 additions & 3 deletions app/controllers/RequestMetadataReviewController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package controllers

import auth.TokenSecurity
import configuration.{ApplicationConfig, KeycloakConfiguration}
import graphql.codegen.types.ConsignmentStatusInput
import org.pac4j.play.scala.SecurityComponents
import play.api.mvc.{Action, AnyContent, Request}
import services.MessagingService.MetadataReviewRequestEvent
Expand Down Expand Up @@ -34,9 +35,17 @@ class RequestMetadataReviewController @Inject() (
}

def submitMetadataForReview(consignmentId: UUID): Action[AnyContent] = standardTypeAction(consignmentId) { implicit request: Request[AnyContent] =>
val token = request.token.bearerAccessToken
for {
_ <- consignmentStatusService.addConsignmentStatus(consignmentId, MetadataReviewType.id, InProgressValue.value, request.token.bearerAccessToken)
summary <- consignmentService.getConsignmentConfirmTransfer(consignmentId, request.token.bearerAccessToken)
consignmentStatuses <- consignmentStatusService.getConsignmentStatuses(consignmentId, token)
statusesToValue = consignmentStatusService.getStatusValues(consignmentStatuses, MetadataReviewType).values.headOption.flatten
_ <-
if (statusesToValue.isEmpty) {
consignmentStatusService.addConsignmentStatus(consignmentId, MetadataReviewType.id, InProgressValue.value, token)
} else {
consignmentStatusService.updateConsignmentStatus(ConsignmentStatusInput(consignmentId, MetadataReviewType.id, Some(InProgressValue.value)), token)
}
summary <- consignmentService.getConsignmentConfirmTransfer(consignmentId, token)
} yield {
messagingService.sendMetadataReviewRequestNotification(
MetadataReviewRequestEvent(
Expand All @@ -47,7 +56,8 @@ class RequestMetadataReviewController @Inject() (
userEmail = request.token.email
)
)
Ok(views.html.standard.metadataReviewStatus(consignmentId, summary.consignmentReference, request.token.name))

Redirect(routes.MetadataReviewStatusController.metadataReviewStatusPage(consignmentId))
}
}
}
2 changes: 2 additions & 0 deletions app/services/Statuses.scala
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ object Statuses {
case SeriesType.id => SeriesType
case DescriptiveMetadataType.id => DescriptiveMetadataType
case ClosureMetadataType.id => ClosureMetadataType
case DraftMetadataType.id => DraftMetadataType
case MetadataReviewType.id => MetadataReviewType
case _ => UnrecognisedType
}
}
Expand Down
10 changes: 10 additions & 0 deletions app/views/partials/downloadMetadataLink.scala.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
@import java.util.UUID
@(consignmentId: UUID, linkLabel: String = "Download metadata")
<a class="govuk-button govuk-button--secondary govuk-!-margin-bottom-8 download-metadata" href="/consignment/@consignmentId/additional-metadata/download-metadata/csv">
<span aria-hidden="true" class="tna-button-icon">
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 23 23">
<path fill="#020202" d="m11.5 16.75-6.563-6.563 1.838-1.903 3.412 3.413V1h2.626v10.697l3.412-3.413 1.837 1.903L11.5 16.75ZM3.625 22c-.722 0-1.34-.257-1.853-.77A2.533 2.533 0 0 1 1 19.375v-3.938h2.625v3.938h15.75v-3.938H22v3.938c0 .722-.257 1.34-.77 1.855a2.522 2.522 0 0 1-1.855.77H3.625Z"></path>
</svg>
</span>
@linkLabel
</a>
40 changes: 40 additions & 0 deletions app/views/partials/metadataReviewFailure.scala.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
@import java.util.UUID
@import views.html.helper.form
@import views.html.helper.CSRF
@import views.html.partials.downloadMetadataLink

@(consignmentId: UUID, email: String)(implicit request: RequestHeader)
<div class="da-alert da-alert--error da-alert--with-icon">
<div class="da-alert__icon">
<div aria-hidden="true"><svg class="da-icon da-icon--xxl" viewBox="0 0 23 23" xmlns="http://www.w3.org/2000/svg" focusable="false" fill="currentColor" role="img" title="da-icon-warning">
<g clip-path="url(#a)">
<path d="M11.5 0C17.851 0 23 5.149 23 11.5S17.851 23 11.5 23 0 17.851 0 11.5 5.149 0 11.5 0Zm0 2.3a9.2 9.2 0 1 0 0 18.4 9.2 9.2 0 0 0 0-18.4Z"></path>
<path d="M11.5 4c-.208 0-.414.046-.605.135-.19.09-.362.221-.502.385-.141.164-.248.358-.315.568-.066.21-.09.434-.072.655l.6 7.01a.982.982 0 0 0 .293.613.87.87 0 0 0 .602.246.87.87 0 0 0 .602-.246.982.982 0 0 0 .293-.612l.598-7.011a1.697 1.697 0 0 0-.072-.654 1.623 1.623 0 0 0-.314-.568 1.506 1.506 0 0 0-.502-.385A1.421 1.421 0 0 0 11.5 4Zm0 14c.35 0 .684-.148.93-.41.246-.263.385-.619.385-.99s-.139-.727-.385-.99a1.274 1.274 0 0 0-.93-.41c-.348 0-.682.148-.928.41a1.448 1.448 0 0 0-.385.99c0 .371.138.727.385.99.246.262.58.41.929.41Z"></path>
</g>
<defs>
<clipPath>
<path fill="#fff" d="M0 0h23v23H0z"></path>
</clipPath>
</defs>
</svg>
</div>
</div>
<div class="da-alert__content">
<h2 class="da-alert__heading">We found issues in your metadata</h2>
<p>We have emailed guidance to <strong>@email</strong></p>
</div>
</div>

<p class="govuk-body">Follow the guidance to amend your metadata. You can download a copy of the metadata we reviewed below.</p>

@downloadMetadataLink(consignmentId)


@form(routes.MetadataReviewStatusController.metadataReviewActionRequired(consignmentId), (Symbol("novalidate"), "")) {
@CSRF.formField
<div class="govuk-button-group">
<button data-prevent-double-click="true" class="govuk-button" type="submit" data-module="govuk-button" role="button">
Continue
</button>
</div>
}
26 changes: 26 additions & 0 deletions app/views/partials/metadataReviewInProgress.scala.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
@import java.util.UUID
@import views.html.partials.downloadMetadataLink
@(consignmentId: UUID, consignmentRef: String, email: String)(implicit messages: Messages)
<div class="da-alert da-alert--with-icon">
<div class="da-alert__icon">
<div aria-hidden="true"><svg class="da-icon da-icon--xl" viewBox="0 0 12 12" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" role="img" title="da-icon-search">
<path d="M11.86 10.23 8.62 6.99a4.63 4.63 0 1 0-6.34 1.64 4.55 4.55 0 0 0 2.36.64 4.65 4.65 0 0 0 2.33-.65l3.24 3.23a.46.46 0 0 0 .65 0l1-1a.48.48 0 0 0 0-.62Zm-5-3.32a3.28 3.28 0 0 1-2.31.93 3.22 3.22 0 1 1 2.35-.93Z"></path>
</svg></div>
</div>
<div class="da-alert__content">
<h2 class="da-alert__heading">Your review is in progress</h2>
<p>When the review is complete you will receive an email to <strong>@email</strong> with further instructions.</p>
</div>
</div>

<p class="govuk-body">
You can leave and return to this page at any time from the <a class="govuk-notification-banner__link" href="@routes.ViewTransfersController.viewConsignments(1)">
View transfers</a> page.</p>

<p class="govuk-body">Download a copy of the metadata you submitted below.</p>

@downloadMetadataLink(consignmentId)

<p class="govuk-body">
If you have any queries email <a href="mailto:@Messages("nationalArchives.email")">@Messages("nationalArchives.email")</a>
quoting the consignment reference: @consignmentRef</p>
25 changes: 25 additions & 0 deletions app/views/partials/metadataReviewSuccess.scala.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
@import java.util.UUID
@(consignmentId: UUID)
<div class="da-alert da-alert--success da-alert--with-icon">
<div class="da-alert__icon">
<div aria-hidden="true"><svg class="da-icon da-icon--xl" viewBox="0 0 13 10" xmlns="http://www.w3.org/2000/svg" focusable="false" fill="currentColor" role="img" title="da-icon-check">
<path d="M14.35,3.9l-.71-.71a.5.5,0,0,0-.71,0h0L5.79,10.34,3.07,7.61a.51.51,0,0,0-.71,0l-.71.71a.51.51,0,0,0,0,.71l3.78,3.78a.5.5,0,0,0,.71,0h0L14.35,4.6A.5.5,0,0,0,14.35,3.9Z" transform="translate(-1.51 -3.04)"></path>
</svg></div>
</div>
<div class="da-alert__content">
<h2 class="da-alert__heading">You can now complete your transfer</h2>
<p>
The metadata you submitted has been reviewed and no issues were found.
</p>
</div>
</div>

<p class="govuk-body">
You can now continue to confirm your transfer.
</p>

<div class="govuk-button-group">
<a class="govuk-button" href="@routes.ConfirmTransferController.confirmTransfer(consignmentId)" role="button" draggable="false" data-module="govuk-button">
Continue
</a>
</div>
40 changes: 26 additions & 14 deletions app/views/standard/metadataReviewStatus.scala.html
Original file line number Diff line number Diff line change
@@ -1,18 +1,30 @@
@import java.util.UUID
@import views.html.partials.transferReference
@import views.html.partials.backLink
@(consignmentId: UUID, consignmentRef: String, name: String)(implicit messages: Messages, request: RequestHeader)
@import views.html.partials.{metadataReviewInProgress, metadataReviewSuccess, metadataReviewFailure, transferReference}
@import services.Statuses.{InProgressValue, CompletedValue, CompletedWithIssuesValue}

@defining("Metadata review") { title =>
@main(title, name = name, backLink = Some(backLink(routes.RequestMetadataReviewController.requestMetadataReviewPage(consignmentId).url, "Back"))) {
@defining(play.core.PlayVersion.current) { version =>
<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds-from-desktop">
@(consignmentId: UUID, consignmentRef: String, name: String, email: String, DTAStatus: String)(implicit messages: Messages, request: RequestHeader)

<h1 class="govuk-heading-xl">@title</h1>
</div>
@transferReference(consignmentRef, isJudgmentUser = false)
</div>
@defining("Metadata review") { title =>
@main(title, name = name) {

<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds-from-desktop">

<h1 class="govuk-heading-xl">@title</h1>

@{
DTAStatus match {
case CompletedWithIssuesValue.value => metadataReviewFailure(consignmentId, email)
case CompletedValue.value => metadataReviewSuccess(consignmentId)
case InProgressValue.value => metadataReviewInProgress(consignmentId, consignmentRef, email)
case _ => {
<h2>Error - cannot find status</h2>
}
}
}
</div>
@transferReference(consignmentRef, isJudgmentUser = false)
</div>

}
}
}
}
15 changes: 10 additions & 5 deletions app/views/standard/requestMetadataReview.scala.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
@import views.html.helper.form
@import views.html.helper.CSRF
@import java.util.UUID
@import views.html.partials.transferReference
@import views.html.partials.backLink
Expand All @@ -18,11 +20,14 @@ <h1 class="govuk-heading-xl">@title</h1>

<p class="govuk-body">Once you have submitted your metadata for review we recommend you don't make further changes to your metadata CSV. If you need to make any changes before requesting a review <a href="@routes.AdditionalMetadataController.start(consignmentId)" class="govuk-link">return to Record metadata</a> to edit the metadata.</p>

<div class="govuk-button-group">
<a href="@routes.RequestMetadataReviewController.submitMetadataForReview(consignmentId)" role="button" draggable="false" class="govuk-button" data-module="govuk-button">
Submit metadata for review
</a>
</div>
@form(routes.RequestMetadataReviewController.submitMetadataForReview(consignmentId), (Symbol("novalidate"), "")) {
@CSRF.formField
<div class="govuk-button-group">
<button data-prevent-double-click="true" class="govuk-button" type="submit" data-module="govuk-button" role="button">
Submit metadata for review
</button>
</div>
}

</div>
@transferReference(consignmentRef, isJudgmentUser = false)
Expand Down
5 changes: 5 additions & 0 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ libraryDependencies += "com.github.karelcemus" %% "play-redis" % "5.0.0"
libraryDependencies += "org.dhatim" % "fastexcel" % "0.18.0"
libraryDependencies += "org.dhatim" % "fastexcel-reader" % "0.18.0"

excludeDependencies ++= Seq(
ExclusionRule(organization = "com.typesafe.akka"),
ExclusionRule(organization = "com.typesafe.play")
)

pipelineStages := Seq(digest)

excludeDependencies ++= Seq(
Expand Down
Loading

0 comments on commit 625e79a

Please sign in to comment.