Skip to content

Commit

Permalink
Convert remaining settings
Browse files Browse the repository at this point in the history
  • Loading branch information
oblakeerickson committed Jan 19, 2024
1 parent 9198c2f commit 6b373e5
Show file tree
Hide file tree
Showing 8 changed files with 125 additions and 39 deletions.
26 changes: 19 additions & 7 deletions assets/javascripts/discourse/components/adbutler-ad.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 17 additions & 5 deletions assets/javascripts/discourse/components/amazon-product-links.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export default AdComponent.extend({
classNames: ["amazon-product-links"],

showAd: and(
"showToTrustLevel",
"showToThroughAllowedGroups",
"showToGroups",
"showAfterPost",
"showOnCurrentPage"
Expand Down Expand Up @@ -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)
);
},

Expand Down
26 changes: 19 additions & 7 deletions assets/javascripts/discourse/components/carbonads-ad.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
Expand Down
15 changes: 4 additions & 11 deletions assets/javascripts/discourse/components/google-adsense.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -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
Expand Down
26 changes: 19 additions & 7 deletions assets/javascripts/discourse/components/google-dfp-ad.js
Original file line number Diff line number Diff line change
Expand Up @@ -299,34 +299,46 @@ export default AdComponent.extend({

@discourseComputed(
"publisherId",
"showToTrustLevel",
"showToThroughAllowedGroups",
"showToGroups",
"showAfterPost",
"showOnCurrentPage",
"size"
)
showAd(
publisherId,
showToTrustLevel,
showToThroughAllowedGroups,
showToGroups,
showAfterPost,
showOnCurrentPage,
size
) {
return (
publisherId &&
showToTrustLevel &&
showToThroughAllowedGroups &&
showToGroups &&
showAfterPost &&
showOnCurrentPage &&
size
);
},

@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)
);
},

Expand Down
32 changes: 32 additions & 0 deletions config/settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: ""
Expand Down Expand Up @@ -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: ""
Expand Down Expand Up @@ -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
Expand All @@ -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: ""
Expand Down
11 changes: 10 additions & 1 deletion test/javascripts/acceptance/dfp-test.js
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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",
Expand Down Expand Up @@ -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")
Expand Down
6 changes: 5 additions & 1 deletion test/javascripts/acceptance/mixed-ads-test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { visit } from "@ember/test-helpers";
import { test } from "qunit";
import { AUTO_GROUPS } from "discourse/lib/constants";
import {
acceptance,
count,
Expand All @@ -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",
Expand Down

0 comments on commit 6b373e5

Please sign in to comment.