[deploy] Add proper 301 status to username change redirects (#7650)
This commit is contained in:
parent
0ee7b97b44
commit
195da03edf
3 changed files with 11 additions and 4 deletions
|
|
@ -81,7 +81,7 @@ class StoriesController < ApplicationController
|
|||
user_or_org = User.find_by("old_username = ? OR old_old_username = ?", potential_username, potential_username) ||
|
||||
Organization.find_by("old_slug = ? OR old_old_slug = ?", potential_username, potential_username)
|
||||
if user_or_org.present? && !user_or_org.decorate.fully_banished?
|
||||
redirect_to user_or_org.path
|
||||
redirect_to user_or_org.path, status: :moved_permanently
|
||||
else
|
||||
not_found
|
||||
end
|
||||
|
|
@ -91,10 +91,10 @@ class StoriesController < ApplicationController
|
|||
potential_username = params[:username].tr("@", "").downcase
|
||||
@user = User.find_by("old_username = ? OR old_old_username = ?", potential_username, potential_username)
|
||||
if @user&.articles&.find_by(slug: params[:slug])
|
||||
redirect_to URI.parse("/#{@user.username}/#{params[:slug]}").path
|
||||
redirect_to URI.parse("/#{@user.username}/#{params[:slug]}").path, status: :moved_permanently
|
||||
return
|
||||
elsif (@organization = @article.organization)
|
||||
redirect_to URI.parse("/#{@organization.slug}/#{params[:slug]}").path
|
||||
redirect_to URI.parse("/#{@organization.slug}/#{params[:slug]}").path, status: :moved_permanently
|
||||
return
|
||||
end
|
||||
not_found
|
||||
|
|
@ -121,7 +121,7 @@ class StoriesController < ApplicationController
|
|||
@tag_model = Tag.find_by(name: @tag) || not_found
|
||||
@moderators = User.with_role(:tag_moderator, @tag_model).select(:username, :profile_image, :id)
|
||||
if @tag_model.alias_for.present?
|
||||
redirect_to "/t/#{@tag_model.alias_for}"
|
||||
redirect_to "/t/#{@tag_model.alias_for}", status: :moved_permanently
|
||||
return
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -254,6 +254,7 @@ RSpec.describe "StoriesIndex", type: :request do
|
|||
tag2 = create(:tag, alias_for: tag.name)
|
||||
get "/t/#{tag2.name}"
|
||||
expect(response.body).to redirect_to "/t/#{tag.name}"
|
||||
expect(response).to have_http_status(:moved_permanently)
|
||||
end
|
||||
|
||||
it "does not render sponsor if not live" do
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ RSpec.describe "StoriesShow", type: :request do
|
|||
article.update(organization: org)
|
||||
get old_path
|
||||
expect(response.body).to redirect_to article.path
|
||||
expect(response).to have_http_status(:moved_permanently)
|
||||
end
|
||||
|
||||
it "renders second and third users if present" do
|
||||
|
|
@ -90,6 +91,7 @@ RSpec.describe "StoriesShow", type: :request do
|
|||
user.update(username: "new_hotness_#{rand(10_000)}")
|
||||
get "/#{old_username}/#{article.slug}"
|
||||
expect(response.body).to redirect_to("/#{user.username}/#{article.slug}")
|
||||
expect(response).to have_http_status(:moved_permanently)
|
||||
end
|
||||
|
||||
it "redirects to appropriate page if user changes username twice" do
|
||||
|
|
@ -98,6 +100,7 @@ RSpec.describe "StoriesShow", type: :request do
|
|||
user.update(username: "new_new_username_#{rand(10_000)}")
|
||||
get "/#{old_username}/#{article.slug}"
|
||||
expect(response.body).to redirect_to("/#{user.username}/#{article.slug}")
|
||||
expect(response).to have_http_status(:moved_permanently)
|
||||
end
|
||||
|
||||
it "redirects to appropriate page if user changes username twice and go to middle username" do
|
||||
|
|
@ -106,6 +109,7 @@ RSpec.describe "StoriesShow", type: :request do
|
|||
user.update(username: "new_new_username_#{rand(10_000)}")
|
||||
get "/#{middle_username}/#{article.slug}"
|
||||
expect(response.body).to redirect_to("/#{user.username}/#{article.slug}")
|
||||
expect(response).to have_http_status(:moved_permanently)
|
||||
end
|
||||
|
||||
it "renders canonical url when exists" do
|
||||
|
|
@ -167,6 +171,7 @@ RSpec.describe "StoriesShow", type: :request do
|
|||
org.update(slug: "somethingnew")
|
||||
get "/#{original_slug}"
|
||||
expect(response.body).to redirect_to org.path
|
||||
expect(response).to have_http_status(:moved_permanently)
|
||||
end
|
||||
|
||||
it "redirects to the appropriate page if given an organization's old old slug" do
|
||||
|
|
@ -175,6 +180,7 @@ RSpec.describe "StoriesShow", type: :request do
|
|||
org.update(slug: "anothernewslug")
|
||||
get "/#{original_slug}"
|
||||
expect(response.body).to redirect_to org.path
|
||||
expect(response).to have_http_status(:moved_permanently)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue