Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove some cookies set by the checkout #6714

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import io.circe.syntax._
import lib.PlayImplicits._
import models.identity.responses.IdentityErrorResponse._
import org.apache.pekko.actor.{ActorSystem, Scheduler}
import org.joda.time.DateTime
import play.api.http.Writeable
import play.api.libs.circe.Circe
import play.api.mvc._
Expand Down Expand Up @@ -343,7 +344,7 @@ class CreateSubscriptionController(

private def cookies(product: ProductType, userEmail: String): Future[List[Cookie]] = {
val productCookiesCreator = SubscriptionProductCookiesCreator(guardianDomain)
val productCookies = productCookiesCreator.createCookiesForProduct(product)
val productCookies = productCookiesCreator.createCookiesForProduct(product, DateTime.now())
checkoutCompleteCookies(product, userEmail).map(_ ++ productCookies)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,47 +32,25 @@ case class SubscriptionProductCookiesCreator(domain: GuardianDomain) {
)
}

def createCookiesForProduct(product: ProductType): List[Cookie] = {
def createCookiesForProduct(product: ProductType, now: DateTime): 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_user_features_expiry", 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 _: SupporterPlus | _: TierThree | _: DigitalPack =>
List(SessionCookie("GU_AF1", 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
List(SessionCookie("GU_AF1", now.plusDays(1).getMillis.toString))

case _: Contribution | _: Paper | _: GuardianWeekly => List.empty

case _: GuardianAdLite => List(PersistentCookie("gu_allow_reject_all", true.toString, oneWeekInSeconds))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ import config.Configuration.GuardianDomain
import org.scalatest.flatspec.AnyFlatSpec
import org.scalatest.matchers.should.Matchers
import play.api.mvc.Cookie
import org.joda.time.DateTime

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 now = DateTime.now()
val cookies = creator.createCookiesForProduct(guardianAdLite, now)

val expectedCookie = Cookie(
name = "gu_allow_reject_all",
Expand All @@ -29,11 +31,12 @@ class SubscriptionProductCookiesCreatorTest extends AnyFlatSpec with Matchers {
val supporterPlus = SupporterPlus(BigDecimal(12), GBP, Monthly)
val creator = SubscriptionProductCookiesCreator(GuardianDomain("thegulocal.com"))

val cookies = creator.createCookiesForProduct(supporterPlus)
val now = new DateTime("2025-01-01T00:00:00")
val cookies = creator.createCookiesForProduct(supporterPlus, now)

val expectedCookie = Cookie(
name = "gu_digital_subscriber",
value = "true",
name = "GU_AF1",
value = "1735776000000", // Jan 2nd 2024 millis
secure = true,
httpOnly = false,
domain = Some("thegulocal.com"),
Expand Down
Loading