Initial statement of intent regarding Listings (#16335)
* Initial statement of intent regarding Listings I want to use this pull request as a means of conveying intended direction; namely that we want Forem administrators to be able to toggle off (or on) the Listing feature set. This refactor is a first, yet incomplete pass, that doesn't make the code worse. Expect more of a similar vein as we work to put the Listing feature set behind a feature flag. Related https://github.com/forem/rfcs/issues/291 * Adding feature flag based on reviewer comment
This commit is contained in:
parent
077ce36fb4
commit
77d9640e3e
4 changed files with 46 additions and 21 deletions
|
|
@ -40,6 +40,24 @@ class Listing < ApplicationRecord
|
|||
|
||||
delegate :cost, to: :listing_category
|
||||
|
||||
# As part of making listings "optional", this is the current place to go for the answer "Is the
|
||||
# Listing feature enabled?" This approach will get us quite far, at least up until we flip this
|
||||
# into a plugin (e.g. we won't be able to guarantee that we have the constant :Listing in the Ruby
|
||||
# object space).
|
||||
#
|
||||
# @note As of <2022-01-28 Fri>, the assumption is that everyone will have this feature enabled.
|
||||
# In part because marking this feature as disabled won't yet properly disable all aspects of
|
||||
# the feature.
|
||||
#
|
||||
# @see https://github.com/forem/rfcs/issues/291 for discussion and rollout strategy
|
||||
# @see FeatureFlag.accessible?
|
||||
#
|
||||
# @return [TrueClass] if the Listing is enabled for this Forem
|
||||
# @return [FalseClass] if the Listing is disabled for this Forem
|
||||
def self.feature_enabled?
|
||||
FeatureFlag.accessible?(:listing_feature_enabled)
|
||||
end
|
||||
|
||||
# Wrapping the column accessor names for consistency. Aliasing did not work.
|
||||
def listing_category_id
|
||||
classified_listing_category_id
|
||||
|
|
|
|||
21
app/views/articles/_sidebar_listings.html.erb
Normal file
21
app/views/articles/_sidebar_listings.html.erb
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
<% @listings = Listing.where(published: true).select(:title, :classified_listing_category_id, :slug, :bumped_at) %>
|
||||
<% if params[:timeframe].blank? && @listings.any? %>
|
||||
<section class="crayons-card crayons-card--secondary">
|
||||
<header class="crayons-card__header">
|
||||
<h3 class="crayons-subtitle-2"><%= t("views.main.side.listings.heading") %></h3>
|
||||
<div class="crayons-card__actions">
|
||||
<a href="/listings" class="crayons-link--branded fw-medium fs-s"><%= t("views.main.side.listings.all") %></a>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<div>
|
||||
<% @listings.order(bumped_at: :desc).limit(5).each do |listing| %>
|
||||
<a class="crayons-link crayons-link--contentful" href="<%= listing.path %>">
|
||||
<div><%= listing.title %></div>
|
||||
<div class="crayons-link__secondary"><%= listing.category %></div>
|
||||
</a>
|
||||
<% end %>
|
||||
<a class="crayons-link crayons-link--branded block align-center p-3 fw-medium fs-s w-100" href="/listings/new"><%= t("views.main.side.listings.new") %></a>
|
||||
</div>
|
||||
</section>
|
||||
<% end %>
|
||||
|
|
@ -8,27 +8,7 @@
|
|||
<% end %>
|
||||
|
||||
<%= render "articles/sidebar_campaign" if Campaign.current.show_in_sidebar? %>
|
||||
<% @listings = Listing.where(published: true).select(:title, :classified_listing_category_id, :slug, :bumped_at) %>
|
||||
<% if params[:timeframe].blank? && @listings.any? %>
|
||||
<section class="crayons-card crayons-card--secondary">
|
||||
<header class="crayons-card__header">
|
||||
<h3 class="crayons-subtitle-2"><%= t("views.main.side.listings.heading") %></h3>
|
||||
<div class="crayons-card__actions">
|
||||
<a href="/listings" class="crayons-link--branded fw-medium fs-s"><%= t("views.main.side.listings.all") %></a>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<div>
|
||||
<% @listings.order(bumped_at: :desc).limit(5).each do |listing| %>
|
||||
<a class="crayons-link crayons-link--contentful" href="<%= listing.path %>">
|
||||
<div><%= listing.title %></div>
|
||||
<div class="crayons-link__secondary"><%= listing.category %></div>
|
||||
</a>
|
||||
<% end %>
|
||||
<a class="crayons-link crayons-link--branded block align-center p-3 fw-medium fs-s w-100" href="/listings/new"><%= t("views.main.side.listings.new") %></a>
|
||||
</div>
|
||||
</section>
|
||||
<% end %>
|
||||
<%= render "articles/sidebar_listings" if Listing.feature_enabled? %>
|
||||
|
||||
<% Settings::General.sidebar_tags.each do |tag| %>
|
||||
<section class="crayons-card crayons-card--secondary">
|
||||
|
|
|
|||
|
|
@ -9,6 +9,12 @@ RSpec.describe Listing, type: :model do
|
|||
# This may apply default parser on area that should not use it.
|
||||
after { ActsAsTaggableOn.default_parser = ActsAsTaggableOn::DefaultParser }
|
||||
|
||||
describe "class methods" do
|
||||
subject(:klass) { described_class }
|
||||
|
||||
it { is_expected.to respond_to(:feature_enabled?) }
|
||||
end
|
||||
|
||||
it { is_expected.to validate_presence_of(:title) }
|
||||
it { is_expected.to validate_presence_of(:body_markdown) }
|
||||
it { is_expected.to have_many(:credits) }
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue