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.
This commit is contained in:
Neil Lalonde 2019-06-17 17:20:38 -04:00
parent ca345f273c
commit 92609c7af4
2 changed files with 19 additions and 15 deletions

View File

@ -13,18 +13,18 @@ export default Ember.Component.extend({
"router.currentRoute.parent.attributes.category.slug" "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( @computed(
"router.currentRoute.parent.attributes.tags",
"router.currentRoute.attributes.__type", "router.currentRoute.attributes.__type",
"router.currentRoute.attributes.id" "router.currentRoute.attributes.id"
) )
currentTags(tagsArray, type, tag) { topicListTag(type, tag) {
if (tagsArray) {
return tagsArray;
}
if (type === "tag" && 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)); return !groupNames.any(g => noAdsGroupNames.includes(g));
}, },
@computed("currentCategoryId", "currentTags") @computed("currentCategoryId", "topicTagsDisableAds", "topicListTag")
showOnCurrentPage(categoryId, currentTags) { showOnCurrentPage(categoryId, topicTagsDisableAds, topicListTag) {
return ( return (
!topicTagsDisableAds &&
(!categoryId || (!categoryId ||
!this.siteSettings.no_ads_for_categories || !this.siteSettings.no_ads_for_categories ||
!this.siteSettings.no_ads_for_categories !this.siteSettings.no_ads_for_categories
.split("|") .split("|")
.includes(categoryId.toString())) && .includes(categoryId.toString())) &&
(!currentTags || (!topicListTag ||
!this.siteSettings.no_ads_for_tags || !this.siteSettings.no_ads_for_tags ||
Ember.isEmpty( !this.siteSettings.no_ads_for_tags.split("|").includes(topicListTag)
this.siteSettings.no_ads_for_tags )
.split("|")
.filter(tag => currentTags.includes(tag))
))
); );
}, },

View File

@ -39,6 +39,12 @@ after_initialize do
AdPlugin::HouseAdSetting.settings_and_ads AdPlugin::HouseAdSetting.settings_and_ads
end 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 class ::AdstxtController < ::ApplicationController
skip_before_action :check_xhr skip_before_action :check_xhr