-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TDRD-225 Metadata Reviews page (#4003)
- Loading branch information
Showing
12 changed files
with
202 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package controllers | ||
|
||
import auth.TokenSecurity | ||
import configuration.KeycloakConfiguration | ||
import org.pac4j.play.scala.SecurityComponents | ||
import play.api.mvc.{Action, AnyContent, Request} | ||
import services.ConsignmentService | ||
|
||
import javax.inject.Inject | ||
|
||
class MetadataReviewController @Inject() ( | ||
val keycloakConfiguration: KeycloakConfiguration, | ||
val controllerComponents: SecurityComponents, | ||
val consignmentService: ConsignmentService | ||
) extends TokenSecurity { | ||
|
||
def metadataReviews(): Action[AnyContent] = tnaUserAction { implicit request: Request[AnyContent] => | ||
for { | ||
consignments <- consignmentService.getConsignmentsForReview(request.token.bearerAccessToken) | ||
} yield { | ||
Ok(views.html.tna.metadataReviews(consignments)) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
@import graphql.codegen.GetConsignmentsForMetadataReview.{getConsignmentsForMetadataReview => gcfmr} | ||
@(consignments: List[gcfmr.GetConsignmentsForMetadataReview])(implicit messages: Messages, request: RequestHeader) | ||
|
||
@main("Metadata Reviews", isTnaUser= true) { | ||
<div class="govuk-grid-row"> | ||
<div class="govuk-grid-column-full"> | ||
|
||
<span class="govuk-caption-l">Transfer Digital records</span> | ||
<h1 class="govuk-heading-l">Metadata Reviews</h1> | ||
<p class="govuk-body">These are requested reviews that have not been responded to.</p> | ||
|
||
<table data-module="table-row-expander" class="govuk-table govuk-table--tdr-transfers govuk-!-margin-bottom-2"> | ||
<thead class="govuk-table__head"> | ||
<tr class="govuk-table__row"> | ||
<th scope="col" class="govuk-table__header">Consignment</th> | ||
<th scope="col" class="govuk-table__header">Status</th> | ||
<th scope="col" class="govuk-table__header">Department</th> | ||
<th scope="col" class="govuk-table__header">Series</th> | ||
<th scope="col" class="govuk-table__header"></th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
@for((consignment, index) <- consignments.zipWithIndex) { | ||
<tr class="govuk-table__row"> | ||
<th scope="row" class="govuk-table__header">@consignment.consignmentReference</th> | ||
<td class="govuk-table__cell"> | ||
<strong class="tdr-tag tdr-tag--green">Requested</strong> | ||
</td> | ||
<td class="govuk-table__cell">@consignment.transferringBodyName</td> | ||
<td class="govuk-table__cell">@consignment.seriesName</td> | ||
<td class="govuk-table__cell"> | ||
<div class="tdr-link-group"> | ||
<a href="#" class="govuk-link govuk-link--no-visited-state">View request</a> | ||
</div> | ||
</td> | ||
</tr> | ||
} | ||
</tbody> | ||
</table> | ||
</div> | ||
</div> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
package controllers | ||
|
||
import com.github.tomakehurst.wiremock.WireMockServer | ||
import configuration.GraphQLConfiguration | ||
import org.scalatest.matchers.should.Matchers._ | ||
import play.api.Play.materializer | ||
import play.api.http.Status.{FORBIDDEN, FOUND, OK} | ||
import play.api.test.CSRFTokenHelper.CSRFRequest | ||
import play.api.test.FakeRequest | ||
import play.api.test.Helpers.{GET, contentAsString, contentType, defaultAwaitTimeout, redirectLocation, status} | ||
import services.ConsignmentService | ||
import testUtils.{CheckPageForStaticElements, FrontEndTestHelper} | ||
|
||
import scala.concurrent.ExecutionContext | ||
|
||
class MetadataReviewControllerSpec extends FrontEndTestHelper { | ||
val wiremockServer = new WireMockServer(9006) | ||
|
||
override def beforeEach(): Unit = { | ||
wiremockServer.start() | ||
} | ||
|
||
override def afterEach(): Unit = { | ||
wiremockServer.resetAll() | ||
wiremockServer.stop() | ||
} | ||
|
||
val checkPageForStaticElements = new CheckPageForStaticElements | ||
|
||
private val TNAUserType = "tna" | ||
|
||
implicit val ec: ExecutionContext = ExecutionContext.global | ||
|
||
"MetadataReviewController GET" should { | ||
|
||
"render the metadata review page" in { | ||
setGetConsignmentsForMetadataReviewResponse(wiremockServer) | ||
val graphQLConfiguration = new GraphQLConfiguration(app.configuration) | ||
val consignmentService = new ConsignmentService(graphQLConfiguration) | ||
val controller = new MetadataReviewController(getValidTNAUserKeycloakConfiguration, getAuthorisedSecurityComponents, consignmentService) | ||
val response = controller | ||
.metadataReviews() | ||
.apply(FakeRequest(GET, s"/metadata-review").withCSRFToken) | ||
val metadataReviewPageAsString = contentAsString(response) | ||
|
||
status(response) mustBe OK | ||
contentType(response) mustBe Some("text/html") | ||
|
||
checkPageForStaticElements.checkContentOfPagesThatUseMainScala(metadataReviewPageAsString, userType = TNAUserType, consignmentExists = false) | ||
checkForExpectedMetadataReviewPageContent(metadataReviewPageAsString) | ||
} | ||
|
||
"return 403 if the metadata review page is accessed by a non TNA user" in { | ||
val graphQLConfiguration = new GraphQLConfiguration(app.configuration) | ||
val consignmentService = new ConsignmentService(graphQLConfiguration) | ||
val controller = new MetadataReviewController(getValidKeycloakConfiguration, getAuthorisedSecurityComponents, consignmentService) | ||
val response = controller | ||
.metadataReviews() | ||
.apply(FakeRequest(GET, s"/metadata-review").withCSRFToken) | ||
|
||
status(response) mustBe FORBIDDEN | ||
} | ||
|
||
"redirect to the login page if the page is accessed by a logged out user" in { | ||
val graphQLConfiguration = new GraphQLConfiguration(app.configuration) | ||
val consignmentService = new ConsignmentService(graphQLConfiguration) | ||
val controller = new MetadataReviewController(getValidKeycloakConfiguration, getUnauthorisedSecurityComponents, consignmentService) | ||
val response = controller | ||
.metadataReviews() | ||
.apply(FakeRequest(GET, s"/metadata-review").withCSRFToken) | ||
|
||
status(response) mustBe FOUND | ||
redirectLocation(response).get must startWith("/auth/realms/tdr/protocol/openid-connect/auth") | ||
} | ||
} | ||
|
||
def checkForExpectedMetadataReviewPageContent(metadataReviewPageAsString: String, consignmentExists: Boolean = true): Unit = { | ||
metadataReviewPageAsString must include("<h1 class=\"govuk-heading-l\">Metadata Reviews</h1>") | ||
metadataReviewPageAsString must include("""<th scope="col" class="govuk-table__header">Consignment</th>""") | ||
metadataReviewPageAsString must include("""<th scope="col" class="govuk-table__header">Status</th>""") | ||
metadataReviewPageAsString must include("""<th scope="col" class="govuk-table__header">Department</th>""") | ||
metadataReviewPageAsString must include("""<th scope="col" class="govuk-table__header">Series</th>""") | ||
metadataReviewPageAsString must include("""<th scope="col" class="govuk-table__header"></th>""") | ||
metadataReviewPageAsString must include(s"""These are requested reviews that have not been responded to.""") | ||
metadataReviewPageAsString must include(s"""<th scope="row" class="govuk-table__header">TDR-2024-TEST</th>""") | ||
metadataReviewPageAsString must include(s"""<strong class="tdr-tag tdr-tag--green">Requested</strong>""") | ||
metadataReviewPageAsString must include(s"""<td class="govuk-table__cell">TransferringBody</td>""") | ||
metadataReviewPageAsString must include(s"""<td class="govuk-table__cell">SeriesName</td>""") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters