Second review fixes

This commit is contained in:
Rafael dos Santos Silva 2016-08-09 00:53:08 -03:00
parent f96fffeb34
commit 0229df4c73
5 changed files with 14 additions and 23 deletions

View File

@ -72,7 +72,7 @@ class TopicsController < ApplicationController
if opts[:print] if opts[:print]
raise Discourse::InvalidAccess unless SiteSetting.max_prints_per_hour_per_user > 0 raise Discourse::InvalidAccess unless SiteSetting.max_prints_per_hour_per_user > 0
begin 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 rescue RateLimiter::LimitExceeded
render_json_error(I18n.t("rate_limiter.slow_down")) render_json_error(I18n.t("rate_limiter.slow_down"))
end end

View File

@ -910,7 +910,7 @@ rate_limits:
shadowed_by_global: true shadowed_by_global: true
default: 0 default: 0
max_prints_per_hour_per_user: max_prints_per_hour_per_user:
default: 0 default: 5
client: true client: true
developer: developer:

View File

@ -137,11 +137,7 @@ class TopicView
end end
def relative_url def relative_url
if !@print "#{@topic.relative_url}#{@print ? '/print' : ''}"
@topic.relative_url
else
@topic.relative_url + '/print'
end
end end
def page_title def page_title

View File

@ -88,10 +88,6 @@ describe TopicsController do
render_views render_views
context "when the SiteSetting is enabled" do 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 it "uses the application layout when there's no param" do
get :show, topic_id: topic.id, slug: topic.slug get :show, topic_id: topic.id, slug: topic.slug
expect(response).to render_template(layout: 'application') expect(response).to render_template(layout: 'application')

View File

@ -747,20 +747,19 @@ describe TopicsController do
expect(IncomingLink.count).to eq(1) expect(IncomingLink.count).to eq(1)
end end
it "doesn't renders the print view by default" do context 'print' do
user = Fabricate(:user)
get :show, topic_id: topic.id, slug: topic.slug, print: true
expect(response).to be_forbidden it "doesn't renders the print view when disabled" do
end 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 it 'renders the print view when enabled' do
SiteSetting.max_prints_per_hour_per_user = 10 SiteSetting.max_prints_per_hour_per_user = 10
get :show, topic_id: topic.id, slug: topic.slug, print: true
user = Fabricate(:user) expect(response).to be_successful
get :show, topic_id: topic.id, slug: topic.slug, print: true end
expect(response).to be_successful
end end
it 'records redirects' do it 'records redirects' do