Skip to content

Commit

Permalink
replace collections on europe front if participating in the europe be…
Browse files Browse the repository at this point in the history
…ta test
  • Loading branch information
cemms1 committed Nov 22, 2024
1 parent fd198dd commit 737ce8c
Showing 1 changed file with 48 additions and 26 deletions.
74 changes: 48 additions & 26 deletions facia/app/controllers/FaciaController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,9 @@ trait FaciaController
Action.async { implicit request =>
if (shouldEditionRedirect(path))
redirectTo(Editionalise(path, Edition(request)))
else if (!ConfigAgent.shouldServeFront(path) || request.getQueryString("page").isDefined)
else if (!ConfigAgent.shouldServeFront(path) || request.getQueryString("page").isDefined) {
applicationsRedirect(path)
else
} else
renderFrontPressResult(path)
}

Expand Down Expand Up @@ -220,33 +220,55 @@ trait FaciaController
)

import PressedPage.pressedPageFormat
private[controllers] def renderFrontPressResult(path: String)(implicit request: RequestHeader): Future[Result] = {
// Europe beta experiment
// Phase 1 prevents users from being able to view the europe-beta front unless opted into the test
val inEuropeBetaTest = ActiveExperiments.isParticipating(EuropeBetaFront)
if (path == "europe-beta" && !inEuropeBetaTest && !context.isPreview) {
return successful(Cached(CacheTime.NotFound)(WithoutRevalidationResult(NotFound)))
}
private[controllers] def getFaciaPage(path: String)(implicit
request: RequestHeader,
): Future[Option[(PressedPage, Boolean)]] = frontJsonFapi.get(path, liteRequestType).flatMap {
case Some(faciaPage: PressedPage) =>
val pageContainsTargetedCollections = TargetedCollections.pageContainsTargetedCollections(faciaPage)
val regionalFaciaPage = TargetedCollections.processTargetedCollections(
faciaPage,
request.territories,
context.isPreview,
pageContainsTargetedCollections,
)
if (conf.Configuration.environment.stage == "CODE") {
logInfoWithCustomFields(
s"Rendering front $path, frontjson: ${Json.stringify(Json.toJson(faciaPage)(pressedPageFormat))}",
List(),
)
}
if (faciaPage.collections.isEmpty && liteRequestType == LiteAdFreeType) {
frontJsonFapi.get(path, LiteType).map(_.map(f => (f, false)))
} else Future.successful(Some(regionalFaciaPage, pageContainsTargetedCollections))
case None => Future.successful(None)
}

val futureFaciaPage: Future[Option[(PressedPage, Boolean)]] = frontJsonFapi.get(path, liteRequestType).flatMap {
case Some(faciaPage: PressedPage) =>
val pageContainsTargetedCollections = TargetedCollections.pageContainsTargetedCollections(faciaPage)
val regionalFaciaPage = TargetedCollections.processTargetedCollections(
faciaPage,
request.territories,
context.isPreview,
pageContainsTargetedCollections,
private[controllers] def renderFrontPressResult(path: String)(implicit request: RequestHeader): Future[Result] = {
val futureFaciaPage: Future[Option[(PressedPage, Boolean)]] = {
// Europe beta test
// Phase 2 swaps the collections on the Europe network front with those on the hidden europe-beta front
// for users participating in the test
if (path == "europe" && ActiveExperiments.isParticipating(EuropeBetaFront)) {
for (
faciaPage <- getFaciaPage(path);
europeBetaPage <- getFaciaPage("europe-beta")
)
if (conf.Configuration.environment.stage == "CODE") {
logInfoWithCustomFields(
s"Rendering front $path, frontjson: ${Json.stringify(Json.toJson(faciaPage)(pressedPageFormat))}",
List(),
yield for (
(pressedPage, _) <- faciaPage;
(pressedEuropeBetaPage, hasTargetedCollections) <- europeBetaPage
)
}
if (faciaPage.collections.isEmpty && liteRequestType == LiteAdFreeType) {
frontJsonFapi.get(path, LiteType).map(_.map(f => (f, false)))
} else Future.successful(Some(regionalFaciaPage, pageContainsTargetedCollections))
case None => Future.successful(None)
yield (
PressedPage(
id = pressedPage.id,
seoData = pressedPage.seoData,
frontProperties = pressedPage.frontProperties,
collections = pressedEuropeBetaPage.collections,
),
hasTargetedCollections,
)
} else {
getFaciaPage(path)
}
}

val networkFrontEdition = Edition.allEditions.find(_.networkFrontId == path)
Expand Down

0 comments on commit 737ce8c

Please sign in to comment.