Rate limit printing

This commit is contained in:
Rafael dos Santos Silva 2016-08-03 01:28:46 -03:00
parent 70c68f0a7c
commit 6faedfa716

View File

@ -3,6 +3,7 @@ require_dependency 'promotion'
require_dependency 'url_helper'
require_dependency 'topics_bulk_action'
require_dependency 'discourse_event'
require_dependency 'rate_limiter'
class TopicsController < ApplicationController
before_filter :ensure_logged_in, only: [:timings,
@ -68,6 +69,14 @@ class TopicsController < ApplicationController
return redirect_to_correct_topic(topic, opts[:post_number]) if topic && topic.visible
end
if opts[:print]
begin
RateLimiter.new(current_user, "print-topic-per-hour", 10, 1.hour).performed!
rescue RateLimiter::LimitExceeded
render_json_error(I18n.t("rate_limiter.slow_down"))
end
end
begin
@topic_view = TopicView.new(params[:id] || params[:topic_id], current_user, opts)
rescue Discourse::NotFound