From b86f8d65d76ce0a121ae17828f27e437daa486ac Mon Sep 17 00:00:00 2001 From: Christian Ratz Date: Tue, 10 Sep 2013 10:03:55 +0200 Subject: [PATCH] [#1850] Disable atom feeds via setting --- app/controllers/application_controller.rb | 17 ++++++++++++++++- app/helpers/application_helper.rb | 9 +++++---- app/models/user.rb | 2 +- app/views/my/_sidebar.html.erb | 20 +++++++++++--------- app/views/settings/_general.html.erb | 2 ++ config/initializers/10-patches.rb | 8 ++++++++ config/locales/de.yml | 1 + config/locales/en.yml | 1 + config/settings.yml | 2 ++ doc/CHANGELOG.md | 1 + lib/redmine/views/other_formats_builder.rb | 1 + 11 files changed, 49 insertions(+), 15 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index b9a1aadd82..8d415a147e 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -69,7 +69,8 @@ class ApplicationController < ActionController::Base :log_requesting_user, :reset_i18n_fallbacks, :set_localization, - :check_session_lifetime + :check_session_lifetime, + :check_if_feeds_enabled rescue_from ActionController::InvalidAuthenticityToken, :with => :invalid_authenticity_token @@ -646,6 +647,20 @@ class ApplicationController < ActionController::Base session[:updated_at] = Time.now end + def atom_request? + if params[:format].nil? + %w(application/rss+xml application/atom+xml).include? request.format.to_s + else + %w(atom).include? params[:format] + end + end + + def check_if_feeds_enabled + if atom_request? && Setting.feeds_disabled? + render_404({:message => I18n.t('label_disabled')}) + end + end + private def session_expired? diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index beae3884ec..da6ce8eaf5 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -402,10 +402,11 @@ module ApplicationHelper end def other_formats_links(&block) - content_tag 'p', :class => 'other-formats' do - formats = capture(Redmine::Views::OtherFormatsBuilder.new(self), &block) - - (l(:label_export_to) + formats).html_safe + formats = capture(Redmine::Views::OtherFormatsBuilder.new(self), &block) + unless formats.nil? || formats.strip.empty? + content_tag 'p', :class => 'other-formats' do + (l(:label_export_to) + formats).html_safe + end end end diff --git a/app/models/user.rb b/app/models/user.rb index 02ad42379f..bcee2f0339 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -459,7 +459,7 @@ class User < Principal def self.find_by_rss_key(key) token = Token.find_by_value(key) - token && token.user.active? ? token.user : nil + token && token.user.active? && !Setting.feeds_disabled? ? token.user : nil end def self.find_by_api_key(key) diff --git a/app/views/my/_sidebar.html.erb b/app/views/my/_sidebar.html.erb index 84e59f44ef..0cd7b482b5 100644 --- a/app/views/my/_sidebar.html.erb +++ b/app/views/my/_sidebar.html.erb @@ -21,16 +21,18 @@ See doc/COPYRIGHT.rdoc for more details. <%= User.human_attribute_name(:created_on) %>: <%= format_time(@user.created_on) %>

-

<%= l(:label_feeds_access_key) %>

- -

-<% if @user.rss_token %> -<%= l(:label_feeds_access_key_created_on, distance_of_time_in_words(Time.now, @user.rss_token.created_on)) %> -<% else %> -<%= l(:label_missing_feeds_access_key) %> +<% unless Setting.feeds_disabled? %> +

<%= l(:label_feeds_access_key) %>

+ +

+ <% if @user.rss_token %> + <%= l(:label_feeds_access_key_created_on, distance_of_time_in_words(Time.now, @user.rss_token.created_on)) %> + <% else %> + <%= l(:label_missing_feeds_access_key) %> + <% end %> + (<%= link_to l(:button_reset), {:action => 'reset_rss_key'}, :method => :post %>) +

<% end %> -(<%= link_to l(:button_reset), {:action => 'reset_rss_key'}, :method => :post %>) -

<% if Setting.rest_api_enabled? %>

<%= l(:label_api_access_key) %>

diff --git a/app/views/settings/_general.html.erb b/app/views/settings/_general.html.erb index b1863ad29e..7bf25d7185 100644 --- a/app/views/settings/_general.html.erb +++ b/app/views/settings/_general.html.erb @@ -36,6 +36,8 @@ See doc/COPYRIGHT.rdoc for more details.

<%= setting_select :wiki_compression, [['Gzip', 'gzip']], :blank => :label_none %>

+

<%= setting_check_box :feeds_disabled, :size => 6 %>

+

<%= setting_text_field :feeds_limit, :size => 6 %>

<%= setting_text_field :file_max_size_displayed, :size => 6 %> <%= l(:"number.human.storage_units.units.kb") %>

diff --git a/config/initializers/10-patches.rb b/config/initializers/10-patches.rb index bb6afbe093..4ac8774c7e 100644 --- a/config/initializers/10-patches.rb +++ b/config/initializers/10-patches.rb @@ -211,6 +211,14 @@ module ActionView end end end + + module AssetTagHelper + def auto_discovery_link_tag_with_no_atom_feeds(type = :rss, url_options = {}, tag_options = {}) + return if (type == :atom) && Setting.table_exists? && Setting.feeds_disabled? + auto_discovery_link_tag_without_no_atom_feeds(type, url_options, tag_options) + end + alias_method_chain :auto_discovery_link_tag, :no_atom_feeds + end end end diff --git a/config/locales/de.yml b/config/locales/de.yml index 218d1d77b3..78611a4c49 100644 --- a/config/locales/de.yml +++ b/config/locales/de.yml @@ -1148,6 +1148,7 @@ de: setting_emails_footer: "E-Mail-Fußzeile" setting_emails_header: "Emailkopf" setting_enabled_scm: "Aktivierte Versionskontrollsysteme" + setting_feeds_disabled: "Atom-Feeds deaktivieren" setting_feeds_limit: "Max. Anzahl Einträge pro Atom-Feed" setting_file_max_size_displayed: "Maximale Größe inline angezeigter Textdateien" setting_gravatar_default: "Standard-Gravatar-Bild" diff --git a/config/locales/en.yml b/config/locales/en.yml index 0284324075..0deb69b482 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -1124,6 +1124,7 @@ en: setting_emails_footer: "Emails footer" setting_emails_header: "Emails header" setting_enabled_scm: "Enabled SCM" + setting_feeds_disabled: "Disable Feeds" setting_feeds_limit: "Feed content limit" setting_file_max_size_displayed: "Max size of text files displayed inline" setting_gravatar_default: "Default Gravatar image" diff --git a/config/settings.yml b/config/settings.yml index 84f819868f..1dce2332e5 100644 --- a/config/settings.yml +++ b/config/settings.yml @@ -81,6 +81,8 @@ host_name: default: localhost:3000 protocol: default: http +feeds_disabled: + default: 0 feeds_limit: format: int default: 15 diff --git a/doc/CHANGELOG.md b/doc/CHANGELOG.md index 0b7f39c1d1..9cdf0d6179 100644 --- a/doc/CHANGELOG.md +++ b/doc/CHANGELOG.md @@ -15,6 +15,7 @@ See doc/COPYRIGHT.rdoc for more details. * `#1418` Additional changes: Change links to issues/planning elements to use work_packages controller * `#1898` Separate action for changing wiki parent page (was same as rename before) * `#1923` Add permission that allows hiding repository statistics on commits per author +* `#1850` Disable atom feeds via setting ## 3.0.0pre15 diff --git a/lib/redmine/views/other_formats_builder.rb b/lib/redmine/views/other_formats_builder.rb index 98d180b4af..0083a6eb81 100644 --- a/lib/redmine/views/other_formats_builder.rb +++ b/lib/redmine/views/other_formats_builder.rb @@ -18,6 +18,7 @@ module Redmine end def link_to(name, options={}) + return if Setting.table_exists? && Setting.feeds_disabled? && name == "Atom" url = { :format => name.to_s.downcase }.merge(options.delete(:url) || {}) caption = options.delete(:caption) || name html_options = { :class => name.to_s.downcase, :rel => 'nofollow' }.merge(options)