summaryrefslogtreecommitdiff
path: root/lib/gitlab/checks
diff options
context:
space:
mode:
authorStan Hu <stanhu@gmail.com>2017-12-24 09:35:30 -0800
committerStan Hu <stanhu@gmail.com>2017-12-25 05:28:51 -0800
commita83c41f6c6e0035c40916b3cbdda7fdd4f7e925f (patch)
treece0ed5b1113e9eec082b832f098504d4bb061d2e /lib/gitlab/checks
parent5e6dd15a996f57d7a8760f4c9c1dbd7beeeaadff (diff)
downloadgitlab-ce-a83c41f6c6e0035c40916b3cbdda7fdd4f7e925f.tar.gz
Fix Error 500s with anonymous clones for a project that has moved
Closes #41457
Diffstat (limited to 'lib/gitlab/checks')
-rw-r--r--lib/gitlab/checks/project_moved.rb13
1 files changed, 10 insertions, 3 deletions
diff --git a/lib/gitlab/checks/project_moved.rb b/lib/gitlab/checks/project_moved.rb
index 3a1c0a3455e..c1da2471b54 100644
--- a/lib/gitlab/checks/project_moved.rb
+++ b/lib/gitlab/checks/project_moved.rb
@@ -2,6 +2,7 @@ module Gitlab
module Checks
class ProjectMoved
REDIRECT_NAMESPACE = "redirect_namespace".freeze
+ ANONYMOUS_ID_KEY = 'anonymous'.freeze
def initialize(project, user, redirected_path, protocol)
@project = project
@@ -22,7 +23,7 @@ module Gitlab
def add_redirect_message
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)
end
end
@@ -45,8 +46,14 @@ module Gitlab
attr_reader :project, :redirected_path, :protocol, :user
- def self.redirect_message_key(user_id, project_id)
- "#{REDIRECT_NAMESPACE}:#{user_id}:#{project_id}"
+ def self.redirect_message_key(user_identifier, project_id)
+ "#{REDIRECT_NAMESPACE}:#{user_identifier}:#{project_id}"
+ end
+
+ def user_identifier
+ return ANONYMOUS_ID_KEY unless user.present?
+
+ user.id
end
def remote_url_message(rejected)