Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add role targeting to billboards #21270

Merged
merged 5 commits into from
Sep 9, 2024
Merged

Conversation

benhalpern
Copy link
Contributor

@benhalpern benhalpern commented Sep 9, 2024

What type of PR is this? (check all applicable)

  • Refactor
  • Feature
  • Bug Fix
  • Optimization
  • Documentation Update

Description

Adds the ability to filter billboards by user's roles.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 [rubocop] <Metrics/CyclomaticComplexity> reported by reviewdog 🐶
Cyclomatic complexity for call is too high. [14/13]

def call
@filtered_billboards = approved_and_published_ads
@filtered_billboards = placement_area_ads
@filtered_billboards = browser_context_ads if @user_agent.present?
@filtered_billboards = page_ads if @page_id.present?
@filtered_billboards = cookies_allowed_ads unless @cookies_allowed
if @article_id.present?
if @article_tags.any?
@filtered_billboards = tagged_ads(@article_tags).or(untagged_ads)
end
if @article_tags.blank?
@filtered_billboards = untagged_ads
end
@filtered_billboards = unexcluded_article_ads
end
if @user_tags.present? && @user_tags.any?
@filtered_billboards = tagged_ads(@user_tags).or(untagged_ads)
end
# We apply the condition feed_targeted_tag_placement? because we only want to filter by
# untagged ads on the home feed area placements. We do not want to have any side effects happen
# on the article page or anywhere else.
if @user_tags.blank? && feed_targeted_tag_placement?(@area)
@filtered_billboards = untagged_ads
end
@filtered_billboards = user_targeting_ads
@filtered_billboards = role_filtered_ads if @user_signed_in
@filtered_billboards = if @user_signed_in
authenticated_ads(%w[all logged_in])
else
authenticated_ads(%w[all logged_out])
end
if FeatureFlag.enabled?(Geolocation::FEATURE_FLAG)
@filtered_billboards = location_targeted_ads
end
# type_of filter needs to be applied as near to the end as possible
# as it checks if any type-matching ads exist (this will apply all/any
# filters applied up to this point, thus near the end is best)
@filtered_billboards = type_of_ads
@filtered_billboards = @filtered_billboards.order(success_rate: :desc)
end

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 [rubocop] <Metrics/PerceivedComplexity> reported by reviewdog 🐶
Perceived complexity for call is too high. [15/14]

def call
@filtered_billboards = approved_and_published_ads
@filtered_billboards = placement_area_ads
@filtered_billboards = browser_context_ads if @user_agent.present?
@filtered_billboards = page_ads if @page_id.present?
@filtered_billboards = cookies_allowed_ads unless @cookies_allowed
if @article_id.present?
if @article_tags.any?
@filtered_billboards = tagged_ads(@article_tags).or(untagged_ads)
end
if @article_tags.blank?
@filtered_billboards = untagged_ads
end
@filtered_billboards = unexcluded_article_ads
end
if @user_tags.present? && @user_tags.any?
@filtered_billboards = tagged_ads(@user_tags).or(untagged_ads)
end
# We apply the condition feed_targeted_tag_placement? because we only want to filter by
# untagged ads on the home feed area placements. We do not want to have any side effects happen
# on the article page or anywhere else.
if @user_tags.blank? && feed_targeted_tag_placement?(@area)
@filtered_billboards = untagged_ads
end
@filtered_billboards = user_targeting_ads
@filtered_billboards = role_filtered_ads if @user_signed_in
@filtered_billboards = if @user_signed_in
authenticated_ads(%w[all logged_in])
else
authenticated_ads(%w[all logged_out])
end
if FeatureFlag.enabled?(Geolocation::FEATURE_FLAG)
@filtered_billboards = location_targeted_ads
end
# type_of filter needs to be applied as near to the end as possible
# as it checks if any type-matching ads exist (this will apply all/any
# filters applied up to this point, thus near the end is best)
@filtered_billboards = type_of_ads
@filtered_billboards = @filtered_billboards.order(success_rate: :desc)
end

Copy link
Contributor

github-actions bot commented Sep 9, 2024

Uffizzi Preview deployment-56053 was deleted.

@benhalpern benhalpern marked this pull request as ready for review September 9, 2024 20:04
@benhalpern benhalpern requested review from a team as code owners September 9, 2024 20:04
@benhalpern benhalpern merged commit 466de28 into main Sep 9, 2024
26 of 31 checks passed
@benhalpern benhalpern deleted the ben/add-role-names-to-billboards branch September 9, 2024 20:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant