docbrown/app/controllers/pages_controller.rb
Keshav Biswa 8d57d45ecc Rubocop Style cops enabled (#2056)
* Rubocop enabled style/alias

* Enabled Style/ArrayJoin Cop

* Enabled Style/Attr

* Enabled Case Equality

* Enabled CharacterLiteral

*  Enabled ColonMethodCall Cop

* Enabled CommentAnnotation cop

* Enabled PreferredHashMethods Cop

*  Enabled DoubleNegation Cop

* Enabled EachWithObject Cop

* Enabled EmptyLiteral Cop

* Enabled EvenOdd Cop

* Enabled IfWithSemicolon Cop

* Enabled Lambda and LambdaCall Cop

* Enabled LineEndConcatenation Cop

* Enabled ModuleFunction Cop;

* Enable NegatedIf and NegatedWhile Cop

* Enabled NilComparison Cop

* Enabled Not Cop

* Enabled NumericLiterals Cop

* Enabled OneLineConditional Cop

* Enabled PercentLiteralDelimiters Cop

* Excluded internal/users_controller from negated_if cop

* Reverted the double negation change from github_issue_tag and github_issue.rb"

* Enabled PerlBackrefs Cop

* Changed Regexp.last_match(1) to Regexp.last_match(0)

* Enabled proc cop

* Enabled RaiseArgs Cop

* Reverted Regexp.last_match(0) to Regexp.last_match(1)

* Enabled SelfAssignment Cop

* Enabled SingleLineMethods Cop

* Enabled SpecialGlobalVars Cop

* Enabled VariableInterpolation Cop

* Enabled WhenThen Cop

* Enabled WhileUntilModifier Cop

* Enabled WordArray Cop

* Enabled IfUnlessModifier Cop

* Enabled GuardClause Cop
2019-03-15 18:33:54 -04:00

91 lines
2.7 KiB
Ruby

class PagesController < ApplicationController
# No authorization required for entirely public controller
before_action :set_cache_control_headers, only: %i[rlyweb now events membership survey badge shecoded]
def now
set_surrogate_key_header "now_page"
end
def survey
set_surrogate_key_header "survey_page"
end
def about
set_surrogate_key_header "about_page"
end
def badge
@html_variant = HtmlVariant.find_for_test([], "badge_landing_page")
render layout: false
set_surrogate_key_header "badge_page"
end
def membership
flash[:notice] = ""
flash[:error] = ""
@members = members_for_display
set_surrogate_key_header "membership_page"
end
def membership_form
render "membership_form", layout: false
end
def report_abuse
reported_url = params[:reported_url] || params[:url] || request.referrer
@feedback_message = FeedbackMessage.new(
reported_url: reported_url&.chomp("?i=i"),
)
render "pages/report-abuse"
end
def rlyweb
set_surrogate_key_header "rlyweb"
end
def welcome
daily_thread = latest_published_welcome_thread
if daily_thread
redirect_to daily_thread.path
else
# fail safe if we haven't made the first welcome thread
redirect_to "/notifications"
end
end
def live
@active_channel = ChatChannel.find_by_channel_name("Workshop")
@chat_channels = [@active_channel].to_json(
only: %i[channel_name channel_type last_message_at slug status id],
)
end
def shecoded
@top_articles = Article.tagged_with(%w[shecoded shecodedally theycoded], any: true).
where(published: true, approved: true).where("published_at > ? AND score > ?", 3.weeks.ago, 28).order("RANDOM()").
includes(:user).decorate
@articles = Article.tagged_with(%w[shecoded shecodedally theycoded], any: true).
where(published: true, approved: true).where("published_at > ? AND score > ?", 3.weeks.ago, -8).order("RANDOM()").
where.not(id: @top_articles.pluck(:id)).
includes(:user).decorate
render layout: false
set_surrogate_key_header "shecoded_page"
end
private # helpers
def latest_published_welcome_thread
Article.where(user_id: ApplicationConfig["DEVTO_USER_ID"], published: true).
tagged_with("welcome").last
end
def members_for_display
Rails.cache.fetch("members-for-display-on-membership-page", expires_in: 6.hours) do
roles = %i[level_1_member level_2_member level_3_member level_4_member triple_unicorn_member
workshop_pass]
members = User.select(:id, :username, :profile_image).with_any_role(*roles)
team_ids = [1, 264, 6, 3, 31_047, 510, 560, 1075, 48_943, 13_962]
members.reject { |user| team_ids.include?(user.id) }.shuffle
end
end
end