diff --git a/app/controllers/topics_controller.rb b/app/controllers/topics_controller.rb index 5aa6f52843f..1a15adc5b5d 100644 --- a/app/controllers/topics_controller.rb +++ b/app/controllers/topics_controller.rb @@ -72,7 +72,7 @@ class TopicsController < ApplicationController if opts[:print] raise Discourse::InvalidAccess unless SiteSetting.max_prints_per_hour_per_user > 0 begin - RateLimiter.new(current_user, "print-topic-per-hour", 10, 1.hour).performed! unless @guardian.is_admin? + RateLimiter.new(current_user, "print-topic-per-hour", SiteSetting.max_prints_per_hour_per_user, 1.hour).performed! unless @guardian.is_admin? rescue RateLimiter::LimitExceeded render_json_error(I18n.t("rate_limiter.slow_down")) end diff --git a/config/site_settings.yml b/config/site_settings.yml index 8d8a67f9b3a..f0392c6909a 100644 --- a/config/site_settings.yml +++ b/config/site_settings.yml @@ -910,7 +910,7 @@ rate_limits: shadowed_by_global: true default: 0 max_prints_per_hour_per_user: - default: 0 + default: 5 client: true developer: diff --git a/lib/topic_view.rb b/lib/topic_view.rb index f87217a215a..7c93adb8698 100644 --- a/lib/topic_view.rb +++ b/lib/topic_view.rb @@ -137,11 +137,7 @@ class TopicView end def relative_url - if !@print - @topic.relative_url - else - @topic.relative_url + '/print' - end + "#{@topic.relative_url}#{@print ? '/print' : ''}" end def page_title diff --git a/spec/controllers/application_controller_spec.rb b/spec/controllers/application_controller_spec.rb index cf2b9ff54ae..62b9bb5afd8 100644 --- a/spec/controllers/application_controller_spec.rb +++ b/spec/controllers/application_controller_spec.rb @@ -88,10 +88,6 @@ describe TopicsController do render_views context "when the SiteSetting is enabled" do - before do - SiteSetting.stubs(:max_prints_per_hour_per_user).returns(10) - end - it "uses the application layout when there's no param" do get :show, topic_id: topic.id, slug: topic.slug expect(response).to render_template(layout: 'application') diff --git a/spec/controllers/topics_controller_spec.rb b/spec/controllers/topics_controller_spec.rb index 6bff4d63347..ee523583bd2 100644 --- a/spec/controllers/topics_controller_spec.rb +++ b/spec/controllers/topics_controller_spec.rb @@ -747,20 +747,19 @@ describe TopicsController do expect(IncomingLink.count).to eq(1) end - it "doesn't renders the print view by default" do - user = Fabricate(:user) - get :show, topic_id: topic.id, slug: topic.slug, print: true + context 'print' do - expect(response).to be_forbidden - end + it "doesn't renders the print view when disabled" do + SiteSetting.max_prints_per_hour_per_user = 0 + get :show, topic_id: topic.id, slug: topic.slug, print: true + expect(response).to be_forbidden + end - it 'renders the print view when enabled' do - SiteSetting.max_prints_per_hour_per_user = 10 - - user = Fabricate(:user) - get :show, topic_id: topic.id, slug: topic.slug, print: true - - expect(response).to be_successful + it 'renders the print view when enabled' do + SiteSetting.max_prints_per_hour_per_user = 10 + get :show, topic_id: topic.id, slug: topic.slug, print: true + expect(response).to be_successful + end end it 'records redirects' do