From 351e710cb1a9d3e83fc89e69f0bfd6cb752767af Mon Sep 17 00:00:00 2001 From: peteslater-ee Date: Mon, 29 Oct 2018 11:51:22 +0000 Subject: [PATCH 1/3] API-3473 - Added unblock facility --- .../gov/hmrc/controllers/GatekeeperController.scala | 8 +++++++- app/uk/gov/hmrc/models/Application.scala | 3 ++- app/uk/gov/hmrc/services/GatekeeperService.scala | 11 +++++++++++ conf/app.routes | 1 + 4 files changed, 21 insertions(+), 2 deletions(-) diff --git a/app/uk/gov/hmrc/controllers/GatekeeperController.scala b/app/uk/gov/hmrc/controllers/GatekeeperController.scala index 956c00809..912d9ab93 100644 --- a/app/uk/gov/hmrc/controllers/GatekeeperController.scala +++ b/app/uk/gov/hmrc/controllers/GatekeeperController.scala @@ -23,7 +23,7 @@ import play.api.libs.json.Json import uk.gov.hmrc.connector.AuthConnector import uk.gov.hmrc.controllers.ErrorCode._ import uk.gov.hmrc.models.JsonFormatters._ -import uk.gov.hmrc.models.{AuthRole, Blocked, InvalidStateTransition} +import uk.gov.hmrc.models.{AuthRole, Blocked, InvalidStateTransition, Unblocked} import uk.gov.hmrc.services.{ApplicationService, GatekeeperService} import scala.concurrent.ExecutionContext.Implicits.global @@ -79,6 +79,12 @@ class GatekeeperController @Inject()(val authConnector: AuthConnector, val appli } recover recovery } + def unblockApplication(id: UUID) = requiresRole(AuthRole.APIGatekeeper).async { implicit request => + gatekeeperService.unblockApplication(id) map { + case Unblocked => Ok + } recover recovery + } + def fetchAppsForGatekeeper = requiresRole(AuthRole.APIGatekeeper).async { gatekeeperService.fetchNonTestingAppsWithSubmittedDate() map { apps => Ok(Json.toJson(apps)) diff --git a/app/uk/gov/hmrc/models/Application.scala b/app/uk/gov/hmrc/models/Application.scala index 6c5752d2a..af7512abf 100644 --- a/app/uk/gov/hmrc/models/Application.scala +++ b/app/uk/gov/hmrc/models/Application.scala @@ -428,4 +428,5 @@ case object UpliftRejected extends ApplicationStateChange case object UpliftVerified extends ApplicationStateChange case object VerificationResent extends ApplicationStateChange case object Deleted extends ApplicationStateChange -case object Blocked extends ApplicationStateChange \ No newline at end of file +case object Blocked extends ApplicationStateChange +case object Unblocked extends ApplicationStateChange \ No newline at end of file diff --git a/app/uk/gov/hmrc/services/GatekeeperService.scala b/app/uk/gov/hmrc/services/GatekeeperService.scala index 79cbece8a..8b8f8fae2 100644 --- a/app/uk/gov/hmrc/services/GatekeeperService.scala +++ b/app/uk/gov/hmrc/services/GatekeeperService.scala @@ -199,6 +199,17 @@ class GatekeeperService @Inject()(applicationRepository: ApplicationRepository, } yield Blocked } + def unblockApplication(applicationId: UUID)(implicit hc: HeaderCarrier): Future[ApplicationStateChange] = { + def unblock(application: ApplicationData): ApplicationData = { + application.copy(blocked = false) + } + + for { + app <- fetchApp(applicationId) + _ <- applicationRepository.save(unblock(app)) + } yield Unblocked + } + private def fetchApp(applicationId: UUID): Future[ApplicationData] = { lazy val notFoundException = new NotFoundException(s"application not found for id: $applicationId") diff --git a/conf/app.routes b/conf/app.routes index c52ccaa89..f09e0e0b2 100644 --- a/conf/app.routes +++ b/conf/app.routes @@ -37,6 +37,7 @@ POST /application/:id/reject-uplift @uk.gov.hmr POST /application/:id/resend-verification @uk.gov.hmrc.controllers.GatekeeperController.resendVerification(id: java.util.UUID) POST /application/:id/delete @uk.gov.hmrc.controllers.GatekeeperController.deleteApplication(id: java.util.UUID) POST /application/:id/block @uk.gov.hmrc.controllers.GatekeeperController.blockApplication(id: java.util.UUID) +POST /application/:id/unblock @uk.gov.hmrc.controllers.GatekeeperController.unblockApplication(id: java.util.UUID) POST /application/:id/rate-limit-tier @uk.gov.hmrc.controllers.ApplicationController.updateRateLimitTier(id: java.util.UUID) From 7fcea19542698be19de867a85fc3fd145bb0b8d7 Mon Sep 17 00:00:00 2001 From: peteslater-ee Date: Mon, 29 Oct 2018 14:21:39 +0000 Subject: [PATCH 2/3] API-3473 - Added tests for unblocking apps --- .../GatekeeperControllerSpec.scala | 15 +++++++++++++++ .../unit/services/GatekeeperServiceSpec.scala | 19 +++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/test/unit/controllers/GatekeeperControllerSpec.scala b/test/unit/controllers/GatekeeperControllerSpec.scala index 3985d0bd4..f8791d394 100644 --- a/test/unit/controllers/GatekeeperControllerSpec.scala +++ b/test/unit/controllers/GatekeeperControllerSpec.scala @@ -353,6 +353,21 @@ class GatekeeperControllerSpec extends UnitSpec with ScalaFutures with MockitoSu } } + "unblockApplication" should { + + val applicationId: UUID = UUID.randomUUID() + + "unblock the application" in new Setup { + + when(mockGatekeeperService.unblockApplication(any()) (any[HeaderCarrier]())).thenReturn(successful(Unblocked)) + + val result = await(underTest.unblockApplication(applicationId)(request)) + + status(result) shouldBe SC_OK + verify(mockGatekeeperService).unblockApplication(applicationId) + } + } + private def aHistory(appId: UUID, state: State = PENDING_GATEKEEPER_APPROVAL) = { StateHistoryResponse(appId, state, Actor("anEmail", COLLABORATOR), None, DateTimeUtils.now) } diff --git a/test/unit/services/GatekeeperServiceSpec.scala b/test/unit/services/GatekeeperServiceSpec.scala index d0359d3ec..8a35d2a44 100644 --- a/test/unit/services/GatekeeperServiceSpec.scala +++ b/test/unit/services/GatekeeperServiceSpec.scala @@ -485,4 +485,23 @@ class GatekeeperServiceSpec extends UnitSpec with ScalaFutures with MockitoSugar verify(mockApplicationRepository).save(updatedApplication) } } + + "unblockApplication" should { + + val applicationId: UUID = UUID.randomUUID() + val applicationData = anApplicationData(applicationId).copy(blocked = true) + val updatedApplication = applicationData.copy(blocked = false) + + "set the block flag to false for an application" in new Setup { + + when(mockApplicationRepository.fetch(any())).thenReturn(successful(Option(applicationData))) + when(mockApplicationRepository.save(any())).thenReturn(successful(updatedApplication)) + + val result = await(underTest.unblockApplication(applicationId)) + result shouldBe Unblocked + + verify(mockApplicationRepository).fetch(applicationId) + verify(mockApplicationRepository).save(updatedApplication) + } + } } From 56e22ccdf9b36827d6a0a5630243beb296d7ea06 Mon Sep 17 00:00:00 2001 From: peteslater-ee Date: Mon, 29 Oct 2018 14:40:25 +0000 Subject: [PATCH 3/3] API-3473 - Optimised imports --- test/unit/controllers/GatekeeperControllerSpec.scala | 10 ++++------ test/unit/services/GatekeeperServiceSpec.scala | 2 -- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/test/unit/controllers/GatekeeperControllerSpec.scala b/test/unit/controllers/GatekeeperControllerSpec.scala index f8791d394..289bf39f3 100644 --- a/test/unit/controllers/GatekeeperControllerSpec.scala +++ b/test/unit/controllers/GatekeeperControllerSpec.scala @@ -18,10 +18,12 @@ package controllers import java.util.UUID +import common.uk.gov.hmrc.common.LogSuppressing +import common.uk.gov.hmrc.testutils.ApplicationStateUtil import org.apache.http.HttpStatus._ import org.joda.time.DateTime import org.mockito.ArgumentCaptor -import org.mockito.Matchers.{any, anyString, eq => eqTo} +import org.mockito.Matchers.any import org.mockito.Mockito._ import org.scalatest.concurrent.ScalaFutures import org.scalatest.mockito.MockitoSugar @@ -32,6 +34,7 @@ import play.api.test.FakeRequest import uk.gov.hmrc.connector.AuthConnector import uk.gov.hmrc.controllers.ErrorCode._ import uk.gov.hmrc.controllers.{ErrorCode, _} +import uk.gov.hmrc.http.{HeaderCarrier, NotFoundException} import uk.gov.hmrc.models.ActorType._ import uk.gov.hmrc.models.JsonFormatters._ import uk.gov.hmrc.models.State._ @@ -39,13 +42,8 @@ import uk.gov.hmrc.models._ import uk.gov.hmrc.play.test.{UnitSpec, WithFakeApplication} import uk.gov.hmrc.services.{ApplicationService, GatekeeperService} import uk.gov.hmrc.time.DateTimeUtils -import common.uk.gov.hmrc.common.LogSuppressing -import common.uk.gov.hmrc.testutils.ApplicationStateUtil import scala.concurrent.Future.{failed, successful} -import uk.gov.hmrc.http.{HeaderCarrier, NotFoundException} -import uk.gov.hmrc.models.AuthRole.APIGatekeeper -import uk.gov.hmrc.models.RateLimitTier.SILVER class GatekeeperControllerSpec extends UnitSpec with ScalaFutures with MockitoSugar with WithFakeApplication with ApplicationStateUtil with LogSuppressing { diff --git a/test/unit/services/GatekeeperServiceSpec.scala b/test/unit/services/GatekeeperServiceSpec.scala index 8a35d2a44..ae5f96037 100644 --- a/test/unit/services/GatekeeperServiceSpec.scala +++ b/test/unit/services/GatekeeperServiceSpec.scala @@ -23,13 +23,11 @@ import org.joda.time.DateTimeUtils import org.mockito.ArgumentCaptor import org.mockito.Matchers.{any, anyString, eq => eqTo} import org.mockito.Mockito._ -import org.apache.http.HttpStatus._ import org.mockito.invocation.InvocationOnMock import org.mockito.stubbing.Answer import org.scalatest.BeforeAndAfterAll import org.scalatest.concurrent.ScalaFutures import org.scalatest.mockito.MockitoSugar -import play.api.test.FakeRequest import uk.gov.hmrc.config.AppContext import uk.gov.hmrc.connector.{ApiSubscriptionFieldsConnector, EmailConnector, ThirdPartyDelegatedAuthorityConnector} import uk.gov.hmrc.controllers.{DeleteApplicationRequest, RejectUpliftRequest}