From 50d258dc37e3f8b167f94fd5f32328f715d2c5ae Mon Sep 17 00:00:00 2001 From: Neil Lalonde Date: Wed, 17 Apr 2019 15:36:21 -0400 Subject: [PATCH] Revert "FEATURE: use groups to control who sees ads" and all later Revert "Updates to codefund-ad" Revert "Updates to carbonads-ad" Revert "Updates to amazon-product-links" --- .../discourse/components/ad_component.js.es6 | 23 ------ .../components/amazon-product-links.js.es6 | 57 +++++++-------- .../discourse/components/carbonads-ad.js.es6 | 20 ++--- .../discourse/components/codefund-ad.js.es6 | 55 +++++++------- .../components/google-adsense.js.es6 | 31 ++++---- .../discourse/components/google-dfp-ad.js.es6 | 73 ++++++++----------- .../components/amazon-product-links.hbs | 2 +- config/locales/client.en.yml | 1 - config/locales/server.en.yml | 2 - config/settings.yml | 8 -- .../acceptance/adsense-test.js.es6 | 16 ---- test/javascripts/acceptance/dfp-test.js.es6 | 72 ------------------ 12 files changed, 108 insertions(+), 252 deletions(-) delete mode 100644 assets/javascripts/discourse/components/ad_component.js.es6 delete mode 100644 test/javascripts/acceptance/dfp-test.js.es6 diff --git a/assets/javascripts/discourse/components/ad_component.js.es6 b/assets/javascripts/discourse/components/ad_component.js.es6 deleted file mode 100644 index b8d6f30..0000000 --- a/assets/javascripts/discourse/components/ad_component.js.es6 +++ /dev/null @@ -1,23 +0,0 @@ -import computed from "ember-addons/ember-computed-decorators"; - -export default Ember.Component.extend({ - @computed() - showToGroups: function() { - const currentUser = Discourse.User.current(); - - if ( - !currentUser || - !currentUser.get("groups") || - !this.siteSettings.no_ads_for_groups || - this.siteSettings.no_ads_for_groups.length === 0 - ) { - return true; - } - - const noAdsGroupNames = this.siteSettings.no_ads_for_groups.split("|"); - - return !currentUser - .get("groups") - .any(group => noAdsGroupNames.includes(group.name)); - } -}); diff --git a/assets/javascripts/discourse/components/amazon-product-links.js.es6 b/assets/javascripts/discourse/components/amazon-product-links.js.es6 index 853a92b..7c5d424 100644 --- a/assets/javascripts/discourse/components/amazon-product-links.js.es6 +++ b/assets/javascripts/discourse/components/amazon-product-links.js.es6 @@ -1,9 +1,6 @@ -import AdComponent from "discourse/plugins/discourse-adplugin/discourse/components/ad_component"; -import computed from "ember-addons/ember-computed-decorators"; +var currentUser = Discourse.User.current(); -const currentUser = Discourse.User.current(); - -const data = { +var data = { "topic-list-top": {}, "topic-above-post-stream": {}, "topic-above-suggested": {}, @@ -122,12 +119,10 @@ if ( ); } -export default AdComponent.extend({ +export default Ember.Component.extend({ classNames: ["amazon-product-links"], - showAd: Ember.computed.and("showToTrustLevel", "showToGroups"), - - init() { + init: function() { let placement = this.get("placement"); this.set("user_input", data[placement]["user_input"]); this.set("amazon_width", data[placement]["amazon_width"]); @@ -138,37 +133,35 @@ export default AdComponent.extend({ this._super(); }, - @computed("amazon_width", "amazon_height") - adWrapperStyle(w, h) { - return `width: ${w}px; height: ${h}px;`.htmlSafe(); - }, + adWrapperStyle: function() { + return `width: ${this.get("amazon_width")}px; height: ${this.get( + "amazon_height" + )}px;`.htmlSafe(); + }.property("amazon_width", "amazon_height"), - @computed("mobile_amazon_width", "mobile_amazon_height") - adWrapperStyleMobile(w, h) { - return `width: ${w}px; height: ${h}px;`.htmlSafe(); - }, + adWrapperStyleMobile: function() { + return `width: ${this.get("mobile_amazon_width")}px; height: ${this.get( + "mobile_amazon_height" + )}px;`.htmlSafe(); + }.property("mobile_amazon_width", "mobile_amazon_height"), - @computed("mobile_amazon_width") - adTitleStyleMobile(w) { - return `width: ${w}px;`.htmlSafe(); - }, + adTitleStyleMobile: function() { + return `width: ${this.get("mobile_amazon_width")}px;`.htmlSafe(); + }.property("mobile_amazon_width"), - @computed("user_input") - userInput(userInput) { - return `${userInput}`.htmlSafe(); - }, + userInput: function() { + return `${this.get("user_input")}`.htmlSafe(); + }.property("user_input"), - @computed("user_input_mobile") - userInputMobile(userInput) { - return `${userInput}`.htmlSafe(); - }, + userInputMobile: function() { + return `${this.get("user_input_mobile")}`.htmlSafe(); + }.property("user_input_mobile"), - @computed() - showToTrustLevel() { + checkTrustLevels: function() { return !( currentUser && currentUser.get("trust_level") > Discourse.SiteSettings.amazon_through_trust_level ); - } + }.property("trust_level") }); diff --git a/assets/javascripts/discourse/components/carbonads-ad.js.es6 b/assets/javascripts/discourse/components/carbonads-ad.js.es6 index 2de358c..2f42edc 100644 --- a/assets/javascripts/discourse/components/carbonads-ad.js.es6 +++ b/assets/javascripts/discourse/components/carbonads-ad.js.es6 @@ -1,4 +1,3 @@ -import AdComponent from "discourse/plugins/discourse-adplugin/discourse/components/ad_component"; import { default as computed, observes @@ -8,20 +7,21 @@ const currentUser = Discourse.User.current(), serve_id = Discourse.SiteSettings.carbonads_serve_id, placement = Discourse.SiteSettings.carbonads_placement; -export default AdComponent.extend({ - init() { +export default Ember.Component.extend({ + init: function() { this.set("serve_id", serve_id); this.set("placement", placement); this._super(); }, @computed("serve_id", "placement") - url(serveId, placement) { - return `//cdn.carbonads.com/carbon.js?serve=${serveId}&placement=${placement}`.htmlSafe(); + url: function() { + return (`//cdn.carbonads.com/carbon.js?serve=${this.get("serve_id")}&placement=${this.get("placement")}`).htmlSafe(); }, - @computed() - showToTrustLevel() { + + @computed("trust_level") + checkTrustLevels: function() { return !( currentUser && currentUser.get("trust_level") > @@ -29,8 +29,8 @@ export default AdComponent.extend({ ); }, - @computed("showToTrustLevel", "showToGroups") - showAd(showToTrustLevel, showToGroups) { - return placement && serve_id && showToTrustLevel && showToGroups; + @computed("checkTrustLevels") + showAd: function(checkTrustLevels) { + return placement && serve_id && checkTrustLevels; } }); diff --git a/assets/javascripts/discourse/components/codefund-ad.js.es6 b/assets/javascripts/discourse/components/codefund-ad.js.es6 index edb9817..1d76f53 100644 --- a/assets/javascripts/discourse/components/codefund-ad.js.es6 +++ b/assets/javascripts/discourse/components/codefund-ad.js.es6 @@ -1,13 +1,11 @@ -import AdComponent from "discourse/plugins/discourse-adplugin/discourse/components/ad_component"; import { default as computed, observes } from "ember-addons/ember-computed-decorators"; -let _loaded = false, - _promise = null; - -const currentUser = Discourse.User.current(), +var _loaded = false, + _promise = null, + currentUser = Discourse.User.current(), propertyId = Discourse.SiteSettings.codefund_property_id; function loadCodeFund() { @@ -50,23 +48,12 @@ function loadCodeFund() { return _promise; } -export default AdComponent.extend({ +export default Ember.Component.extend({ classNameBindings: [":codefund-ad"], propertyId: propertyId, adRequested: false, adDetails: {}, - displayPostBottom: Ember.computed.equal("placement", "post-bottom"), - displayTopicAbovePostStream: Ember.computed.equal( - "placement", - "topic-above-post-stream" - ), - displayTopicAboveSuggested: Ember.computed.equal( - "placement", - "topic-above-suggested" - ), - displayTopicListTop: Ember.computed.equal("placement", "topic-list-top"), - _triggerAds() { if (!propertyId) return; @@ -96,7 +83,7 @@ export default AdComponent.extend({ }, @observes("listLoading") - waitForLoad() { + waitForLoad: function() { if (this.get("adRequested")) { return; } // already requested that this ad unit be populated @@ -106,7 +93,7 @@ export default AdComponent.extend({ }, @computed() - showToTrustLevel() { + checkTrustLevels: function() { return !( currentUser && currentUser.get("trust_level") > @@ -114,12 +101,28 @@ export default AdComponent.extend({ ); }, - @computed("showToTrustLevel", "showToGroups") - showAd(showToTrustLevel, showToGroups) { - return ( - Discourse.SiteSettings.codefund_property_id && - showToTrustLevel && - showToGroups - ); + @computed("checkTrustLevels") + showAd: function(checkTrustLevels) { + return Discourse.SiteSettings.codefund_property_id && checkTrustLevels; + }, + + @computed("placement") + displayPostBottom: function(placement) { + return placement === "post-bottom"; + }, + + @computed("placement") + displayTopicAbovePostStream: function() { + return this.get("placement") === "topic-above-post-stream"; + }, + + @computed("placement") + displayTopicAboveSuggested: function() { + return this.get("placement") === "topic-above-suggested"; + }, + + @computed("placement") + displayTopicListTop: function() { + return this.get("placement") === "topic-list-top"; } }); diff --git a/assets/javascripts/discourse/components/google-adsense.js.es6 b/assets/javascripts/discourse/components/google-adsense.js.es6 index b3a910b..bdab286 100644 --- a/assets/javascripts/discourse/components/google-adsense.js.es6 +++ b/assets/javascripts/discourse/components/google-adsense.js.es6 @@ -1,4 +1,3 @@ -import AdComponent from "discourse/plugins/discourse-adplugin/discourse/components/ad_component"; import { default as computed, observes @@ -147,7 +146,7 @@ if (Discourse.SiteSettings.adsense_publisher_code) { } } -export default AdComponent.extend({ +export default Ember.Component.extend({ classNameBindings: [ ":google-adsense", "classForSlot", @@ -194,7 +193,7 @@ export default AdComponent.extend({ }, @observes("listLoading") - waitForLoad() { + waitForLoad: function() { if (this.get("adRequested")) { return; } // already requested that this ad unit be populated @@ -204,34 +203,34 @@ export default AdComponent.extend({ }, @computed("ad_width") - isResponsive(adWidth) { + isResponsive: function(adWidth) { return adWidth === "auto"; }, - @computed("placement", "showAd") - classForSlot(placement, showAd) { - return showAd ? `adsense-${placement}`.htmlSafe() : ""; + @computed("placement", "checkTrustLevels") + classForSlot: function(placement, shown) { + return shown ? `adsense-${placement}`.htmlSafe() : ""; }, @computed("isResponsive") - autoAdFormat(isResponsive) { + autoAdFormat: function(isResponsive) { return isResponsive ? "auto".htmlSafe() : false; }, @computed("ad_width", "ad_height", "isResponsive") - adWrapperStyle(w, h, isResponsive) { + adWrapperStyle: function(w, h, isResponsive) { return (isResponsive ? "" : `width: ${w}; height: ${h};`).htmlSafe(); }, @computed("adWrapperStyle", "isResponsive") - adInsStyle(adWrapperStyle, isResponsive) { + adInsStyle: function(adWrapperStyle, isResponsive) { return `display: ${ isResponsive ? "block" : "inline-block" }; ${adWrapperStyle}`.htmlSafe(); }, @computed() - showToTrustLevel() { + checkTrustLevels: function() { return !( currentUser && currentUser.get("trust_level") > @@ -239,12 +238,8 @@ export default AdComponent.extend({ ); }, - @computed("showToTrustLevel", "showToGroups") - showAd(showToTrustLevel, showToGroups) { - return ( - showToTrustLevel && - showToGroups && - Discourse.SiteSettings.adsense_publisher_code - ); + @computed("checkTrustLevels") + showAd: function(shown) { + return shown && Discourse.SiteSettings.adsense_publisher_code; } }); diff --git a/assets/javascripts/discourse/components/google-dfp-ad.js.es6 b/assets/javascripts/discourse/components/google-dfp-ad.js.es6 index 55a570d..2c236e6 100755 --- a/assets/javascripts/discourse/components/google-dfp-ad.js.es6 +++ b/assets/javascripts/discourse/components/google-dfp-ad.js.es6 @@ -1,9 +1,3 @@ -import AdComponent from "discourse/plugins/discourse-adplugin/discourse/components/ad_component"; -import { - default as computed, - observes, - on -} from "ember-addons/ember-computed-decorators"; import loadScript from "discourse/lib/load-script"; var currentUser = Discourse.User.current(), @@ -204,56 +198,51 @@ function loadGoogle() { return _promise; } -export default AdComponent.extend({ +export default Ember.Component.extend({ classNameBindings: ["adUnitClass"], classNames: ["google-dfp-ad"], loadedGoogletag: false, refreshOnChange: null, - @computed("placement", "postNumber") - divId(placement, postNumber) { - if (postNumber) { - return `div-gpt-ad-${placement}-${postNumber}`; + divId: function() { + if (this.get("postNumber")) { + return ( + "div-gpt-ad-" + this.get("placement") + "-" + this.get("postNumber") + ); } else { - return `div-gpt-ad-${placement}`; + return "div-gpt-ad-" + this.get("placement"); } - }, + }.property("placement", "postNumber"), - @computed("placement", "showAd") - adUnitClass(placement, showAd) { - return showAd ? `dfp-ad-${placement}` : ""; - }, + adUnitClass: function() { + return "dfp-ad-" + this.get("placement"); + }.property("placement"), - @computed("width", "height") - adWrapperStyle(w, h) { - return `width: ${w}px; height: ${h}px;`.htmlSafe(); - }, + adWrapperStyle: function() { + return `width: ${this.get("width")}px; height: ${this.get( + "height" + )}px;`.htmlSafe(); + }.property("width", "height"), - @computed("width") - adTitleStyleMobile(w) { - return `width: ${w}px;`.htmlSafe(); - }, + adTitleStyleMobile: function() { + return `width: ${this.get("width")}px;`.htmlSafe(); + }.property("width"), - @computed("showToTrustLevel", "showToGroups") - showAd(showToTrustLevel, showToGroups) { + showAd: function() { return ( - Discourse.SiteSettings.dfp_publisher_id && - showToTrustLevel && - showToGroups + Discourse.SiteSettings.dfp_publisher_id && this.get("checkTrustLevels") ); - }, + }.property("checkTrustLevels"), - @computed() - showToTrustLevel() { + checkTrustLevels: function() { return !( currentUser && currentUser.get("trust_level") > Discourse.SiteSettings.dfp_through_trust_level ); - }, + }.property("trust_level"), - @observes("refreshOnChange") - refreshAd() { + refreshAd: function() { var slot = ads[this.get("divId")]; if (!(slot && slot.ad)) { return; @@ -271,10 +260,9 @@ export default AdComponent.extend({ window.googletag.pubads().refresh([ad]); }); } - }, + }.observes("refreshOnChange"), - @on("didInsertElement") - _initGoogleDFP() { + _initGoogleDFP: function() { if (!this.get("showAd")) { return; } @@ -299,7 +287,7 @@ export default AdComponent.extend({ } }); }); - }, + }.on("didInsertElement"), willRender() { this._super(...arguments); @@ -312,8 +300,7 @@ export default AdComponent.extend({ this.set("height", size.height); }, - @on("willDestroyElement") - cleanup() { + cleanup: function() { destroySlot(this.get("divId")); - } + }.on("willDestroyElement") }); diff --git a/assets/javascripts/discourse/templates/components/amazon-product-links.hbs b/assets/javascripts/discourse/templates/components/amazon-product-links.hbs index 3516dcf..8eb83d8 100644 --- a/assets/javascripts/discourse/templates/components/amazon-product-links.hbs +++ b/assets/javascripts/discourse/templates/components/amazon-product-links.hbs @@ -1,4 +1,4 @@ -{{#if showAd}} +{{#if checkTrustLevels}} {{#if site.mobileView}}