Skip to content
Permalink
Browse files

FIX: no_ads_for_tags support for hidden tags

Hidden tags aren't sent to the client, so they couldn't be used to
disable ads on topic pages. Do this calculation on the server.
Topic list pages for tags can continue to check on the client because
non-staff get a 404 error when trying to view a hidden tag's topic list.
  • Loading branch information...
nlalonde committed Jun 17, 2019
1 parent ca345f2 commit 92609c7af4ce6326cfb4d9615429058a8b8f12f7
Showing with 19 additions and 15 deletions.
  1. +13 −15 assets/javascripts/discourse/components/ad-component.js.es6
  2. +6 −0 plugin.rb
@@ -13,18 +13,18 @@ export default Ember.Component.extend({
"router.currentRoute.parent.attributes.category.slug"
),

// Server needs to compute this in case hidden tags are being used.
topicTagsDisableAds: Ember.computed.alias(
"router.currentRoute.parent.attributes.tags_disable_ads"
),

@computed(
"router.currentRoute.parent.attributes.tags",
"router.currentRoute.attributes.__type",
"router.currentRoute.attributes.id"
)
currentTags(tagsArray, type, tag) {
if (tagsArray) {
return tagsArray;
}

topicListTag(type, tag) {
if (type === "tag" && tag) {
return [tag];
return tag;
}
},

@@ -49,21 +49,19 @@ export default Ember.Component.extend({
return !groupNames.any(g => noAdsGroupNames.includes(g));
},

@computed("currentCategoryId", "currentTags")
showOnCurrentPage(categoryId, currentTags) {
@computed("currentCategoryId", "topicTagsDisableAds", "topicListTag")
showOnCurrentPage(categoryId, topicTagsDisableAds, topicListTag) {
return (
!topicTagsDisableAds &&
(!categoryId ||
!this.siteSettings.no_ads_for_categories ||
!this.siteSettings.no_ads_for_categories
.split("|")
.includes(categoryId.toString())) &&
(!currentTags ||
(!topicListTag ||
!this.siteSettings.no_ads_for_tags ||
Ember.isEmpty(
this.siteSettings.no_ads_for_tags
.split("|")
.filter(tag => currentTags.includes(tag))
))
!this.siteSettings.no_ads_for_tags.split("|").includes(topicListTag)
)
);
},

@@ -39,6 +39,12 @@ def self.pstore_delete(key)
AdPlugin::HouseAdSetting.settings_and_ads
end

add_to_serializer :topic_view, :tags_disable_ads do
return false if !SiteSetting.tagging_enabled || !SiteSetting.no_ads_for_tags.present?
return false if object.topic.tags.empty?
!(SiteSetting.no_ads_for_tags.split('|') & object.topic.tags.map(&:name)).empty?
end

class ::AdstxtController < ::ApplicationController
skip_before_action :check_xhr

0 comments on commit 92609c7

Please sign in to comment.
You can’t perform that action at this time.