diff --git a/app/assets/javascripts/discourse/models/topic.js.es6 b/app/assets/javascripts/discourse/models/topic.js.es6 index d52ffafacd6..15b181fae88 100644 --- a/app/assets/javascripts/discourse/models/topic.js.es6 +++ b/app/assets/javascripts/discourse/models/topic.js.es6 @@ -134,9 +134,10 @@ const Topic = RestModel.extend({ return this.get('url') + (user ? '?u=' + user.get('username_lower') : ''); }.property('url'), - printUrl: function(){ - return this.get('url') + '/print'; - }.property('url'), + @computed('url') + printUrl(url) { + return url + '/print'; + }, url: function() { let slug = this.get('slug') || ''; diff --git a/app/assets/javascripts/discourse/views/topic-footer-main-buttons.js.es6 b/app/assets/javascripts/discourse/views/topic-footer-main-buttons.js.es6 index 1dac46feb5b..9ea80990c2b 100644 --- a/app/assets/javascripts/discourse/views/topic-footer-main-buttons.js.es6 +++ b/app/assets/javascripts/discourse/views/topic-footer-main-buttons.js.es6 @@ -7,7 +7,6 @@ export default ContainerView.extend({ @on('init') createButtons() { const mobileView = this.site.mobileView; - const { siteSettings } = this; const topic = this.get('topic'); @@ -33,7 +32,7 @@ export default ContainerView.extend({ this.attachViewClass('invite-reply-button'); } - if (!mobileView && siteSettings.allow_print_page) { + if (!mobileView && this.siteSettings.max_prints_per_hour_per_user > 0) { this.attachViewClass('print-button'); } diff --git a/app/controllers/topics_controller.rb b/app/controllers/topics_controller.rb index d2c66fd9451..5aa6f52843f 100644 --- a/app/controllers/topics_controller.rb +++ b/app/controllers/topics_controller.rb @@ -70,9 +70,9 @@ class TopicsController < ApplicationController end if opts[:print] - raise Discourse::InvalidAccess unless SiteSetting.allow_print_page + 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 current_user.admin? + RateLimiter.new(current_user, "print-topic-per-hour", 10, 1.hour).performed! unless @guardian.is_admin? rescue RateLimiter::LimitExceeded render_json_error(I18n.t("rate_limiter.slow_down")) end diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml index a9bc245b305..a6812420742 100644 --- a/config/locales/server.en.yml +++ b/config/locales/server.en.yml @@ -1312,7 +1312,7 @@ en: topic_page_title_includes_category: "Topic page title includes the category name." - allow_print_page: "Enable a special topic page for printing" + max_prints_per_hour_per_user: "Maximum number of /print page impressions (set to 0 to disable)" full_name_required: "Full name is a required field of a user's profile." enable_names: "Show the user's full name on their profile, user card, and emails. Disable to hide full name everywhere." diff --git a/config/site_settings.yml b/config/site_settings.yml index ee36b1c02b4..8d8a67f9b3a 100644 --- a/config/site_settings.yml +++ b/config/site_settings.yml @@ -909,6 +909,9 @@ rate_limits: client: true shadowed_by_global: true default: 0 + max_prints_per_hour_per_user: + default: 0 + client: true developer: force_hostname: @@ -1220,9 +1223,6 @@ uncategorized: topic_page_title_includes_category: true - allow_print_page: - default: true - client: true user_preferences: default_email_digest_frequency: diff --git a/lib/topic_view.rb b/lib/topic_view.rb index ec31a74562a..f87217a215a 100644 --- a/lib/topic_view.rb +++ b/lib/topic_view.rb @@ -51,7 +51,7 @@ class TopicView @page = 1 if (!@page || @page.zero?) @chunk_size = case when options[:slow_platform] then TopicView.slow_chunk_size - when @print then 1000 + when @print then TopicView.print_chunk_size else TopicView.chunk_size end @limit ||= @chunk_size