From 92609c7af4ce6326cfb4d9615429058a8b8f12f7 Mon Sep 17 00:00:00 2001 From: Neil Lalonde Date: Mon, 17 Jun 2019 17:20:38 -0400 Subject: [PATCH] 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. --- .../discourse/components/ad-component.js.es6 | 28 +++++++++---------- plugin.rb | 6 ++++ 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/assets/javascripts/discourse/components/ad-component.js.es6 b/assets/javascripts/discourse/components/ad-component.js.es6 index 660c681..7fa0aa5 100644 --- a/assets/javascripts/discourse/components/ad-component.js.es6 +++ b/assets/javascripts/discourse/components/ad-component.js.es6 @@ -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) + ) ); }, diff --git a/plugin.rb b/plugin.rb index 29e7528..fc63edc 100755 --- a/plugin.rb +++ b/plugin.rb @@ -39,6 +39,12 @@ after_initialize do 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