Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pods 9128 #378

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/controllers/address/ChooseAddressController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class ChooseAddressController @Inject()(val controllerComponents: MessagesContro
addresses,
index
))
case _ => Redirect(controllers.routes.JourneyRecoveryController.onPageLoad(None).url)
case _ => throw new RuntimeException("User answers not available")
}
}

Expand Down
11 changes: 6 additions & 5 deletions app/controllers/fileUpload/FileUploadResultController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -112,14 +112,15 @@ class FileUploadResultController @Inject()(val controllerComponents: MessagesCon
val originalUserAnswers = request.userAnswers.fold(UserAnswers())(identity)
val updatedAnswers = originalUserAnswers.setOrException(FileUploadResultPage(eventType), value)
val redirectResultPage: Result = Redirect(FileUploadResultPage(eventType).navigate(waypoints, originalUserAnswers, updatedAnswers).route)
userAnswersCacheConnector.save(request.pstr, eventType, updatedAnswers).map { _ =>
userAnswersCacheConnector.save(request.pstr, eventType, updatedAnswers).flatMap { _ =>
if (value == FileUploadResult.Yes) {
parsingAndValidationOutcomeCacheConnector
.deleteOutcome
.flatMap(_ => asyncGetUpscanFileAndParse(eventType))
redirectResultPage
.map(_ => redirectResultPage)

} else {
redirectResultPage
Future.successful(redirectResultPage)
}
}
}
Expand Down Expand Up @@ -213,8 +214,8 @@ class FileUploadResultController @Inject()(val controllerComponents: MessagesCon
sendUpscanFileDownloadAuditEvent(eventType, httpResponse.status, startTime, fileUploadOutcomeResponse)
httpResponse.status match {
case OK => performValidation(eventType, httpResponse.bodyAsSource, fileName) recoverWith {
case e: Throwable =>
setGeneralErrorOutcome("Unable to download file", fileName, Some(e))
case e =>
throw new RuntimeException("Unable to download file", e) //TODO: Might need to handle this in error handler.
}
case e =>
setGeneralErrorOutcome(s"Upscan download error response code $e", fileName)
Expand Down
12 changes: 9 additions & 3 deletions app/handlers/ErrorHandler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@
package handlers

import config.FrontendAppConfig
import play.api.Logging
import play.api.i18n.{I18nSupport, MessagesApi}
import play.api.mvc.Results.{Ok, Redirect}
import play.api.mvc.{Request, RequestHeader, Result}
import play.api.mvc.{Request, RequestHeader, Result, Results}
import play.twirl.api.Html
import uk.gov.hmrc.http.HttpException
import uk.gov.hmrc.play.bootstrap.frontend.http.FrontendErrorHandler
import views.html.{ErrorTemplate, NoDataEnteredErrorView, PageNotFoundErrorView}
import views.html.{ErrorTemplate, NoDataEnteredErrorView, PageNotFoundErrorView, UserLockedView}

import javax.inject.{Inject, Singleton}
import scala.concurrent.Future
Expand All @@ -33,8 +35,9 @@ class ErrorHandler @Inject()(
view: ErrorTemplate,
noDataEnteredView: NoDataEnteredErrorView,
pageNotFoundView: PageNotFoundErrorView,
userLockedView: UserLockedView,
config: FrontendAppConfig
) extends FrontendErrorHandler with I18nSupport {
) extends FrontendErrorHandler with I18nSupport with Logging {

override def standardErrorTemplate(pageTitle: String, heading: String, message: String)(implicit rh: Request[_]): Html =
view(pageTitle, heading, message)
Expand All @@ -44,6 +47,9 @@ class ErrorHandler @Inject()(

override def onServerError(request: RequestHeader, exception: Throwable): Future[Result] = {
exception match {
case e: HttpException if e.message.contains("EVENT_LOCKED") =>
logger.warn("User is locked on " + request.uri)
Future.successful(new Results.Status(e.responseCode)(userLockedView(config.contactHmrcURL)(Request(request, ""), request2Messages(request))))
case _ : TaxYearNotAvailableException =>
Future.successful(Redirect(config.yourPensionSchemesUrl))
case _: NothingToSubmitException =>
Expand Down
37 changes: 37 additions & 0 deletions app/views/UserLockedView.scala.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
@*
* Copyright 2024 HM Revenue & Customs
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*@

@this(
layout: templates.Layout
)

@(contactHmrcUrl: String)(implicit request: Request[_], messages: Messages)

@layout(
pageTitle = titleNoForm(messages("userLocked.text")),
showBackLink = false
) {

<h1 class="govuk-heading-xl">@messages("userLocked.text")</h1>
<p class="govuk-body">
@messages("pageNotFound404.p3")
<a href="@contactHmrcUrl" class="govuk-link">
@messages("pageNotFound404.p4")
</a>
</p>

}

2 changes: 2 additions & 0 deletions conf/messages.en
Original file line number Diff line number Diff line change
Expand Up @@ -1850,6 +1850,8 @@ pageNotFound404.p2 = If you pasted the web address, check you copied the entire
pageNotFound404.p3 = If the web address is correct or you selected a link or button,
pageNotFound404.p4 = contact HMRC.

userLocked.text = Event is locked by a user

cannotResume.title = This event report cannot be submitted
cannotResume.heading = This event report cannot be submitted
cannotResume.p1 = You have attempted to amend or create an event report but no changes have been made.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
package controllers.fileUpload

import base.SpecBase
import connectors.{EventReportingConnector, UserAnswersCacheConnector}
import connectors.{EventReportingConnector, ParsingAndValidationOutcomeCacheConnector, UserAnswersCacheConnector}
import forms.fileUpload.FileUploadResultFormProvider
import models.FileUploadOutcomeResponse
import models.FileUploadOutcomeStatus.{FAILURE, IN_PROGRESS, SUCCESS}
Expand Down Expand Up @@ -51,10 +51,12 @@ class FileUploadResultControllerSpec extends SpecBase with BeforeAndAfterEach {

private val mockUserAnswersCacheConnector = mock[UserAnswersCacheConnector]
private val mockERConnector = mock[EventReportingConnector]
private val mockParsingAndValidationOutcomeCacheConnector = mock[ParsingAndValidationOutcomeCacheConnector]

private val extraModules: Seq[GuiceableModule] = Seq[GuiceableModule](
bind[UserAnswersCacheConnector].toInstance(mockUserAnswersCacheConnector),
bind[EventReportingConnector].toInstance(mockERConnector)
bind[EventReportingConnector].toInstance(mockERConnector),
bind[ParsingAndValidationOutcomeCacheConnector].toInstance(mockParsingAndValidationOutcomeCacheConnector)
)

private def getRoute(eventType: EventType): String = routes.FileUploadResultController.onPageLoad(waypoints, eventType).url
Expand All @@ -63,8 +65,11 @@ class FileUploadResultControllerSpec extends SpecBase with BeforeAndAfterEach {

override def beforeEach(): Unit = {
super.beforeEach()
reset(mockParsingAndValidationOutcomeCacheConnector)
reset(mockUserAnswersCacheConnector)
reset(mockERConnector)
when(mockParsingAndValidationOutcomeCacheConnector.deleteOutcome(any(), any())).thenReturn(Future.successful())
when(mockParsingAndValidationOutcomeCacheConnector.setOutcome(any())(any(), any())).thenReturn(Future.successful())
}

"FileUploadResult Controller" - {
Expand Down