diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2009-01-27 17:27:50 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2009-01-27 17:27:50 +0000 |
commit | e1f96ca4db645f0da090dfcee378217353505c62 (patch) | |
tree | 149dd8fa4a99f9e96ab5a9f20ab9050aeee047a1 | |
parent | 6c93b8d5992efe0efc2d00a2f0d846c4460d6f67 (diff) | |
download | redmine-e1f96ca4db645f0da090dfcee378217353505c62.tar.gz redmine-e1f96ca4db645f0da090dfcee378217353505c62.zip |
Replaces the obsolete robots.txt with a cached action (#2491).
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@2319 e93f8b46-1217-0410-a6f0-8f06a7374b81
-rw-r--r-- | app/controllers/projects_controller.rb | 6 | ||||
-rw-r--r-- | app/controllers/welcome_controller.rb | 6 | ||||
-rw-r--r-- | app/models/project.rb | 1 | ||||
-rw-r--r-- | app/views/welcome/robots.rhtml | 9 | ||||
-rw-r--r-- | config/routes.rb | 1 | ||||
-rw-r--r-- | public/robots.txt | 4 | ||||
-rw-r--r-- | test/functional/welcome_controller_test.rb | 7 |
7 files changed, 30 insertions, 4 deletions
diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 64040e3ba..5d90c92af 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -29,6 +29,12 @@ class ProjectsController < ApplicationController before_filter :require_admin, :only => [ :add, :archive, :unarchive, :destroy ] accept_key_auth :activity + after_filter :only => [:add, :edit, :archive, :unarchive, :destroy] do |controller| + if controller.request.post? + controller.send :expire_action, :controller => 'welcome', :action => 'robots.txt' + end + end + helper :sort include SortHelper helper :custom_fields diff --git a/app/controllers/welcome_controller.rb b/app/controllers/welcome_controller.rb index b8108e8ac..c14ec4dbe 100644 --- a/app/controllers/welcome_controller.rb +++ b/app/controllers/welcome_controller.rb @@ -16,9 +16,15 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. class WelcomeController < ApplicationController + caches_action :robots def index @news = News.latest User.current @projects = Project.latest User.current end + + def robots + @projects = Project.public.active + render :layout => false, :content_type => 'text/plain' + end end diff --git a/app/models/project.rb b/app/models/project.rb index f40bcb603..7ce0051ed 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -67,6 +67,7 @@ class Project < ActiveRecord::Base named_scope :has_module, lambda { |mod| { :conditions => ["#{Project.table_name}.id IN (SELECT em.project_id FROM #{EnabledModule.table_name} em WHERE em.name=?)", mod.to_s] } } named_scope :active, { :conditions => "#{Project.table_name}.status = #{STATUS_ACTIVE}"} + named_scope :public, { :conditions => { :is_public => true } } named_scope :visible, lambda { { :conditions => Project.visible_by(User.current) } } def identifier=(identifier) diff --git a/app/views/welcome/robots.rhtml b/app/views/welcome/robots.rhtml new file mode 100644 index 000000000..c6e206bd6 --- /dev/null +++ b/app/views/welcome/robots.rhtml @@ -0,0 +1,9 @@ +User-agent: * +<% @projects.each do |p| -%> +Disallow: /projects/<%= p.to_param %>/repository +Disallow: /projects/<%= p.to_param %>/issues +Disallow: /projects/<%= p.to_param %>/activity +<% end -%> +Disallow: /issues/gantt +Disallow: /issues/calendar +Disallow: /activity diff --git a/config/routes.rb b/config/routes.rb index ca66f4b57..77df6816e 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -250,4 +250,5 @@ ActionController::Routing::Routes.draw do |map| # Install the default route as the lowest priority. map.connect ':controller/:action/:id' + map.connect 'robots.txt', :controller => 'welcome', :action => 'robots' end diff --git a/public/robots.txt b/public/robots.txt deleted file mode 100644 index 5fb2d1597..000000000 --- a/public/robots.txt +++ /dev/null @@ -1,4 +0,0 @@ -User-agent: * -Disallow: /projects/gantt -Disallow: /projects/calendar -Disallow: /repositories/diff diff --git a/test/functional/welcome_controller_test.rb b/test/functional/welcome_controller_test.rb index df565a751..b45cb97c8 100644 --- a/test/functional/welcome_controller_test.rb +++ b/test/functional/welcome_controller_test.rb @@ -60,4 +60,11 @@ class WelcomeControllerTest < Test::Unit::TestCase get :index assert_equal :fr, @controller.current_language end + + def test_robots + get :robots + assert_response :success + assert_equal 'text/plain', @response.content_type + assert @response.body.match(%r{^Disallow: /projects/ecookbook/issues$}) + end end |