diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index 5dd9054d1..110d1d819 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -67,4 +67,3 @@ accessibility is impacted and tested. For more info, check out the ## [optional] What gif best describes this PR or how it makes you feel?  - diff --git a/app/controllers/display_ads_controller.rb b/app/controllers/display_ads_controller.rb new file mode 100644 index 000000000..eec3106db --- /dev/null +++ b/app/controllers/display_ads_controller.rb @@ -0,0 +1,30 @@ +class DisplayAdsController < ApplicationController + before_action :set_cache_control_headers, only: %i[for_display], unless: -> { current_user } + CACHE_EXPIRY_FOR_DISPLAY_ADS = 15.minutes.to_i.freeze + + def show + skip_authorization + set_cache_control_headers(CACHE_EXPIRY_FOR_DISPLAY_ADS) unless session_current_user_id + + if params[:placement_area] + if params[:username].present? && params[:slug].present? + @article = Article.find_by(slug: params[:slug]) + end + + @display_ad = DisplayAd.for_display( + area: params[:placement_area], + user_signed_in: user_signed_in?, + organization_id: @article&.organization_id, + permit_adjacent_sponsors: ArticleDecorator.new(@article).permit_adjacent_sponsors?, + article_tags: @article&.decorate&.cached_tag_list_array || [], + article_id: @article&.id, + ) + + if @display_ad && !session_current_user_id + set_surrogate_key_header @display_ad.record_key + end + end + + render layout: false + end +end diff --git a/app/decorators/article_decorator.rb b/app/decorators/article_decorator.rb index 821947f98..fb07d7a48 100644 --- a/app/decorators/article_decorator.rb +++ b/app/decorators/article_decorator.rb @@ -113,6 +113,8 @@ class ArticleDecorator < ApplicationDecorator end def permit_adjacent_sponsors? + return true unless respond_to?(:user_id) && user_id.present? + author_ids = [user_id] + co_author_ids Users::Setting.where(user_id: author_ids).all?(&:permit_adjacent_sponsors) end diff --git a/app/javascript/packs/billboard.js b/app/javascript/packs/billboard.js new file mode 100644 index 000000000..f9b7d7ccb --- /dev/null +++ b/app/javascript/packs/billboard.js @@ -0,0 +1,23 @@ +import { setupDisplayAdDropdown } from '../utilities/displayAdDropdown'; + +// the term billboard can be synonymously interchanged with displayAd +async function getBillboard() { + const placeholderElement = document.getElementsByClassName( + 'js-display-ad-comments-container', + )[0]; + + const { asyncUrl } = placeholderElement.dataset || {}; + + if (placeholderElement.innerHTML.trim() === '') { + const response = await window.fetch(`${asyncUrl}`); + const htmlContent = await response.text(); + + const generatedElement = document.createElement('div'); + generatedElement.innerHTML = htmlContent; + + placeholderElement.appendChild(generatedElement); + setupDisplayAdDropdown(); + } +} + +getBillboard(); diff --git a/app/views/articles/_sidebar.html.erb b/app/views/articles/_sidebar.html.erb index 500da4414..2af17ff10 100644 --- a/app/views/articles/_sidebar.html.erb +++ b/app/views/articles/_sidebar.html.erb @@ -8,14 +8,14 @@ <% cache("display-area-left-#{rand(5)}-#{user_signed_in?}", expires_in: 5.minutes) do %> <% @left_sidebar_ad = DisplayAd.for_display(area: "sidebar_left", user_signed_in: user_signed_in?) %> <% if @left_sidebar_ad %> - <%= render partial: "shared/display_ad", locals: {display_ad: @left_sidebar_ad, data_context_type: DisplayAdEvent::CONTEXT_TYPE_HOME} %> + <%= render partial: "shared/display_ad", locals: { display_ad: @left_sidebar_ad, data_context_type: DisplayAdEvent::CONTEXT_TYPE_HOME } %> <% end %> <% end %> <% cache("display-area-left-2-#{rand(5)}-#{user_signed_in?}", expires_in: 5.minutes) do %> <% @second_left_sidebar_ad = DisplayAd.for_display(area: "sidebar_left_2", user_signed_in: user_signed_in?) %> <% if @second_left_sidebar_ad %>