FEATURE: add redirect_users_to_top_page site setting (default to true)

This commit is contained in:
Régis Hanol 2014-03-31 21:53:38 +02:00
parent 7baa8ea0af
commit ef24a4c71c
4 changed files with 45 additions and 31 deletions

View File

@ -560,6 +560,8 @@ class User < ActiveRecord::Base
end end
def redirected_to_top_reason def redirected_to_top_reason
# redirect is enabled
return unless SiteSetting.redirect_users_to_top_page
# top must be in the top_menu # top must be in the top_menu
return unless SiteSetting.top_menu =~ /top/i return unless SiteSetting.top_menu =~ /top/i
# there should be enough topics # there should be enough topics

View File

@ -665,6 +665,7 @@ en:
topics_per_period_in_top_summary: "How many topics loaded on the top topics summary" topics_per_period_in_top_summary: "How many topics loaded on the top topics summary"
topics_per_period_in_top_page: "How many topics loaded on the top topics page" topics_per_period_in_top_page: "How many topics loaded on the top topics page"
redirect_users_to_top_page: "Automatically redirect new & long-time-no-see users to top page"
redirect_new_users_to_top_page_duration: "Number of days during which new users are automatically redirect to the top page" redirect_new_users_to_top_page_duration: "Number of days during which new users are automatically redirect to the top page"
enable_badges: "Enable the badge system (experimental)" enable_badges: "Enable the badge system (experimental)"

View File

@ -148,6 +148,7 @@ users:
client: true client: true
default: 60 default: 60
delete_all_posts_max: 15 delete_all_posts_max: 15
redirect_users_to_top_page: true
posting: posting:
min_post_length: min_post_length:

View File

@ -1093,48 +1093,58 @@ describe User do
describe "redirected_to_top_reason" do describe "redirected_to_top_reason" do
let!(:user) { Fabricate(:user) } let!(:user) { Fabricate(:user) }
it "should have no reason when top is not in the top_menu" do it "should have no reason when redirect_users_to_top_page is disabled" do
SiteSetting.expects(:top_menu).returns("latest") SiteSetting.expects(:redirect_users_to_top_page).returns(false)
user.redirected_to_top_reason.should == nil user.redirected_to_top_reason.should == nil
end end
it "should have no reason when there isn't enough topics" do context "redirect_users_to_top_page is enabled" do
SiteSetting.expects(:top_menu).returns("latest|top") before { SiteSetting.stubs(:redirect_users_to_top_page).returns(true) }
SiteSetting.expects(:has_enough_topics_to_redirect_to_top).returns(false)
user.redirected_to_top_reason.should == nil
end
describe "new users" do it "should have no reason when top is not in the top_menu" do
before do SiteSetting.expects(:top_menu).returns("latest")
user.expects(:trust_level).returns(0)
user.stubs(:last_seen_at).returns(1.day.ago)
SiteSetting.expects(:top_menu).returns("latest|top")
SiteSetting.expects(:has_enough_topics_to_redirect_to_top).returns(true)
SiteSetting.expects(:redirect_new_users_to_top_page_duration).returns(7)
end
it "should have a reason for newly created user" do
user.expects(:created_at).returns(5.days.ago)
user.redirected_to_top_reason.should == I18n.t('redirected_to_top_reasons.new_user')
end
it "should not have a reason for newly created user" do
user.expects(:created_at).returns(10.days.ago)
user.redirected_to_top_reason.should == nil user.redirected_to_top_reason.should == nil
end end
end
describe "old users" do it "should have no reason when there isn't enough topics" do
before do
user.stubs(:trust_level).returns(1)
SiteSetting.expects(:top_menu).returns("latest|top") SiteSetting.expects(:top_menu).returns("latest|top")
SiteSetting.expects(:has_enough_topics_to_redirect_to_top).returns(true) SiteSetting.expects(:has_enough_topics_to_redirect_to_top).returns(false)
user.redirected_to_top_reason.should == nil
end end
it "should have a reason for long-time-no-see users" do describe "new users" do
user.last_seen_at = 2.months.ago before do
user.redirected_to_top_reason.should == I18n.t('redirected_to_top_reasons.not_seen_in_a_month') user.expects(:trust_level).returns(0)
user.stubs(:last_seen_at).returns(1.day.ago)
SiteSetting.expects(:top_menu).returns("latest|top")
SiteSetting.expects(:has_enough_topics_to_redirect_to_top).returns(true)
SiteSetting.expects(:redirect_new_users_to_top_page_duration).returns(7)
end
it "should have a reason for newly created user" do
user.expects(:created_at).returns(5.days.ago)
user.redirected_to_top_reason.should == I18n.t('redirected_to_top_reasons.new_user')
end
it "should not have a reason for newly created user" do
user.expects(:created_at).returns(10.days.ago)
user.redirected_to_top_reason.should == nil
end
end end
describe "old users" do
before do
user.stubs(:trust_level).returns(1)
SiteSetting.expects(:top_menu).returns("latest|top")
SiteSetting.expects(:has_enough_topics_to_redirect_to_top).returns(true)
end
it "should have a reason for long-time-no-see users" do
user.last_seen_at = 2.months.ago
user.redirected_to_top_reason.should == I18n.t('redirected_to_top_reasons.not_seen_in_a_month')
end
end
end end
end end