UX: add a route /rules as an alias for /faq and /guidelines

This commit is contained in:
Neil Lalonde 2018-07-26 15:37:56 -04:00
parent 56ae826efb
commit 1708ff1808
3 changed files with 22 additions and 24 deletions

View File

@ -12,7 +12,9 @@ class StaticController < ApplicationController
def show
return redirect_to(path '/') if current_user && (params[:id] == 'login' || params[:id] == 'signup')
return redirect_to path('/login') if SiteSetting.login_required? && current_user.nil? && (params[:id] == 'faq' || params[:id] == 'guidelines')
if SiteSetting.login_required? && current_user.nil? && ['faq', 'guidelines', 'rules'].include?(params[:id])
return redirect_to path('/login')
end
map = {
"faq" => { redirect: "faq_url", topic_id: "guidelines_topic_id" },
@ -29,7 +31,7 @@ class StaticController < ApplicationController
end
# The /guidelines route ALWAYS shows our FAQ, ignoring the faq_url site setting.
@page = 'faq' if @page == 'guidelines'
@page = 'faq' if @page == 'guidelines' || @page == 'rules'
# Don't allow paths like ".." or "/" or anything hacky like that
@page.gsub!(/[^a-z0-9\_\-]/, '')

View File

@ -328,6 +328,7 @@ Discourse::Application.routes.draw do
get "password-reset" => "static#show", id: "password_reset", constraints: { format: /(json|html)/ }
get "faq" => "static#show", id: "faq", constraints: { format: /(json|html)/ }
get "guidelines" => "static#show", id: "guidelines", as: 'guidelines', constraints: { format: /(json|html)/ }
get "rules" => "static#show", id: "rules", as: 'rules', constraints: { format: /(json|html)/ }
get "tos" => "static#show", id: "tos", as: 'tos', constraints: { format: /(json|html)/ }
get "privacy" => "static#show", id: "privacy", as: 'privacy', constraints: { format: /(json|html)/ }
get "signup" => "static#show", id: "signup", constraints: { format: /(json|html)/ }

View File

@ -162,32 +162,27 @@ describe StaticController do
SiteSetting.login_required = true
end
it 'faq page redirects to login page for anon' do
get '/faq'
expect(response).to redirect_to '/login'
['faq', 'guidelines', 'rules'].each do |page_name|
it "#{page_name} page redirects to login page for anon" do
get "/#{page_name}"
expect(response).to redirect_to '/login'
end
it "#{page_name} page redirects to login page for anon" do
get "/#{page_name}"
expect(response).to redirect_to '/login'
end
end
it 'guidelines page redirects to login page for anon' do
get '/guidelines'
expect(response).to redirect_to '/login'
end
['faq', 'guidelines', 'rules'].each do |page_name|
it "#{page_name} page loads for logged in user" do
sign_in(Fabricate(:user))
it 'faq page loads for logged in user' do
sign_in(Fabricate(:user))
get "/#{page_name}"
get '/faq'
expect(response.status).to eq(200)
expect(response.body).to include(I18n.t('js.faq'))
end
it 'guidelines page loads for logged in user' do
sign_in(Fabricate(:user))
get '/guidelines'
expect(response.status).to eq(200)
expect(response.body).to include(I18n.t('guidelines'))
expect(response.status).to eq(200)
expect(response.body).to include(I18n.t('guidelines'))
end
end
end
end