A platform for community discussion. Free, open, simple.
FIX: Always noindex /u routes (#27712)
Natalie Tay8bbb4c5cca0a
diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rbindex 1400ae0e8f2..4cd1f17d5ea 100644--- a/app/controllers/users_controller.rb+++ b/app/controllers/users_controller.rb@@ -105,7 +105,7 @@ class UsersController < ApplicationController]skip_before_action :redirect_to_profile_if_required, only: %i[show staff_info update]- after_action :add_noindex_header, only: %i[show my_redirect]+ before_action :add_noindex_header, only: %i[show my_redirect]allow_in_staff_writes_only_mode :admin_loginallow_in_staff_writes_only_mode :email_logindiff --git a/spec/requests/users_controller_spec.rb b/spec/requests/users_controller_spec.rbindex 7b23aa3ff7b..af7d2b95c5f 100644--- a/spec/requests/users_controller_spec.rb+++ b/spec/requests/users_controller_spec.rb@@ -4556,6 +4556,7 @@ RSpec.describe UsersController doexpect(parsed["username"]).to eq(user.username)expect(parsed["profile_hidden"]).to be_blankexpect(parsed["trust_level"]).to be_present+ expect(response.headers["X-Robots-Tag"]).to eq("noindex")endit "returns a hidden profile" do@@ -4568,11 +4569,13 @@ RSpec.describe UsersController doexpect(parsed["username"]).to eq(user.username)expect(parsed["profile_hidden"]).to eq(true)expect(parsed["trust_level"]).to be_blank+ expect(response.headers["X-Robots-Tag"]).to eq("noindex")endit "should 403 for anonymous user when profiles are hidden" doSiteSetting.hide_user_profiles_from_public = trueget "/u/#{user.username}.json"+ expect(response.headers["X-Robots-Tag"]).to eq("noindex")expect(response).to have_http_status(:forbidden)get "/u/#{user.username}/messages.json"expect(response).to have_http_status(:forbidden)@@ -4583,6 +4586,7 @@ RSpec.describe UsersController doget "/u/#{user.username}", headers: { "User-Agent" => "Googlebot" }expect(response).to have_http_status(:forbidden)expect(response.body).to have_tag("body.crawler")+ expect(response.headers["X-Robots-Tag"]).to eq("noindex")enddescribe "user profile views" do@@ -4615,12 +4619,14 @@ RSpec.describe UsersController doit "returns not found when the username doesn't exist" doget "/u/madeuppity.json"expect(response).not_to be_successful+ expect(response.headers["X-Robots-Tag"]).to eq("noindex")endit "returns not found when the user is inactive" doinactive = Fabricate(:user, active: false)get "/u/#{inactive.username}.json"expect(response).not_to be_successful+ expect(response.headers["X-Robots-Tag"]).to eq("noindex")endit "returns success when show_inactive_accounts is true and user is logged in" do@@ -4634,6 +4640,7 @@ RSpec.describe UsersController doGuardian.any_instance.expects(:can_see?).with(user1).returns(false)get "/u/#{user1.username}.json"expect(response).to be_forbidden+ expect(response.headers["X-Robots-Tag"]).to eq("noindex")enddescribe "user profile views" do