* Initial automatic cleanup with rubocop * Fix syntax error introduced by rubocop * Cleanup seeds file * Cleanup lib folder * Exclude bin folder because it contains auto generated files * Make Rubocop a little bit more chatty * Block length should not include comments in the count * Cleanup config folder * Cleanup specs * Updated Rubocop version and generated a todo file * Fix broken ArticlesApi spec * Fix tests * Restored rubocop pre-commit hook
145 lines
4.7 KiB
Ruby
145 lines
4.7 KiB
Ruby
class Internal::ArticlesController < Internal::ApplicationController
|
|
layout "internal"
|
|
|
|
def index
|
|
case params[:state]
|
|
|
|
when "by-featured-number"
|
|
@articles = Article.
|
|
where(published: true).
|
|
includes(:user).
|
|
order("featured_number DESC").
|
|
page(params[:page]).
|
|
limited_columns_internal_select.
|
|
per(50)
|
|
when "unfeatured-by-published"
|
|
@articles = Article.
|
|
where(featured: false, published: true).
|
|
includes(:user).
|
|
order("published_at DESC").
|
|
page(params[:page]).
|
|
limited_columns_internal_select.
|
|
per(50)
|
|
when "rss"
|
|
@articles = Article.
|
|
where(published_from_feed: true).
|
|
includes(:user).
|
|
order("created_at DESC").
|
|
page(params[:page]).
|
|
limited_columns_internal_select.
|
|
per(50)
|
|
when "rss-recent"
|
|
@articles = Article.
|
|
where(published_from_feed: true).
|
|
includes(:user).
|
|
order("published_at DESC").
|
|
page(params[:page]).
|
|
limited_columns_internal_select.
|
|
per(50)
|
|
when "spam"
|
|
@articles = Article.
|
|
where(published: true).
|
|
where("spaminess_rating > ?", 10).
|
|
includes(:user).
|
|
order("published_at DESC").
|
|
page(params[:page]).
|
|
limited_columns_internal_select.
|
|
per(50)
|
|
when /top\-/
|
|
@articles = Article.
|
|
where("published_at > ?", params[:state].split("-")[1].to_i.months.ago).
|
|
includes(:user).
|
|
order("positive_reactions_count DESC").
|
|
page(params[:page]).
|
|
limited_columns_internal_select.
|
|
per(50)
|
|
when "classic-candidate"
|
|
@articles = Article.where("positive_reactions_count > ?",
|
|
Suggester::Articles::Classic::MIN_REACTION_COUNT).
|
|
includes(:user).
|
|
order("positive_reactions_count DESC").
|
|
where(featured: false).
|
|
page(params[:page]).
|
|
per(100).
|
|
limited_columns_internal_select
|
|
when "classic"
|
|
@articles = Article.where("positive_reactions_count > ?",
|
|
Suggester::Articles::Classic::MIN_REACTION_COUNT).
|
|
includes(:user).
|
|
order("positive_reactions_count DESC").
|
|
where(featured: true).
|
|
page(params[:page]).
|
|
per(100).
|
|
limited_columns_internal_select
|
|
when "boosted-additional-articles"
|
|
@articles = Article.
|
|
includes(:user).
|
|
order("published_at DESC").
|
|
boosted_via_additional_articles.
|
|
page(params[:page]).
|
|
per(100).
|
|
limited_columns_internal_select
|
|
when "boosted-dev-digest"
|
|
@articles = Article.
|
|
includes(:user).
|
|
order("published_at DESC").
|
|
boosted_via_dev_digest_email.
|
|
page(params[:page]).
|
|
per(100).
|
|
limited_columns_internal_select
|
|
else # MIX
|
|
@articles = Article.
|
|
where(published: true).
|
|
order("published_at DESC").
|
|
page(params[:page]).
|
|
limited_columns_internal_select.
|
|
per(50)
|
|
|
|
@featured_articles = Article.
|
|
where(published: true).
|
|
or(Article.where(published_from_feed: true)).
|
|
where(featured: true).
|
|
where("featured_number > ?", Time.now.to_i).
|
|
includes(:user).
|
|
limited_columns_internal_select.
|
|
order("featured_number DESC")
|
|
end
|
|
end
|
|
|
|
def show
|
|
@article = Article.find(params[:id])
|
|
end
|
|
|
|
def update
|
|
article = Article.find(params[:id])
|
|
article.featured = article_params[:featured].to_s == "true"
|
|
article.approved = article_params[:approved].to_s == "true"
|
|
article.live_now = article_params[:live_now].to_s == "true"
|
|
article.email_digest_eligible = article_params[:email_digest_eligible].to_s == "true"
|
|
article.boosted_additional_articles = article_params[:boosted_additional_articles].to_s == "true"
|
|
article.boosted_dev_digest_email = article_params[:boosted_dev_digest_email].to_s == "true"
|
|
article.update!(article_params)
|
|
if article.live_now
|
|
Article.where.not(id: article.id).where(live_now: true).update_all(live_now: false)
|
|
end
|
|
CacheBuster.new.bust "/live_articles"
|
|
# raise
|
|
render body: nil
|
|
# redirect_to "/internal/articles"
|
|
end
|
|
|
|
private
|
|
|
|
def article_params
|
|
params.require(:article).permit(:featured,
|
|
:social_image,
|
|
:body_markdown,
|
|
:approved,
|
|
:live_now,
|
|
:email_digest_eligible,
|
|
:boosted_additional_articles,
|
|
:boosted_dev_digest_email,
|
|
:main_image_background_hex_color,
|
|
:featured_number)
|
|
end
|
|
end
|