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]
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

View File

@ -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:

View File

@ -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

View File

@ -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')

View File

@ -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