Skip to content

Commit

Permalink
API-5944 - Hide sign in on index page if alrady signed in (hmrc#470)
Browse files Browse the repository at this point in the history
  • Loading branch information
AndySpaven authored Jul 11, 2023
1 parent f418bd9 commit 94c4938
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import uk.gov.hmrc.apidocumentation.views.html._
@Singleton
class DocumentationController @Inject() (
val navigationService: NavigationService,
loggedInUserService: LoggedInUserService,
partialsService: PartialsService,
mcc: MessagesControllerComponents,
indexView: IndexView,
Expand All @@ -55,9 +56,19 @@ class DocumentationController @Inject() (
with TermsCrumb
with ApplicationLogger {


def indexPage(): Action[AnyContent] = headerNavigation {
def extractDeveloperIdentifier(f: Future[Option[Developer]]): Future[Option[DeveloperIdentifier]] = {
f.map(o =>
o.map(d => UuidIdentifier(d.userId))
)
}

implicit request => navLinks =>
Future.successful(Ok(indexView("Home", navLinks)))
for {
userId <- extractDeveloperIdentifier(loggedInUserService.fetchLoggedInUser())
isLoggedIn = userId.isDefined
} yield Ok(indexView("Home", navLinks, isLoggedIn))
}

def tutorialsPage(): Action[AnyContent] = headerNavigation {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ class OpenApiDocumentationController @Inject() (
// The OAS specification has been found and parsed by Swagger - return the fully resolved specification to the caller.
case Some(openApi) => {
logger.info("Successfully parsed the OAS specification.")
logger.info(parserResult.getMessages().asScala.mkString)
logger.info(Option(parserResult.getMessages()).map(_.asScala.mkString).getOrElse(""))
handleSuccess(openApi)
}
// The OAS specification has been found but there was a parsing problem - return an empty specification to the caller.
Expand Down
26 changes: 14 additions & 12 deletions app/uk/gov/hmrc/apidocumentation/views/IndexView.scala.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

@this(layoutHomePage: LayoutHomePage)

@(pageTitle: String, navLinks: Seq[NavLink])(implicit applicationConfig: ApplicationConfig, messagesProvider: MessagesProvider, request: play.api.mvc.Request[Any])
@(pageTitle: String, navLinks: Seq[NavLink], loggedIn: Boolean)(implicit applicationConfig: ApplicationConfig, messagesProvider: MessagesProvider, request: play.api.mvc.Request[Any])

@layoutHomePage(
headerNavLinks = Some(partials.headerNavLinks(navLinks)),
Expand Down Expand Up @@ -52,17 +52,19 @@ <h1 id="RESTful-APIs-Title" class="govuk-heading-xl hero-title govuk-!-margin-to
<p class="govuk-body govuk-!-font-size-24 app-inverse">
<a class="govuk-link govuk-link--inverse" href="@controllers.routes.ApiDocumentationController.apiIndexPage(None, None, None).url">Explore our APIs, review documentation and check endpoints</a>.
</p>
<p class="govuk-body govuk-!-font-size-24 app-inverse">
Sign up to use our APIs and get email updates.
</p>
<div class="govuk-button-group">
<a href="/developer/registration" role="button" draggable="false" class="govuk-button hero-button govuk-!-font-size-24 govuk-!-font-weight-bold" data-module="govuk-button">
Get an account
</a>
<span class="govuk-body app-inverse">or
<a class="govuk-link govuk-link--inverse govuk-!-font-weight-bold" href="/developer/login">sign in</a>
</span>
</div>
@if(!loggedIn) {
<p class="govuk-body govuk-!-font-size-24 app-inverse">
Sign up to use our APIs and get email updates.
</p>
<div class="govuk-button-group">
<a href="/developer/registration" role="button" draggable="false" class="govuk-button hero-button govuk-!-font-size-24 govuk-!-font-weight-bold" data-module="govuk-button">
Get an account
</a>
<span class="govuk-body app-inverse">or
<a class="govuk-link govuk-link--inverse govuk-!-font-weight-bold" href="/developer/login">sign in</a>
</span>
</div>
}
</div>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import uk.gov.hmrc.apidocumentation.models._
import uk.gov.hmrc.apidocumentation.services.PartialsService
import uk.gov.hmrc.apidocumentation.views.html.{TermsOfUseNotMeetingView, TermsOfUseWhatYouCanExpectView, _}
import uk.gov.hmrc.apidocumentation.{ErrorHandler, controllers}
import uk.gov.hmrc.apidocumentation.services.LoggedInUserService

class DocumentationControllerSpec
extends CommonControllerBaseSpec
Expand Down Expand Up @@ -72,6 +73,7 @@ class DocumentationControllerSpec
private lazy val usingTheHubView = app.injector.instanceOf[UsingTheHubView]
private lazy val termsOfUseWhatYouCanExpectView = app.injector.instanceOf[TermsOfUseWhatYouCanExpectView]
private lazy val termsOfUseNotMeetingView = app.injector.instanceOf[TermsOfUseNotMeetingView]
private lazy val loggedInUserService = app.injector.instanceOf[LoggedInUserService]

lazy val usingTheHubBreadcrumb = Crumb(
"Using the Developer Hub",
Expand All @@ -82,6 +84,7 @@ class DocumentationControllerSpec

val underTest: DocumentationController = new DocumentationController(
navigationService,
loggedInUserService,
partialsService,
mcc,
indexView,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,23 @@ class IndexViewSpec extends CommonViewSpec {

"htmlView" must {
"render with no indexing meta tags" in new TestCase {
val renderedHtml = new IndexView(main)(pageTitle, navLinks)
val renderedHtml = new IndexView(main)(pageTitle, navLinks, false)
renderedHtml.body shouldNot include("<meta name=\"robots\" content=\"noindex\">")
renderedHtml.body shouldNot include("<meta name=\"googlebot\" content=\"noindex\">")
}

"render with sign in components if not signed in" in new TestCase {
val renderedHtml = new IndexView(main)(pageTitle, navLinks, false)
renderedHtml.body should include("Get an account")
renderedHtml.body should include("Sign up to use our APIs and get email updates.")
renderedHtml.body should include("sign in</a>")
}

"render without sign in components if signed in" in new TestCase {
val renderedHtml = new IndexView(main)(pageTitle, navLinks, true)
renderedHtml.body shouldNot include("Get an account")
renderedHtml.body shouldNot include("Sign up to use our APIs and get email updates.")
renderedHtml.body shouldNot include("sign in</a>")
}
}
}

0 comments on commit 94c4938

Please sign in to comment.