Fix Error 500s with anonymous clones for a project that has moved
Closes #41457
This commit is contained in:
parent
5e6dd15a99
commit
a83c41f6c6
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
title: Fix Error 500s with anonymous clones for a project that has moved
|
||||||
|
merge_request:
|
||||||
|
author:
|
||||||
|
type: fixed
|
|
@ -2,6 +2,7 @@ module Gitlab
|
||||||
module Checks
|
module Checks
|
||||||
class ProjectMoved
|
class ProjectMoved
|
||||||
REDIRECT_NAMESPACE = "redirect_namespace".freeze
|
REDIRECT_NAMESPACE = "redirect_namespace".freeze
|
||||||
|
ANONYMOUS_ID_KEY = 'anonymous'.freeze
|
||||||
|
|
||||||
def initialize(project, user, redirected_path, protocol)
|
def initialize(project, user, redirected_path, protocol)
|
||||||
@project = project
|
@project = project
|
||||||
|
@ -22,7 +23,7 @@ module Gitlab
|
||||||
|
|
||||||
def add_redirect_message
|
def add_redirect_message
|
||||||
Gitlab::Redis::SharedState.with do |redis|
|
Gitlab::Redis::SharedState.with do |redis|
|
||||||
key = self.class.redirect_message_key(user.id, project.id)
|
key = self.class.redirect_message_key(user_identifier, project.id)
|
||||||
redis.setex(key, 5.minutes, redirect_message)
|
redis.setex(key, 5.minutes, redirect_message)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -45,8 +46,14 @@ module Gitlab
|
||||||
|
|
||||||
attr_reader :project, :redirected_path, :protocol, :user
|
attr_reader :project, :redirected_path, :protocol, :user
|
||||||
|
|
||||||
def self.redirect_message_key(user_id, project_id)
|
def self.redirect_message_key(user_identifier, project_id)
|
||||||
"#{REDIRECT_NAMESPACE}:#{user_id}:#{project_id}"
|
"#{REDIRECT_NAMESPACE}:#{user_identifier}:#{project_id}"
|
||||||
|
end
|
||||||
|
|
||||||
|
def user_identifier
|
||||||
|
return ANONYMOUS_ID_KEY unless user.present?
|
||||||
|
|
||||||
|
user.id
|
||||||
end
|
end
|
||||||
|
|
||||||
def remote_url_message(rejected)
|
def remote_url_message(rejected)
|
||||||
|
|
|
@ -35,6 +35,13 @@ describe Gitlab::Checks::ProjectMoved, :clean_gitlab_redis_shared_state do
|
||||||
project_moved = described_class.new(project, user, 'foo/bar', 'http')
|
project_moved = described_class.new(project, user, 'foo/bar', 'http')
|
||||||
expect(project_moved.add_redirect_message).to eq("OK")
|
expect(project_moved.add_redirect_message).to eq("OK")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'should handle anonymous clones' do
|
||||||
|
project_moved = described_class.new(project, nil, 'foo/bar', 'http')
|
||||||
|
|
||||||
|
expect(project_moved.add_redirect_message).to eq("OK")
|
||||||
|
expect(Gitlab::Redis::SharedState.with { |redis| redis.get("redirect_namespace:anonymous:#{project.id}") }).not_to be_nil
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#redirect_message' do
|
describe '#redirect_message' do
|
||||||
|
|
Loading…
Reference in New Issue