docbrown/app/controllers/admin/articles_controller.rb
Rajat Talesra bbb9fd2e1e
Add more visibility to admins (part-2) (#19375)
* Basic thumbsup, thumbsdown and vomit

* Refined UI of flags and vomits

* If check

* Optimised code and added a method in article.rb

* Removed public keyword

* Nit fixes

* Section for flags and quality details

* Basic vomit item

* Quality item UI

* Separated code into partials

* UI changes and empty state added

* With correct implementation

* Fixed showing reaction items in all cases

* Dropdown visible

* Enabled click listerners and call functions for dropdown-button clicks

* Empty state UI fixed

* Tabs and divider UI

* Mark as valid/invalid conditions

* Nit fixes

* Logical fixes

* Added comments

* Partial item status update fix

* Reload page feature fixed

* Removed snackbar

* I18n strings

* Bug fix

* I18n strings

* Nit fixes

* Added date

* Added view details button

* Added view details test

* Sample test

* Test fixes

* Added tests for new article

* Flagged item tests added

* Added more tests

* Nit fix

* Suggested design changes

* Nit design fixes

* Tests with cy.intercept

* Nit fixes

* Nit fixes

* Hero Billboard Placement (#19467)

* init

* add option to swagger docs

* in_house validation

* filtered ad quesry changes

* styling and prioritizing home hero banner over campaign banner

* rubocop

* typo

* broken spec

* more spec fixes

* found the spec break culprit

* derp

* Update app/views/shared/_display_ad.html.erb

Co-authored-by: Ridhwana <Ridhwana.Khan16@gmail.com>

* Update app/controllers/stories_controller.rb

Co-authored-by: Ridhwana <Ridhwana.Khan16@gmail.com>

* remove immediate return

* styling feedback and moving banner to articles index

* remove nil

* updated styling

* add signed in bool

* add feature flag

* remove feature flag data scripts

---------

Co-authored-by: Ridhwana <Ridhwana.Khan16@gmail.com>

* Fix typo / erroneous word in Admin Section (#19488)

* Typo fixes

* Update admin_menu.rb

* Minor background and shadow change (#19501)

* Refresh audience segment for 'active' user (#19470)

* Refresh an individual user's segmentation

* Refresh segment if creating a published article

* Quick refactor

* Refresh segment if update publishing

* Quick refactor

* Refresh segment if update user settings

* Refresh segments after user update + role change

* Using latest_article_updated_at

* Sidekiq uses JSON for arguments, needs basic types

* Fix test issues with last_updated_at and sidekiq params

* Tests update continues

* Consolidate dependencies

* Method names acknowledging manual exclusive

* Fix test name copypasta

* Rubocop

* Try to clarify Creator#series

* Try to avoid naming predicate

* Remove erroneously included helper

* Improve onboarding “suggested tags” page design (#19475)

* Onboarding tags

* Logical design issue fixes

* Posts count added

* Checkbox design fixes

* Optimised css

* Nit fixes

* Test case added

* Reduced data

* Nit fix

* Added more tests

* Nit fix

* Tests updatedt

* Update @honeybadger-io/js to version 5.4.1 (#19479)

Co-authored-by: depfu[bot] <23717796+depfu[bot]@users.noreply.github.com>

* Update sidekiq-cron to version 1.10.1 (#19473)

Co-authored-by: depfu[bot] <23717796+depfu[bot]@users.noreply.github.com>

* Update nokogiri to version 1.15.0 (#19495)

Co-authored-by: depfu[bot] <23717796+depfu[bot]@users.noreply.github.com>

* use tabindex instead of disabled to get proper keyboard nav on /onboarding tags (#19513)

* Add billboard to safe param list in Fastly vcl (#19515)

* Removed static article id from setup

* All tests passing

* Nit fixes

* Nit fixes

* Fixed tests with Joshua's help

* Added trusted user related tests

* Fixed few tests

* Added intercept and wait

* Removed tab and enter key

* Updated comment

* Updated tests

---------

Co-authored-by: Lawrence <lawrence@forem.com>
Co-authored-by: Ridhwana <Ridhwana.Khan16@gmail.com>
Co-authored-by: Peter Frank <peter.kim.frank@gmail.com>
Co-authored-by: Joshua Wehner <joshua@forem.com>
Co-authored-by: depfu[bot] <23717796+depfu[bot]@users.noreply.github.com>
Co-authored-by: Ben Halpern <bendhalpern@gmail.com>
2023-05-26 19:15:12 +05:30

130 lines
3.5 KiB
Ruby

module Admin
class ArticlesController < Admin::ApplicationController
layout "admin"
after_action only: %i[update unpin] do
Audit::Logger.log(:moderator, current_user, params.dup)
end
ARTICLES_ALLOWED_PARAMS = %i[featured
social_image
body_markdown
approved
email_digest_eligible
main_image_background_hex_color
user_id
co_author_ids_list
published_at].freeze
def index
case params[:state]
when /top-/
months_ago = params[:state].split("-")[1].to_i.months.ago
@articles = articles_top(months_ago)
when "chronological"
@articles = articles_chronological
else
@articles = articles_mixed
@featured_articles = articles_featured
end
@pinned_article = PinnedArticle.get
@articles = @articles.where.not(id: @pinned_article) if @pinned_article
end
def show
@article = Article.includes(reactions: :user).find(params[:id])
end
def update
article = Article.find(params[:id])
if article.update(article_params.merge(admin_update: true))
flash[:success] = I18n.t("admin.articles_controller.saved")
else
flash[:danger] = article.errors_as_sentence
end
redirect_to admin_article_path(article.id)
end
def unpin
article = Article.find(params[:id])
PinnedArticle.remove
respond_to do |format|
format.html do
flash[:danger] = I18n.t("admin.articles_controller.unpinned")
redirect_to admin_article_path(article.id)
end
format.js do
render partial: "admin/articles/article_item", locals: { article: article }, content_type: "text/html"
end
end
end
def pin
article = Article.find(params[:id])
PinnedArticle.set(article)
respond_to do |format|
format.html do
flash[:success] = I18n.t("admin.articles_controller.pinned")
redirect_to admin_article_path(article.id)
end
format.js do
render partial: "admin/articles/article_item", locals: { article: article }, content_type: "text/html"
end
end
end
private
def articles_top(months_ago)
Article.published
.where("published_at > ?", months_ago)
.includes(user: [:notes])
.limited_columns_internal_select
.order(public_reactions_count: :desc)
.page(params[:page])
.per(50)
end
def articles_chronological
Article.published
.includes(user: [:notes])
.limited_columns_internal_select
.order(published_at: :desc)
.page(params[:page])
.per(50)
end
def articles_mixed
Article.published
.includes(user: [:notes])
.limited_columns_internal_select
.order(hotness_score: :desc)
.page(params[:page])
.per(30)
end
def articles_featured
Article.published.or(Article.where(published_from_feed: true))
.featured
.where("published_at > ?", Time.current)
.includes(:user)
.limited_columns_internal_select
.order(published_at: :desc)
end
def article_params
params.require(:article).permit(ARTICLES_ALLOWED_PARAMS)
end
def authorize_admin
authorize Article, :access?, policy_class: InternalPolicy
end
end
end