diff --git a/assets/javascripts/discourse/components/adbutler-ad.js b/assets/javascripts/discourse/components/adbutler-ad.js index ab786984..4360e39b 100644 --- a/assets/javascripts/discourse/components/adbutler-ad.js +++ b/assets/javascripts/discourse/components/adbutler-ad.js @@ -111,30 +111,42 @@ export default AdComponent.extend({ scheduleOnce("afterRender", this, this._triggerAds); }, - @discourseComputed("currentUser.trust_level") - showToTrustLevel(trustLevel) { - return !( - trustLevel && trustLevel > this.siteSettings.adbutler_through_trust_level + @discourseComputed("currentUser.groups") + showToThroughAllowedGroups(groups) { + const currentUser = this.currentUser; + + if ( + !currentUser || + !groups || + !this.siteSettings.adbutler_through_allowed_groups || + this.siteSettings.adbutler_through_allowed_groups.length === 0 + ) { + return true; + } + return groups.some((group) => + this.siteSettings.adbutler_through_allowed_groups + .map((g) => g.id) + .includes(group.id) ); }, @discourseComputed( "publisherId", - "showToTrustLevel", + "showToThroughAllowedGroups", "showToGroups", "showAfterPost", "showOnCurrentPage" ) showAd( publisherId, - showToTrustLevel, + showToThroughAllowedGroups, showToGroups, showAfterPost, showOnCurrentPage ) { return ( publisherId && - showToTrustLevel && + showToThroughAllowedGroups && showToGroups && showAfterPost && showOnCurrentPage diff --git a/assets/javascripts/discourse/components/amazon-product-links.js b/assets/javascripts/discourse/components/amazon-product-links.js index 571ed507..087af2e6 100644 --- a/assets/javascripts/discourse/components/amazon-product-links.js +++ b/assets/javascripts/discourse/components/amazon-product-links.js @@ -7,7 +7,7 @@ export default AdComponent.extend({ classNames: ["amazon-product-links"], showAd: and( - "showToTrustLevel", + "showToThroughAllowedGroups", "showToGroups", "showAfterPost", "showOnCurrentPage" @@ -173,10 +173,22 @@ export default AdComponent.extend({ return htmlSafe(`${userInput}`); }, - @discourseComputed("currentUser.trust_level") - showToTrustLevel(trustLevel) { - return !( - trustLevel && trustLevel > this.siteSettings.amazon_through_trust_level + @discourseComputed("currentUser.groups") + showToThroughAllowedGroups(groups) { + const currentUser = this.currentUser; + + if ( + !currentUser || + !groups || + !this.siteSettings.amazon_through_allowed_groups || + this.siteSettings.amazon_through_allowed_groups.length === 0 + ) { + return true; + } + return groups.some((group) => + this.siteSettings.amazon_through_allowed_groups + .map((g) => g.id) + .includes(group.id) ); }, diff --git a/assets/javascripts/discourse/components/carbonads-ad.js b/assets/javascripts/discourse/components/carbonads-ad.js index a9e5b95e..c7458008 100644 --- a/assets/javascripts/discourse/components/carbonads-ad.js +++ b/assets/javascripts/discourse/components/carbonads-ad.js @@ -19,31 +19,43 @@ export default AdComponent.extend({ ); }, - @discourseComputed("currentUser.trust_level") - showToTrustLevel(trustLevel) { - return !( - trustLevel && trustLevel > this.siteSettings.carbonads_through_trust_level + @discourseComputed("currentUser.groups") + showToThroughAllowedGroups(groups) { + const currentUser = this.currentUser; + + if ( + !currentUser || + !groups || + !this.siteSettings.carbonads_through_allowed_groups || + this.siteSettings.carbonads_through_allowed_groups.length === 0 + ) { + return true; + } + return groups.some((group) => + this.siteSettings.carbonads_through_allowed_groups + .map((g) => g.id) + .includes(group.id) ); }, @discourseComputed( "placement", "serve_id", - "showToTrustLevel", + "showToThroughAllowedGroups", "showToGroups", "showOnCurrentPage" ) showAd( placement, serveId, - showToTrustLevel, + showToThroughAllowedGroups, showToGroups, showOnCurrentPage ) { return ( placement && serveId && - showToTrustLevel && + showToThroughAllowedGroups && showToGroups && showOnCurrentPage ); diff --git a/assets/javascripts/discourse/components/google-adsense.js b/assets/javascripts/discourse/components/google-adsense.js index 696de452..e6d5acdf 100644 --- a/assets/javascripts/discourse/components/google-adsense.js +++ b/assets/javascripts/discourse/components/google-adsense.js @@ -206,15 +206,8 @@ export default AdComponent.extend({ ); }, - @discourseComputed("currentUser.trust_level") - showToTrustLevel(trustLevel) { - return !( - trustLevel && trustLevel > this.siteSettings.adsense_through_trust_level - ); - }, - @discourseComputed("currentUser.groups") - showToAllowedGroups(groups) { + showToThroughAllowedGroups(groups) { const currentUser = this.currentUser; if ( @@ -234,21 +227,21 @@ export default AdComponent.extend({ @discourseComputed( "publisher_id", - "showToAllowedGroups", + "showToThroughAllowedGroups", "showToGroups", "showAfterPost", "showOnCurrentPage" ) showAd( publisherId, - showToAllowedGroups, + showToThroughAllowedGroups, showToGroups, showAfterPost, showOnCurrentPage ) { return ( publisherId && - showToAllowedGroups && + showToThroughAllowedGroups && showToGroups && showAfterPost && showOnCurrentPage diff --git a/assets/javascripts/discourse/components/google-dfp-ad.js b/assets/javascripts/discourse/components/google-dfp-ad.js index b09f7a7e..32dc18af 100755 --- a/assets/javascripts/discourse/components/google-dfp-ad.js +++ b/assets/javascripts/discourse/components/google-dfp-ad.js @@ -299,7 +299,7 @@ export default AdComponent.extend({ @discourseComputed( "publisherId", - "showToTrustLevel", + "showToThroughAllowedGroups", "showToGroups", "showAfterPost", "showOnCurrentPage", @@ -307,7 +307,7 @@ export default AdComponent.extend({ ) showAd( publisherId, - showToTrustLevel, + showToThroughAllowedGroups, showToGroups, showAfterPost, showOnCurrentPage, @@ -315,7 +315,7 @@ export default AdComponent.extend({ ) { return ( publisherId && - showToTrustLevel && + showToThroughAllowedGroups && showToGroups && showAfterPost && showOnCurrentPage && @@ -323,10 +323,22 @@ export default AdComponent.extend({ ); }, - @discourseComputed("currentUser.trust_level") - showToTrustLevel(trustLevel) { - return !( - trustLevel && trustLevel > this.siteSettings.dfp_through_trust_level + @discourseComputed("currentUser.groups") + showToThroughAllowedGroups(groups) { + const currentUser = this.currentUser; + + if ( + !currentUser || + !groups || + !this.siteSettings.dfp_through_allowed_groups || + this.siteSettings.dfp_through_allowed_groups.length === 0 + ) { + return true; + } + return groups.some((group) => + this.siteSettings.dfp_through_allowed_groups + .map((g) => g.id) + .includes(group.id) ); }, diff --git a/config/settings.yml b/config/settings.yml index ebfd9e7a..9b69e6a6 100755 --- a/config/settings.yml +++ b/config/settings.yml @@ -171,6 +171,14 @@ dfp_plugin: client: true default: 2 enum: "TrustLevelSetting" + hidden: true + dfp_through_allowed_groups: + client: true + default: "10|11|12" + type: group_list + allow_any: false + refresh: true + validator: "AtLeastOneGroupValidator" dfp_topic_list_top_code: client: true default: "" @@ -320,6 +328,14 @@ amazon_plugin: client: true default: 2 enum: "TrustLevelSetting" + hidden: true + amazon_through_allowed_groups: + client: true + default: "10|11|12" + type: group_list + allow_any: false + refresh: true + validator: "AtLeastOneGroupValidator" amazon_topic_list_top_src_code: client: true default: "" @@ -408,6 +424,14 @@ carbonads_plugin: client: true default: 2 enum: "TrustLevelSetting" + hidden: true + carbonads_through_allowed_groups: + client: true + default: "10|11|12" + type: group_list + allow_any: false + refresh: true + validator: "AtLeastOneGroupValidator" carbonads_topic_list_top_enabled: client: true default: false @@ -423,6 +447,14 @@ adbutler_plugin: client: true default: 2 enum: "TrustLevelSetting" + hidden: true + adbutler_through_allowed_groups: + client: true + default: "10|11|12" + type: group_list + allow_any: false + refresh: true + validator: "AtLeastOneGroupValidator" adbutler_topic_list_top_zone_id: client: true default: "" diff --git a/test/javascripts/acceptance/dfp-test.js b/test/javascripts/acceptance/dfp-test.js index 0c53ecd4..ee69ecfd 100644 --- a/test/javascripts/acceptance/dfp-test.js +++ b/test/javascripts/acceptance/dfp-test.js @@ -1,5 +1,6 @@ import { visit } from "@ember/test-helpers"; import { test } from "qunit"; +import { AUTO_GROUPS } from "discourse/lib/constants"; import groupFixtures from "discourse/tests/fixtures/group-fixtures"; import { acceptance, @@ -13,6 +14,10 @@ acceptance("DFP Ads", function (needs) { no_ads_for_categories: "1", dfp_publisher_id: "MYdfpID", dfp_through_trust_level: 2, + dfp_through_allowed_groups: [ + AUTO_GROUPS.trust_level_1, + AUTO_GROUPS.trust_level_2, + ], dfp_topic_list_top_code: "list_top_ad_unit", dfp_topic_list_top_ad_sizes: "728*90 - leaderboard", dfp_mobile_topic_list_top_code: "mobile_list_top_ad_unit", @@ -60,7 +65,11 @@ acceptance("DFP Ads", function (needs) { }); test("no ads for trust level 3", async (assert) => { - updateCurrentUser({ staff: false, trust_level: 3 }); + updateCurrentUser({ + staff: false, + trust_level: 3, + groups: [AUTO_GROUPS.trust_level_3], + }); await visit("/t/280"); assert .dom(".google-dfp-ad.dfp-ad-post-bottom") diff --git a/test/javascripts/acceptance/mixed-ads-test.js b/test/javascripts/acceptance/mixed-ads-test.js index 754c6a11..d41f78df 100644 --- a/test/javascripts/acceptance/mixed-ads-test.js +++ b/test/javascripts/acceptance/mixed-ads-test.js @@ -1,5 +1,6 @@ import { visit } from "@ember/test-helpers"; import { test } from "qunit"; +import { AUTO_GROUPS } from "discourse/lib/constants"; import { acceptance, count, @@ -12,7 +13,10 @@ acceptance("Mixed Ads", function (needs) { house_ads_after_nth_post: 6, house_ads_frequency: 50, dfp_publisher_id: "MYdfpID", - dfp_through_trust_level: 2, + dfp_through_allowed_groups: [ + AUTO_GROUPS.trust_level_1, + AUTO_GROUPS.trust_level_2, + ], dfp_topic_list_top_code: "list_top_ad_unit", dfp_topic_list_top_ad_sizes: "728*90 - leaderboard", dfp_mobile_topic_list_top_code: "mobile_list_top_ad_unit",