docbrown/app/controllers/pages_controller.rb
Ali Spittel 52c60ce37e Feature/refactored onboarding (#3333)
* set up refactored onboarding

* create onboarding page

* add in first slide and change slide functionality

* fix test suite

* profile refactor

* profile refactor

* refactor to api

* add checkbox fields

* add checkbox fields

* remove puts

* add basic css

* add styling

* add redirect

* hide back and next at first and last slides

* test refactored onboarding

* test refactored onboarding

* remove article edits

* Fix schema

* Add deleted file back in

* Add default value for checked_t&c column

* Adjust HTML structure to keep nav buttons in place

* Fix ESLint issues on Onboarding.jsx file

* Handling for undefined or empty followedTags on getUserTags

* Fix codeclimate issues

* Fix codeclimate issues

* Fix more codeclimate issues

* Fix more codeclimate issues

* Update Onboarding snapshots

* Uncheck the CoC and T&C checkboxes on render

* Update snapshots

* Return false instead of raising error

* Update spec to use new onboarding

* Redirect to onboarding if haven't seen it yet

* Prevent redirect to onboarding from /signout_confirm

* Use assign_attributes instead of saving twice

* Move COC and T&C checkbox page to second slide

* Add 'go back to original page' functionality

* Reuse ready prototype logic

* Keep track of the last visited onboarding page

* Fix email subscription bug

* Fix overflow issue for tags page

* Remove height to prevent page container scrolling

* Check for CoC and T&C for displaying onboarding

* Add InstantClick redirect and preserve referrer in client

* Fix async update + check by using localStorage

* Turn off onboarding for tests

* Finalize design for onboarding

* Finalize design for onboarding

* Make bulk follows during onboarding

* Fix bulk follow test
2019-07-26 15:53:32 -04:00

116 lines
3.2 KiB
Ruby

class PagesController < ApplicationController
# No authorization required for entirely public controller
before_action :set_cache_control_headers, only: %i[show rlyweb now survey badge shecoded bounty faq]
def show
@page = Page.find_by!(slug: params[:slug])
set_surrogate_key_header "show-page-#{params[:slug]}"
end
def now
set_surrogate_key_header "now_page"
end
def survey
set_surrogate_key_header "survey_page"
end
def about
@page = Page.find_by(slug: "about")
render :show if @page
set_surrogate_key_header "about_page"
end
def faq
@page = Page.find_by(slug: "faq")
render :show if @page
set_surrogate_key_header "faq_page"
end
def bounty
@page = Page.find_by(slug: "security")
render :show if @page
set_surrogate_key_header "bounty_page"
end
def badge
@html_variant = HtmlVariant.find_for_test([], "badge_landing_page")
render layout: false
set_surrogate_key_header "badge_page"
end
def onboarding
set_surrogate_key_header "onboarding_page"
end
def report_abuse
reported_url = params[:reported_url] || params[:url] || request.referer
@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_thread("welcome")
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 challenge
daily_thread = latest_published_thread("challenge")
if daily_thread
redirect_to daily_thread.path
else
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.published.tagged_with(%w[shecoded shecodedally theycoded], any: true).
where(approved: true).where("published_at > ? AND score > ?", 3.weeks.ago, 28).
order(Arel.sql("RANDOM()")).
includes(:user).decorate
@articles = Article.published.tagged_with(%w[shecoded shecodedally theycoded], any: true).
where(approved: true).where("published_at > ? AND score > ?", 3.weeks.ago, -8).
order(Arel.sql("RANDOM()")).
where.not(id: @top_articles).
includes(:user).decorate
render layout: false
set_surrogate_key_header "shecoded_page"
end
private # helpers
def latest_published_thread(tag_name)
Article.published.
where(user_id: ApplicationConfig["DEVTO_USER_ID"]).
order("published_at ASC").
tagged_with(tag_name).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