mirror of
https://github.com/discourse/discourse.git
synced 2025-05-22 16:41:17 +08:00
UX: add a route /rules as an alias for /faq and /guidelines
This commit is contained in:
@ -12,7 +12,9 @@ class StaticController < ApplicationController
|
|||||||
|
|
||||||
def show
|
def show
|
||||||
return redirect_to(path '/') if current_user && (params[:id] == 'login' || params[:id] == 'signup')
|
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 = {
|
map = {
|
||||||
"faq" => { redirect: "faq_url", topic_id: "guidelines_topic_id" },
|
"faq" => { redirect: "faq_url", topic_id: "guidelines_topic_id" },
|
||||||
@ -29,7 +31,7 @@ class StaticController < ApplicationController
|
|||||||
end
|
end
|
||||||
|
|
||||||
# The /guidelines route ALWAYS shows our FAQ, ignoring the faq_url site setting.
|
# 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
|
# Don't allow paths like ".." or "/" or anything hacky like that
|
||||||
@page.gsub!(/[^a-z0-9\_\-]/, '')
|
@page.gsub!(/[^a-z0-9\_\-]/, '')
|
||||||
|
@ -328,6 +328,7 @@ Discourse::Application.routes.draw do
|
|||||||
get "password-reset" => "static#show", id: "password_reset", constraints: { format: /(json|html)/ }
|
get "password-reset" => "static#show", id: "password_reset", constraints: { format: /(json|html)/ }
|
||||||
get "faq" => "static#show", id: "faq", 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 "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 "tos" => "static#show", id: "tos", as: 'tos', constraints: { format: /(json|html)/ }
|
||||||
get "privacy" => "static#show", id: "privacy", as: 'privacy', 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)/ }
|
get "signup" => "static#show", id: "signup", constraints: { format: /(json|html)/ }
|
||||||
|
@ -162,35 +162,30 @@ describe StaticController do
|
|||||||
SiteSetting.login_required = true
|
SiteSetting.login_required = true
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'faq page redirects to login page for anon' do
|
['faq', 'guidelines', 'rules'].each do |page_name|
|
||||||
get '/faq'
|
it "#{page_name} page redirects to login page for anon" do
|
||||||
|
get "/#{page_name}"
|
||||||
expect(response).to redirect_to '/login'
|
expect(response).to redirect_to '/login'
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'guidelines page redirects to login page for anon' do
|
it "#{page_name} page redirects to login page for anon" do
|
||||||
get '/guidelines'
|
get "/#{page_name}"
|
||||||
expect(response).to redirect_to '/login'
|
expect(response).to redirect_to '/login'
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'faq page loads for logged in user' do
|
|
||||||
sign_in(Fabricate(:user))
|
|
||||||
|
|
||||||
get '/faq'
|
|
||||||
|
|
||||||
expect(response.status).to eq(200)
|
|
||||||
expect(response.body).to include(I18n.t('js.faq'))
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'guidelines page loads for logged in user' do
|
['faq', 'guidelines', 'rules'].each do |page_name|
|
||||||
|
it "#{page_name} page loads for logged in user" do
|
||||||
sign_in(Fabricate(:user))
|
sign_in(Fabricate(:user))
|
||||||
|
|
||||||
get '/guidelines'
|
get "/#{page_name}"
|
||||||
|
|
||||||
expect(response.status).to eq(200)
|
expect(response.status).to eq(200)
|
||||||
expect(response.body).to include(I18n.t('guidelines'))
|
expect(response.body).to include(I18n.t('guidelines'))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
describe '#enter' do
|
describe '#enter' do
|
||||||
context 'without a redirect path' do
|
context 'without a redirect path' do
|
||||||
|
Reference in New Issue
Block a user