diff --git a/app/controllers/api/v1/billboards_controller.rb b/app/controllers/api/v1/billboards_controller.rb index 09a9b74c2..88cc8abe5 100644 --- a/app/controllers/api/v1/billboards_controller.rb +++ b/app/controllers/api/v1/billboards_controller.rb @@ -47,7 +47,7 @@ module Api end def permitted_params - params.permit :approved, :body_markdown, :creator_id, :display_to, + params.permit :approved, :body_markdown, :creator_id, :display_to, :page_id, :name, :organization_id, :placement_area, :published, :dismissal_sku, :tag_list, :type_of, :exclude_article_ids, :weight, :requires_cookies, :audience_segment_type, :audience_segment_id, :priority, :special_behavior, diff --git a/app/controllers/billboards_controller.rb b/app/controllers/billboards_controller.rb index 175c5d80e..8ffcb37da 100644 --- a/app/controllers/billboards_controller.rb +++ b/app/controllers/billboards_controller.rb @@ -30,6 +30,7 @@ class BillboardsController < ApplicationController user_signed_in: user_signed_in?, user_id: current_user&.id, article: @article ? ArticleDecorator.new(@article) : nil, + page_id: params[:page_id], user_tags: user_tags, cookies_allowed: cookies_allowed?, location: client_geolocation, @@ -60,7 +61,7 @@ class BillboardsController < ApplicationController end def return_test_billboard? - param_present = params[:bb_test_placement_area] == placement_area && params[:bb_test_id].present? + param_present = params[:bb_test_placement_area] == placement_area && params[:bb_test_id].present? present_and_admin = param_present && current_user&.any_admin? present_and_live = param_present && Billboard.approved_and_published.where(id: params[:bb_test_id]).any? present_and_admin || present_and_live diff --git a/app/models/billboard.rb b/app/models/billboard.rb index d5556b4a0..bf963a477 100644 --- a/app/models/billboard.rb +++ b/app/models/billboard.rb @@ -4,8 +4,8 @@ class Billboard < ApplicationRecord resourcify belongs_to :creator, class_name: "User", optional: true belongs_to :audience_segment, optional: true + belongs_to :page, optional: true - # rubocop:disable Layout/LineLength ALLOWED_PLACEMENT_AREAS = %w[sidebar_left sidebar_left_2 sidebar_right @@ -14,10 +14,10 @@ class Billboard < ApplicationRecord feed_first feed_second feed_third home_hero + page_fixed_bottom post_fixed_bottom post_sidebar post_comments].freeze - # rubocop:enable Layout/LineLength ALLOWED_PLACEMENT_AREAS_HUMAN_READABLE = ["Sidebar Left (First Position)", "Sidebar Left (Second Position)", "Sidebar Right (Home first position)", @@ -27,6 +27,7 @@ class Billboard < ApplicationRecord "Home Feed Second", "Home Feed Third", "Home Hero", + "Fixed Bottom (Page)", "Fixed Bottom (Individual Post)", "Sidebar Right (Individual Post)", "Below the comment section"].freeze @@ -79,7 +80,8 @@ class Billboard < ApplicationRecord self.table_name = "display_ads" - def self.for_display(area:, user_signed_in:, user_id: nil, article: nil, user_tags: nil, location: nil, cookies_allowed: false) + def self.for_display(area:, user_signed_in:, user_id: nil, article: nil, user_tags: nil, + location: nil, cookies_allowed: false, page_id: nil) permit_adjacent = article ? article.permit_adjacent_sponsors? : true billboards_for_display = Billboards::FilteredAdsQuery.call( @@ -91,6 +93,7 @@ class Billboard < ApplicationRecord organization_id: article&.organization_id, permit_adjacent_sponsors: permit_adjacent, user_id: user_id, + page_id: page_id, user_tags: user_tags, location: location, cookies_allowed: cookies_allowed, diff --git a/app/models/page.rb b/app/models/page.rb index 17fce7900..47e5b9952 100644 --- a/app/models/page.rb +++ b/app/models/page.rb @@ -6,6 +6,8 @@ class Page < ApplicationRecord CODE_OF_CONDUCT_SLUG = "code-of-conduct".freeze PRIVACY_SLUG = "privacy".freeze + has_many :billboards, dependent: :nullify + validates :title, presence: true validates :description, presence: true validates :template, inclusion: { in: TEMPLATE_OPTIONS } diff --git a/app/queries/billboards/filtered_ads_query.rb b/app/queries/billboards/filtered_ads_query.rb index df9d4ff1c..80cc6312a 100644 --- a/app/queries/billboards/filtered_ads_query.rb +++ b/app/queries/billboards/filtered_ads_query.rb @@ -9,13 +9,14 @@ module Billboards # @param user_signed_in [Boolean] whether or not the visitor is signed-in # @param billboards [Billboard] can be a filtered scope or Arel relationship # @param location [Geolocation|String] the visitor's geographic location - def initialize(area:, user_signed_in:, organization_id: nil, article_tags: [], + def initialize(area:, user_signed_in:, organization_id: nil, article_tags: [], page_id: nil, permit_adjacent_sponsors: true, article_id: nil, billboards: Billboard, user_id: nil, user_tags: nil, location: nil, cookies_allowed: false) @filtered_billboards = billboards.includes([:organization]) @area = area @user_signed_in = user_signed_in @user_id = user_signed_in ? user_id : nil + @page_id = page_id @organization_id = organization_id @article_tags = article_tags @article_id = article_id @@ -28,6 +29,7 @@ module Billboards def call @filtered_billboards = approved_and_published_ads @filtered_billboards = placement_area_ads + @filtered_billboards = page_ads if @page_id.present? @filtered_billboards = cookies_allowed_ads unless @cookies_allowed if @article_id.present? @@ -83,6 +85,10 @@ module Billboards @filtered_billboards.where(placement_area: @area) end + def page_ads + @filtered_billboards.where(page_id: @page_id) + end + def tagged_ads(tag_type) @filtered_billboards.cached_tagged_with_any(tag_type) end diff --git a/app/views/pages/show.en.html.erb b/app/views/pages/show.en.html.erb index 52f122524..6e18311bb 100644 --- a/app/views/pages/show.en.html.erb +++ b/app/views/pages/show.en.html.erb @@ -41,4 +41,5 @@ <%= @page.processed_html.html_safe %> <% end %> -
+ +<%= javascript_include_tag "billboard", defer: true %> diff --git a/app/views/pages/show.fr.html.erb b/app/views/pages/show.fr.html.erb index 52f122524..958bbdf6f 100644 --- a/app/views/pages/show.fr.html.erb +++ b/app/views/pages/show.fr.html.erb @@ -41,4 +41,4 @@ <%= @page.processed_html.html_safe %> <% end %> - + diff --git a/app/views/shared/_billboard.html.erb b/app/views/shared/_billboard.html.erb index 81517f918..0ebe7b298 100644 --- a/app/views/shared/_billboard.html.erb +++ b/app/views/shared/_billboard.html.erb @@ -57,7 +57,7 @@ <%= billboard.processed_html.html_safe %> -<% elsif billboard.placement_area == "post_fixed_bottom" %> +<% elsif billboard.placement_area == "post_fixed_bottom" || billboard.placement_area == "page_fixed_bottom" %>