diff --git a/app/models/user.rb b/app/models/user.rb index 08c561b510d..0686a3289b9 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -560,6 +560,8 @@ class User < ActiveRecord::Base end def redirected_to_top_reason + # redirect is enabled + return unless SiteSetting.redirect_users_to_top_page # top must be in the top_menu return unless SiteSetting.top_menu =~ /top/i # there should be enough topics diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml index 2c8e3c9fedc..57054c6452d 100644 --- a/config/locales/server.en.yml +++ b/config/locales/server.en.yml @@ -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_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" enable_badges: "Enable the badge system (experimental)" diff --git a/config/site_settings.yml b/config/site_settings.yml index c464b03eb3f..22dd3296640 100644 --- a/config/site_settings.yml +++ b/config/site_settings.yml @@ -148,6 +148,7 @@ users: client: true default: 60 delete_all_posts_max: 15 + redirect_users_to_top_page: true posting: min_post_length: diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 82b20ee4fe3..fcd8e635f88 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -1093,48 +1093,58 @@ describe User do describe "redirected_to_top_reason" do let!(:user) { Fabricate(:user) } - it "should have no reason when top is not in the top_menu" do - SiteSetting.expects(:top_menu).returns("latest") + it "should have no reason when redirect_users_to_top_page is disabled" do + SiteSetting.expects(:redirect_users_to_top_page).returns(false) user.redirected_to_top_reason.should == nil end - it "should have no reason when there isn't enough topics" do - SiteSetting.expects(:top_menu).returns("latest|top") - SiteSetting.expects(:has_enough_topics_to_redirect_to_top).returns(false) - user.redirected_to_top_reason.should == nil - end + context "redirect_users_to_top_page is enabled" do + before { SiteSetting.stubs(:redirect_users_to_top_page).returns(true) } - describe "new users" do - before do - 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) + it "should have no reason when top is not in the top_menu" do + SiteSetting.expects(:top_menu).returns("latest") user.redirected_to_top_reason.should == nil end - end - describe "old users" do - before do - user.stubs(:trust_level).returns(1) + it "should have no reason when there isn't enough topics" do 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 - 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') + describe "new users" do + before do + 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 + + 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