-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into pd/landing-page-abtest-benefit-reset
- Loading branch information
Showing
12 changed files
with
283 additions
and
341 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
support-frontend/app/controllers/SubscriptionProductCookiesCreator.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package controllers | ||
|
||
import com.gu.support.workers.ProductType | ||
import config.Configuration.GuardianDomain | ||
import org.joda.time.DateTime | ||
import play.api.mvc.Cookie | ||
import com.gu.support.workers._ | ||
|
||
case class SubscriptionProductCookiesCreator(domain: GuardianDomain) { | ||
sealed trait SupportCookie { | ||
def toPlayCookie: Cookie | ||
} | ||
|
||
case class SessionCookie(name: String, value: String) extends SupportCookie { | ||
def toPlayCookie: Cookie = Cookie( | ||
name = name, | ||
value = value, | ||
secure = true, | ||
httpOnly = false, | ||
domain = Some(domain.value), | ||
) | ||
} | ||
|
||
case class PersistentCookie(name: String, value: String, maxAge: Int) extends SupportCookie { | ||
def toPlayCookie: Cookie = Cookie( | ||
name = name, | ||
value = value, | ||
maxAge = Some(maxAge), | ||
secure = true, | ||
httpOnly = false, | ||
domain = Some(domain.value), | ||
) | ||
} | ||
|
||
def createCookiesForProduct(product: ProductType): List[Cookie] = { | ||
// Setting the user attributes cookies used by frontend. See: | ||
// https://github.com/guardian/dotcom-rendering/blob/3c4700cae532993ace6f40c3b59c337f3efe2247/dotcom-rendering/src/client/userFeatures/user-features.ts | ||
val standardCookies: List[SupportCookie] = List( | ||
SessionCookie("gu_user_features_expiry", DateTime.now.plusDays(1).getMillis.toString), | ||
SessionCookie("gu_hide_support_messaging", true.toString), | ||
) | ||
val oneWeekInSeconds = 604800 | ||
val productCookies: List[SupportCookie] = product match { | ||
case Contribution(_, _, billingPeriod) => | ||
List( | ||
SessionCookie( | ||
s"gu.contributions.recurring.contrib-timestamp.$billingPeriod", | ||
DateTime.now.getMillis.toString, | ||
), | ||
SessionCookie("gu_recurring_contributor", true.toString), | ||
) | ||
case _: SupporterPlus => | ||
List( | ||
SessionCookie("gu_digital_subscriber", true.toString), | ||
// "gu_supporter_plus" -> true.toString, // TODO: add this and remove the digisub one now that the CMP cookie list has been updated | ||
SessionCookie("GU_AF1", DateTime.now().plusDays(1).getMillis.toString), | ||
) | ||
case _: TierThree => | ||
List( | ||
SessionCookie("gu_digital_subscriber", true.toString), | ||
// SessionCookie("gu_supporter_plus", true.toString), // TODO: add this and remove the digisub one now that the CMP cookie list has been updated | ||
SessionCookie("GU_AF1", DateTime.now().plusDays(1).getMillis.toString), | ||
) | ||
case _: DigitalPack => | ||
List( | ||
SessionCookie("gu_digital_subscriber", true.toString), | ||
SessionCookie("GU_AF1", DateTime.now().plusDays(1).getMillis.toString), | ||
) | ||
case p: Paper if p.productOptions.hasDigitalSubscription => | ||
List( | ||
SessionCookie("gu_digital_subscriber", true.toString), | ||
SessionCookie("GU_AF1", DateTime.now().plusDays(1).getMillis.toString), | ||
) | ||
case _: Paper => List.empty | ||
case _: GuardianWeekly => List.empty | ||
case _: GuardianAdLite => List(PersistentCookie("gu_allow_reject_all", true.toString, oneWeekInSeconds)) | ||
} | ||
|
||
(standardCookies ++ productCookies).map(_.toPlayCookie) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
support-frontend/test/controllers/SubscriptionProductCookiesCreatorTest.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package controllers | ||
|
||
import com.gu.i18n.Currency.GBP | ||
import com.gu.support.workers.{GuardianAdLite, Monthly, SupporterPlus} | ||
import config.Configuration.GuardianDomain | ||
import org.scalatest.flatspec.AnyFlatSpec | ||
import org.scalatest.matchers.should.Matchers | ||
import play.api.mvc.Cookie | ||
|
||
class SubscriptionProductCookiesCreatorTest extends AnyFlatSpec with Matchers { | ||
"createCookiesForProduct" should "set the gu_allow_reject_all cookie for GuardianAdLite" in { | ||
val guardianAdLite = GuardianAdLite(GBP) | ||
val creator = SubscriptionProductCookiesCreator(GuardianDomain("thegulocal.com")) | ||
|
||
val cookies = creator.createCookiesForProduct(guardianAdLite) | ||
|
||
val expectedCookie = Cookie( | ||
name = "gu_allow_reject_all", | ||
value = "true", | ||
maxAge = Some(604800), | ||
secure = true, | ||
httpOnly = false, | ||
domain = Some("thegulocal.com"), | ||
) | ||
cookies should contain(expectedCookie) | ||
} | ||
|
||
it should "set the gu_digital_subscriber cookie for SupporterPlus" in { | ||
val supporterPlus = SupporterPlus(BigDecimal(12), GBP, Monthly) | ||
val creator = SubscriptionProductCookiesCreator(GuardianDomain("thegulocal.com")) | ||
|
||
val cookies = creator.createCookiesForProduct(supporterPlus) | ||
|
||
val expectedCookie = Cookie( | ||
name = "gu_digital_subscriber", | ||
value = "true", | ||
secure = true, | ||
httpOnly = false, | ||
domain = Some("thegulocal.com"), | ||
) | ||
cookies should contain(expectedCookie) | ||
} | ||
} |
Oops, something went wrong.