From cd1c27694b6c7b2d43d433d258d2862e256977d8 Mon Sep 17 00:00:00 2001 From: Brian Wakenshaw <36340167+BriWak@users.noreply.github.com> Date: Wed, 25 Sep 2024 14:47:13 +0100 Subject: [PATCH] BDOG-3261: Feature flag create user pages --- .../cataloguefrontend/config/CatalogueConfig.scala | 6 +++++- .../users/CreateUserController.scala | 12 +++++++++--- conf/application.conf | 5 ++++- .../createuser/CreateUserControllerSpec.scala | 9 +++++++-- 4 files changed, 25 insertions(+), 7 deletions(-) diff --git a/app/uk/gov/hmrc/cataloguefrontend/config/CatalogueConfig.scala b/app/uk/gov/hmrc/cataloguefrontend/config/CatalogueConfig.scala index 3b25c0bc0..3fd5b56be 100644 --- a/app/uk/gov/hmrc/cataloguefrontend/config/CatalogueConfig.scala +++ b/app/uk/gov/hmrc/cataloguefrontend/config/CatalogueConfig.scala @@ -16,11 +16,15 @@ package uk.gov.hmrc.cataloguefrontend.config +import play.api.Configuration import uk.gov.hmrc.play.bootstrap.config.ServicesConfig import javax.inject.{Inject, Singleton} @Singleton -class CatalogueConfig @Inject() (servicesConfig: ServicesConfig): +class CatalogueConfig @Inject() (configuration: Configuration, servicesConfig: ServicesConfig): def killSwitchLink(shutterType: String): String = servicesConfig.getString(s"killswitch.jenkins-job.$shutterType") + + val showCreateUserJourney: Boolean = + configuration.get[Boolean]("feature.show-create-user-journey") \ No newline at end of file diff --git a/app/uk/gov/hmrc/cataloguefrontend/users/CreateUserController.scala b/app/uk/gov/hmrc/cataloguefrontend/users/CreateUserController.scala index 842e109b8..915e0dd08 100644 --- a/app/uk/gov/hmrc/cataloguefrontend/users/CreateUserController.scala +++ b/app/uk/gov/hmrc/cataloguefrontend/users/CreateUserController.scala @@ -20,12 +20,14 @@ import cats.data.EitherT import play.api.Logger import play.api.data.{Form, Forms} import play.api.data.validation.{Constraint, Constraints, Invalid, Valid} -import play.api.mvc._ +import play.api.mvc.* import uk.gov.hmrc.cataloguefrontend.auth.CatalogueAuthBuilders +import uk.gov.hmrc.cataloguefrontend.config.CatalogueConfig import uk.gov.hmrc.cataloguefrontend.connector.UserManagementConnector import uk.gov.hmrc.cataloguefrontend.model.TeamName import uk.gov.hmrc.cataloguefrontend.users.view.html.{CreateUserPage, CreateUserRequestSentPage} -import uk.gov.hmrc.internalauth.client._ +import uk.gov.hmrc.cataloguefrontend.view.html.error_404_template +import uk.gov.hmrc.internalauth.client.* import uk.gov.hmrc.play.bootstrap.frontend.controller.FrontendController import javax.inject.{Inject, Singleton} @@ -35,6 +37,7 @@ import scala.concurrent.{ExecutionContext, Future} class CreateUserController @Inject()( override val auth : FrontendAuthComponents, override val mcc : MessagesControllerComponents, + config : CatalogueConfig, createUserPage : CreateUserPage, createUserRequestSentPage: CreateUserRequestSentPage, userManagementConnector : UserManagementConnector @@ -59,7 +62,10 @@ class CreateUserController @Inject()( continueUrl = routes.CreateUserController.createUserLanding(isServiceAccount), retrieval = Retrieval.locations(resourceType = Some(ResourceType("catalogue-frontend")), action = Some(IAAction("CREATE_USER"))) ).apply { implicit request => - Ok(createUserPage(CreateUserForm.form, cleanseUserTeams(request.retrieval), Organisation.values.toSeq, isServiceAccount)) + if config.showCreateUserJourney then + Ok(createUserPage(CreateUserForm.form, cleanseUserTeams(request.retrieval), Organisation.values.toSeq, isServiceAccount)) + else + NotFound(error_404_template()) } def createUser(isServiceAccount: Boolean): Action[AnyContent] = diff --git a/conf/application.conf b/conf/application.conf index 01f71051f..96ae3df65 100644 --- a/conf/application.conf +++ b/conf/application.conf @@ -255,4 +255,7 @@ bootstrap.auditfilter.maskedFormFields = [ "password" ] # B&D api for create app configs does not support externaltest environmentsToHideByDefault = ["integration", "development", "externaltest"] -feature.show-decommission-button = false +feature { + show-decommission-button = false + show-create-user-journey = false +} diff --git a/test/uk/gov/hmrc/cataloguefrontend/createuser/CreateUserControllerSpec.scala b/test/uk/gov/hmrc/cataloguefrontend/createuser/CreateUserControllerSpec.scala index 27e37881f..094078df6 100644 --- a/test/uk/gov/hmrc/cataloguefrontend/createuser/CreateUserControllerSpec.scala +++ b/test/uk/gov/hmrc/cataloguefrontend/createuser/CreateUserControllerSpec.scala @@ -16,7 +16,7 @@ package uk.gov.hmrc.cataloguefrontend.createuser -import org.mockito.ArgumentMatchers.{any, eq => eqTo} +import org.mockito.ArgumentMatchers.{any, eq as eqTo} import org.mockito.Mockito.when import org.scalatest.concurrent.ScalaFutures import org.scalatest.matchers.should.Matchers @@ -25,6 +25,7 @@ import org.scalatestplus.mockito.MockitoSugar import play.api.mvc.MessagesControllerComponents import play.api.test.FakeRequest import play.api.test.Helpers.{POST, contentAsString, defaultAwaitTimeout, redirectLocation, status} +import uk.gov.hmrc.cataloguefrontend.config.CatalogueConfig import uk.gov.hmrc.cataloguefrontend.test.FakeApplicationBuilder import uk.gov.hmrc.cataloguefrontend.connector.UserManagementConnector import uk.gov.hmrc.cataloguefrontend.model.TeamName @@ -32,7 +33,7 @@ import uk.gov.hmrc.cataloguefrontend.users.{CreateUserController, CreateUserRequ import uk.gov.hmrc.cataloguefrontend.users.view.html.{CreateUserPage, CreateUserRequestSentPage} import uk.gov.hmrc.http.{HeaderCarrier, SessionKeys} import uk.gov.hmrc.internalauth.client.test.{FrontendAuthComponentsStub, StubBehaviour} -import uk.gov.hmrc.internalauth.client._ +import uk.gov.hmrc.internalauth.client.* import scala.concurrent.ExecutionContext.Implicits.global import scala.concurrent.Future @@ -195,14 +196,18 @@ class CreateUserControllerSpec val mockCUPView : CreateUserPage = app.injector.instanceOf[CreateUserPage] val mockCURSPView : CreateUserRequestSentPage = app.injector.instanceOf[CreateUserRequestSentPage] + val mockConfig : CatalogueConfig = mock[CatalogueConfig] val mockUMConnector : UserManagementConnector = mock[UserManagementConnector] val authStubBehaviour: StubBehaviour = mock[StubBehaviour] val authComponent : FrontendAuthComponents = FrontendAuthComponentsStub(authStubBehaviour) + when(mockConfig.showCreateUserJourney).thenReturn(true) + val controller = CreateUserController( auth = authComponent, mcc = mcc, + config = mockConfig, createUserPage = mockCUPView, createUserRequestSentPage = mockCURSPView, userManagementConnector = mockUMConnector