-
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-373 DTA Add email address to request details page (#4061)
* New userDetails method * Replace userId with email in dta action page * Alter `MetadataReviewSubmittedEvent`to include status and userEmail * Read `READ_AUTH_SECRET` environment variable
- Loading branch information
Showing
11 changed files
with
58 additions
and
29 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,26 @@ | ||
package configuration | ||
|
||
import javax.inject.Inject | ||
import play.api.Configuration | ||
import sttp.client3.{HttpURLConnectionBackend, Identity, SttpBackend} | ||
import uk.gov.nationalarchives.tdr.keycloak.{KeycloakUtils, TdrKeycloakDeployment, Token} | ||
|
||
import scala.concurrent.ExecutionContext | ||
import javax.inject.Inject | ||
import scala.concurrent.{ExecutionContext, Future} | ||
|
||
class KeycloakConfiguration @Inject() (configuration: Configuration)(implicit val executionContext: ExecutionContext) { | ||
implicit val backend: SttpBackend[Identity, Any] = HttpURLConnectionBackend() | ||
val authUrl: String = configuration.get[String]("auth.url") | ||
val secret: String = configuration.get[String]("read.auth.secret") | ||
|
||
def token(value: String): Option[Token] = { | ||
implicit val tdrKeycloakDeployment: TdrKeycloakDeployment = | ||
TdrKeycloakDeployment(s"${configuration.get[String]("auth.url")}", "tdr", 3600) | ||
TdrKeycloakDeployment(authUrl, "tdr", 3600) | ||
KeycloakUtils().token(value).toOption | ||
} | ||
|
||
def userDetails(userId: String): Future[KeycloakUtils.UserDetails] = { | ||
implicit val tdrKeycloakDeployment: TdrKeycloakDeployment = | ||
TdrKeycloakDeployment(authUrl, "tdr", 3600) | ||
KeycloakUtils().userDetails(userId, "tdr-user-read", secret) | ||
} | ||
} |
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
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 |
---|---|---|
|
@@ -46,12 +46,11 @@ class MetadataReviewActionControllerSpec extends FrontEndTestHelper { | |
|
||
"MetadataReviewActionController GET" should { | ||
|
||
"render the correct series details page with an authenticated user" in { | ||
"render the correct metadata details page with an authenticated user" in { | ||
setGetConsignmentDetailsForMetadataReviewResponse() | ||
|
||
val controller = instantiateMetadataReviewActionController(getAuthorisedSecurityComponents, getValidTNAUserKeycloakConfiguration) | ||
val metadataReviewActionPage = controller.consignmentMetadataDetails(consignmentId).apply(FakeRequest(GET, s"/admin/metadata-review/$consignmentId").withCSRFToken) | ||
|
||
val metadataReviewActionPageAsString = contentAsString(metadataReviewActionPage) | ||
|
||
playStatus(metadataReviewActionPage) mustBe OK | ||
|
@@ -75,23 +74,27 @@ class MetadataReviewActionControllerSpec extends FrontEndTestHelper { | |
status(response) mustBe FORBIDDEN | ||
} | ||
|
||
"Update the consignment status and send metadata decision message when a valid form is submitted and the api response is successful" in { | ||
"Update the consignment status and send MetadataReviewSubmittedEvent message when a valid form is submitted and the api response is successful" in { | ||
val controller = instantiateMetadataReviewActionController(getAuthorisedSecurityComponents, getValidTNAUserKeycloakConfiguration) | ||
val consignmentRef = "TDR-TEST-2024" | ||
val expectedPath = s"/consignment/$consignmentId/metadata-review/request" | ||
val userEmail = "[email protected]" | ||
val status = CompletedValue.value | ||
val expectedPath = s"/consignment/$consignmentId/metadata-review/review-progress" | ||
|
||
// Custom ArgumentMatcher to match the event based on the consignment reference and the path | ||
class MetadataReviewSubmittedEventMatcher(expectedConsignmentRef: String, expectedPath: String) extends ArgumentMatcher[MetadataReviewSubmittedEvent] { | ||
// Custom ArgumentMatcher to match the event based on the consignment reference, path, userEmail and status | ||
class MetadataReviewSubmittedEventMatcher(expectedConsignmentRef: String, expectedPath: String, expectedEmail: String, expectedStatus: String) | ||
extends ArgumentMatcher[MetadataReviewSubmittedEvent] { | ||
override def matches(event: MetadataReviewSubmittedEvent): Boolean = { | ||
event.consignmentReference == expectedConsignmentRef && event.urlLink.contains(expectedPath) | ||
event.consignmentReference == expectedConsignmentRef && event.urlLink.contains(expectedPath) && event.userEmail == expectedEmail && event.status == expectedStatus | ||
} | ||
} | ||
|
||
val metadataReviewDecisionEventMatcher = new MetadataReviewSubmittedEventMatcher(consignmentRef, expectedPath) | ||
val metadataReviewDecisionEventMatcher = new MetadataReviewSubmittedEventMatcher(consignmentRef, expectedPath, userEmail, status) | ||
|
||
setUpdateConsignmentStatus(wiremockServer) | ||
|
||
val reviewSubmit = controller.submitReview(consignmentId, consignmentRef).apply(FakeRequest().withFormUrlEncodedBody(("status", CompletedValue.value)).withCSRFToken) | ||
val reviewSubmit = | ||
controller.submitReview(consignmentId, consignmentRef, userEmail).apply(FakeRequest().withFormUrlEncodedBody(("status", status)).withCSRFToken) | ||
playStatus(reviewSubmit) mustBe SEE_OTHER | ||
redirectLocation(reviewSubmit) must be(Some(s"/admin/metadata-review")) | ||
verify(messagingService, times(1)).sendMetadataReviewSubmittedNotification(argThat(metadataReviewDecisionEventMatcher)) | ||
|
@@ -100,8 +103,9 @@ class MetadataReviewActionControllerSpec extends FrontEndTestHelper { | |
"display errors when an invalid form is submitted" in { | ||
val controller = instantiateMetadataReviewActionController(getAuthorisedSecurityComponents, getValidTNAUserKeycloakConfiguration) | ||
val consignmentRef = "TDR-TEST-2024" | ||
val metadataReviewDecisionEvent = MetadataReviewSubmittedEvent(consignmentRef, "SomeUrl") | ||
val reviewSubmit = controller.submitReview(consignmentId, consignmentRef).apply(FakeRequest().withFormUrlEncodedBody(("status", "")).withCSRFToken) | ||
val userEmail = "[email protected]" | ||
val metadataReviewDecisionEvent = MetadataReviewSubmittedEvent(consignmentRef, "SomeUrl", userEmail, "status") | ||
val reviewSubmit = controller.submitReview(consignmentId, consignmentRef, userEmail).apply(FakeRequest().withFormUrlEncodedBody(("status", "")).withCSRFToken) | ||
setUpdateConsignmentStatus(wiremockServer) | ||
setGetConsignmentDetailsForMetadataReviewResponse() | ||
playStatus(reviewSubmit) mustBe BAD_REQUEST | ||
|
@@ -174,15 +178,15 @@ class MetadataReviewActionControllerSpec extends FrontEndTestHelper { | |
| SeriesName | ||
| </dd>""".stripMargin) | ||
pageAsString must include(s"""<dt class="govuk-summary-list__key"> | ||
| UserId | ||
| Contact email | ||
| </dt> | ||
| <dd class="govuk-summary-list__value"> | ||
| $userId | ||
| [email protected] | ||
| </dd>""".stripMargin) | ||
pageAsString must include("""1. Download and review transfer metadata""") | ||
pageAsString must include(downloadLinkHTML(consignmentId)) | ||
pageAsString must include("""2. Set the status of this review""") | ||
pageAsString must include(s"""<form action="/admin/metadata-review/$consignmentId?consignmentRef=TDR-2024-TEST" method="POST" novalidate="">""") | ||
pageAsString must include(s"""<form action="/admin/metadata-review/$consignmentId?consignmentRef=TDR-2024-TEST&userEmail=email%40test.com" method="POST" novalidate="">""") | ||
pageAsString must include(s"""<option value="" selected> | ||
| Select a status | ||
| </option>""".stripMargin) | ||
|
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 |
---|---|---|
|
@@ -65,11 +65,15 @@ class MessagingServiceSpec extends AnyFlatSpec with Matchers { | |
val service = createService | ||
val metadataReviewSubmittedEvent = MessagingService.MetadataReviewSubmittedEvent( | ||
consignmentReference = "Ref123", | ||
urlLink = "example.com" | ||
urlLink = "example.com", | ||
userEmail = "[email protected]", | ||
status = "Status" | ||
) | ||
val expectedMessageString = """{ | ||
| "consignmentReference" : "Ref123", | ||
| "urlLink" : "example.com" | ||
| "urlLink" : "example.com", | ||
| "userEmail" : "[email protected]", | ||
| "status" : "Status" | ||
|}""".stripMargin | ||
service.sendMetadataReviewSubmittedNotification(metadataReviewSubmittedEvent) | ||
verify(mockUtils).publish(expectedMessageString, testArn) | ||
|
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 |
---|---|---|
|
@@ -75,6 +75,7 @@ import play.api.test.Injecting | |
import play.api.{Application, Configuration} | ||
import services.Statuses.{InProgressValue, SeriesType} | ||
import uk.gov.nationalarchives.tdr.GraphQLClient | ||
import uk.gov.nationalarchives.tdr.keycloak.KeycloakUtils.UserDetails | ||
import uk.gov.nationalarchives.tdr.keycloak.Token | ||
import viewsapi.FrontEndInfo | ||
|
||
|
@@ -929,6 +930,7 @@ trait FrontEndTestHelper extends PlaySpec with MockitoSugar with Injecting with | |
accessToken.setEmail("[email protected]") | ||
val token = Token(accessToken, new BearerAccessToken) | ||
doAnswer(_ => Some(token)).when(keycloakMock).token(any[String]) | ||
when(keycloakMock.userDetails(any[String])).thenReturn(Future(UserDetails("[email protected]"))) | ||
keycloakMock | ||
} | ||
|
||
|