FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Use reader revenue flag not sensitive (#17310) · devhttps/frontend@e789b64 · GitHub

Commit e789b64

Browse files
authored
Use reader revenue flag not sensitive (guardian#17310)
1 parent f59cc4b commit e789b64

18 files changed

Lines changed: 197 additions & 97 deletions

‎common/app/model/meta.scala‎

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@ final case class Commercial(
4646
* MetaData represents a page on the site, whether facia or content
4747
*/
4848
object Fields {
49+
// This is the time from which journalists start using the reader revenue flag in Composer.
50+
// For content published before then, we need handle it as we did before, taking
51+
// the sensitive flag to mean "don't display reader revenue asks"
52+
private val shouldHideReaderRevenueCutoffDate = new DateTime("2017-07-03T12:00:00.000Z")
53+
4954
def make(apiContent: contentapi.Content): Fields = {
5055
Fields (
5156
trailText = apiContent.fields.flatMap(_.trailText),
@@ -59,12 +64,26 @@ object Fields {
5964
displayHint = apiContent.fields.flatMap(_.displayHint).getOrElse(""),
6065
isLive = apiContent.fields.flatMap(_.liveBloggingNow).getOrElse(false),
6166
sensitive = apiContent.fields.flatMap(_.sensitive),
62-
shouldHideReaderRevenue = apiContent.fields.flatMap(_.shouldHideReaderRevenue),
67+
shouldHideReaderRevenue = Some(shouldHideReaderRevenue(apiContent, shouldHideReaderRevenueCutoffDate)),
6368
legallySensitive = apiContent.fields.flatMap(_.legallySensitive),
6469
firstPublicationDate = apiContent.fields.flatMap(_.firstPublicationDate).map(_.toJodaDateTime),
6570
lang = apiContent.fields.flatMap(_.lang)
6671
)
6772
}
73+
74+
def shouldHideReaderRevenue(apiContent: contentapi.Content, cutoffDate: DateTime): Boolean = {
75+
val publishedBeforeCutoff = apiContent.webPublicationDate.exists(_.toJodaDateTime < cutoffDate)
76+
val isPaidContent = Tags.make(apiContent).isPaidContent
77+
val isSensitive = apiContent.fields.flatMap(_.sensitive).getOrElse(false)
78+
val shouldHideAdverts = apiContent.fields.flatMap(_.shouldHideAdverts).getOrElse(false)
79+
80+
apiContent.fields.flatMap(_.shouldHideReaderRevenue) match {
81+
case _ if isPaidContent => true
82+
case Some(shouldHide) => shouldHide
83+
case None if publishedBeforeCutoff => isSensitive || shouldHideAdverts
84+
case None => false
85+
}
86+
}
6887
}
6988

7089
final case class Fields(

‎common/test/model/MetaDataTest.scala‎

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package model
22

3+
import com.gu.contentapi.client.model.v1.{Content => ApiContent, ContentFields, Tag => ApiTag, TagType}
4+
import com.gu.contentapi.client.utils.CapiModelEnrichment.RichJodaDateTime
35
import org.scalatest.{FlatSpec, Matchers}
6+
import org.joda.time.DateTime
47

58
class MetaDataTest extends FlatSpec with Matchers {
69

@@ -15,4 +18,87 @@ class MetaDataTest extends FlatSpec with Matchers {
1518
testMetaData("world/2014/jun/19/obama-100-special-forces-iraq", "world").adUnitSuffix should be("world")
1619
}
1720

21+
val defaultTag = ApiTag(id = "type/article", `type` = TagType.Keyword, webTitle = "",
22+
sectionId = None, sectionName = None, webUrl = "", apiUrl = "apiurl", references = Nil)
23+
24+
val paidContentTag = ApiTag(id = "tone/advertisement-features", `type` = TagType.Keyword, webTitle = "",
25+
sectionId = None, sectionName = None, webUrl = "", apiUrl = "apiurl", references = Nil)
26+
27+
val cutoffDate = new DateTime("2017-07-03T12:00:00.000Z")
28+
val dateBeforeCutoff = new DateTime("2017-07-02T12:00:00.000Z")
29+
val dateAfterCutoff = new DateTime("2017-07-04T12:00:00.000Z")
30+
31+
private def contentApi( shouldHideReaderRevenue: Option[Boolean] = None,
32+
isPaid: Boolean = false,
33+
isSensitive: Boolean = false,
34+
shouldHideAdverts: Boolean = false,
35+
publicationDate: DateTime) = {
36+
ApiContent(
37+
id = "/content",
38+
sectionId = None,
39+
sectionName = None,
40+
webPublicationDate = Some(publicationDate.toCapiDateTime),
41+
webTitle = "webTitle",
42+
webUrl = "webUrl",
43+
apiUrl = "apiUrl",
44+
tags = defaultTag :: (if (isPaid) List(paidContentTag) else Nil),
45+
elements = None,
46+
fields = Some(
47+
ContentFields(
48+
sensitive = Some(isSensitive),
49+
shouldHideReaderRevenue = shouldHideReaderRevenue,
50+
shouldHideAdverts = Some(shouldHideAdverts)
51+
)
52+
)
53+
)
54+
}
55+
56+
"shouldHideReaderRevenue" should "hide if shouldHideReaderRevenue is unset, and content is sensitive and published before cutoff" in {
57+
val content = contentApi(isSensitive = true, publicationDate = dateBeforeCutoff)
58+
Fields.shouldHideReaderRevenue(content, cutoffDate) should be(true)
59+
}
60+
61+
it should "hide if shouldHideReaderRevenue is unset, and content is shouldHideAdverts and published before cutoff" in {
62+
val content = contentApi(shouldHideAdverts = true, publicationDate = dateBeforeCutoff)
63+
Fields.shouldHideReaderRevenue(content, cutoffDate) should be(true)
64+
}
65+
66+
it should "not hide if shouldHideReaderRevenue is unset and published after cutoff, even if sensitive" in {
67+
val content = contentApi(isSensitive = true, publicationDate = dateAfterCutoff)
68+
Fields.shouldHideReaderRevenue(content, cutoffDate) should be(false)
69+
}
70+
71+
it should "not hide if shouldHideReaderRevenue is unset and published after cutoff, even if shouldHideAdverts" in {
72+
val content = contentApi(shouldHideAdverts = true, publicationDate = dateAfterCutoff)
73+
Fields.shouldHideReaderRevenue(content, cutoffDate) should be(false)
74+
}
75+
76+
it should "not hide if shouldHideReaderRevenue is false and published before cutoff, even if sensitive" in {
77+
val content = contentApi(shouldHideReaderRevenue = Some(false), isSensitive = true, publicationDate = dateBeforeCutoff)
78+
Fields.shouldHideReaderRevenue(content, cutoffDate) should be(false)
79+
}
80+
81+
it should "hide if shouldHideReaderRevenue is true, regardless of publication date or sensitive flag" in {
82+
val sensitiveOldContent = contentApi(shouldHideReaderRevenue = Some(true), isSensitive = true, publicationDate = dateBeforeCutoff)
83+
val sensitiveNewContent = contentApi(shouldHideReaderRevenue = Some(true), isSensitive = true, publicationDate = dateBeforeCutoff)
84+
val notSensitiveOldContent = contentApi(shouldHideReaderRevenue = Some(true), publicationDate = dateAfterCutoff)
85+
val notSensitiveNewContent = contentApi(shouldHideReaderRevenue = Some(true), publicationDate = dateAfterCutoff)
86+
87+
Fields.shouldHideReaderRevenue(sensitiveOldContent, cutoffDate) should be(true)
88+
Fields.shouldHideReaderRevenue(sensitiveNewContent, cutoffDate) should be(true)
89+
Fields.shouldHideReaderRevenue(notSensitiveOldContent, cutoffDate) should be(true)
90+
Fields.shouldHideReaderRevenue(notSensitiveNewContent, cutoffDate) should be(true)
91+
}
92+
93+
it should "hide if content is paid, regardless of shouldHideReaderRevenue flag, publication date or sensitive flag" in {
94+
val sensitiveOldContent = contentApi(shouldHideReaderRevenue = Some(false), isSensitive = true, isPaid = true, publicationDate = dateBeforeCutoff)
95+
val sensitiveNewContent = contentApi(shouldHideReaderRevenue = Some(true), isSensitive = true, isPaid = true, publicationDate = dateBeforeCutoff)
96+
val notSensitiveOldContent = contentApi(shouldHideReaderRevenue = None, isPaid = true, publicationDate = dateAfterCutoff)
97+
val notSensitiveNewContent = contentApi(shouldHideReaderRevenue = None, isPaid = true, publicationDate = dateAfterCutoff)
98+
99+
Fields.shouldHideReaderRevenue(sensitiveOldContent, cutoffDate) should be(true)
100+
Fields.shouldHideReaderRevenue(sensitiveNewContent, cutoffDate) should be(true)
101+
Fields.shouldHideReaderRevenue(notSensitiveOldContent, cutoffDate) should be(true)
102+
Fields.shouldHideReaderRevenue(notSensitiveNewContent, cutoffDate) should be(true)
103+
}
18104
}

‎static/src/javascripts-legacy/projects/common/modules/experiments/tests/acquisitions-epic-always-ask-if-tagged.js‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ define([
2020
audienceCriteria: 'All',
2121
audience: 1,
2222
audienceOffset: 0,
23-
showForSensitive: true,
2423
useTargetingTool: true,
2524

2625

‎static/src/javascripts-legacy/projects/common/modules/experiments/tests/acquisitions-epic-election-interactive-end.js‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@ define([
3030
audience: 1,
3131
audienceOffset: 0,
3232

33-
showForSensitive: true,
34-
3533
pageCheck: function(page) {
3634
var isElection = page.keywordIds &&
3735
page.keywordIds.includes('general-election-2017') &&

‎static/src/javascripts-legacy/projects/common/modules/experiments/tests/acquisitions-epic-election-interactive-slice.js‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@ define([
2929
audience: 1,
3030
audienceOffset: 0,
3131

32-
showForSensitive: true,
33-
3432
pageCheck: function(page) {
3533
return page.keywordIds &&
3634
page.keywordIds.includes('general-election-2017') &&

‎static/src/javascripts-legacy/projects/common/modules/experiments/tests/acquisitions-epic-liveblog-design-test.js‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,6 @@ define([
9191
audience: 1,
9292
audienceOffset: 0,
9393

94-
showForSensitive: true,
95-
9694
pageCheck: function(page) {
9795
return page.contentType === 'LiveBlog';
9896
},

‎static/src/javascripts-legacy/projects/common/modules/experiments/tests/acquisitions-epic-liveblog.js‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,6 @@ define([
6868
audience: 1,
6969
audienceOffset: 0,
7070

71-
showForSensitive: true,
72-
7371
pageCheck: function(page) {
7472
return page.contentType === 'LiveBlog';
7573
},

‎static/src/javascripts-legacy/projects/common/modules/experiments/tests/acquisitions-epic-thank-you.js‎

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,8 @@ define([
1212
acquisitionsEpicThankYouTemplate
1313
) {
1414

15-
function isRecentContributor() {
16-
return contributionsUtilities.daysSinceLastContribution < 180
17-
}
18-
1915
function isTargetReader() {
20-
return userFeatures.isPayingMember() || isRecentContributor()
16+
return userFeatures.isPayingMember() || userFeatures.isRecentContributor()
2117
}
2218

2319
function worksWellWithPageTemplate() {
@@ -27,9 +23,7 @@ define([
2723
}
2824

2925
function isTargetPage() {
30-
return worksWellWithPageTemplate() &&
31-
!config.page.isPaidContent &&
32-
!config.page.shouldHideAdverts
26+
return worksWellWithPageTemplate() && !config.page.shouldHideReaderRevenue
3327
}
3428

3529
return contributionsUtilities.makeABTest({

‎static/src/javascripts-legacy/projects/common/modules/experiments/tests/acquisitions-this-land-series.js‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ define([
1919
audience: 1,
2020
audienceOffset: 0,
2121

22-
showForSensitive: true,
2322
showToContributorsAndSupporters: true,
2423

2524
useTargetingTool: true,

‎static/src/javascripts-legacy/projects/common/modules/experiments/tests/bundle-digital-sub-price-test-1.js‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ define([
5050
audienceCriteria: 'Non-paying UK edition readers - mobile resolution and above',
5151
audience: 0.1,
5252
audienceOffset: 0,
53-
showForSensitive: false,
5453
useTargetingTool: false,
5554

5655
overrideCanRun: false,
@@ -59,7 +58,7 @@ define([
5958
config.page.edition.toUpperCase() === 'UK' &&
6059
config.page.contentType === 'Article' &&
6160
!config.page.isMinuteArticle &&
62-
commercialFeatures.commercialFeatures.canReasonablyAskForMoney
61+
contributionsUtilities.shouldShowReaderRevenue()
6362
},
6463

6564
variants: [

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL