Project

General

Profile

Feature #37807 » 0003-Disallow-all-in-robots.txt-if-login-is-required.patch

Holger Just, 2022-10-20 17:27

View differences:

app/controllers/welcome_controller.rb
end
def robots
@projects = Project.visible(User.anonymous)
@projects = Project.visible(User.anonymous) unless Setting.login_required?
render :layout => false, :content_type => 'text/plain'
end
end
app/views/welcome/robots.text.erb
User-agent: *
<% if Setting.login_required? -%>
Disallow: /
<% else -%>
<% @projects.each do |project| -%>
<% [project, project.id].each do |p| -%>
Disallow: <%= url_for(:controller => 'repositories', :action => :show, :id => p) %>
......
Disallow: <%= url_for(signin_path) %>
Disallow: <%= url_for(register_path) %>
Disallow: <%= url_for(lost_password_path) %>
<% end -%>
test/integration/welcome_test.rb
get '/robots.txt'
assert_response :success
assert_equal 'text/plain', @response.media_type
# Disallow everything if logins are required
refute @response.body.match(%r{^Disallow: /projects/ecookbook/issues\r?$})
assert @response.body.match(%r{^Disallow: /\r?$})
end
end
end
(3-3/3)