Update post-receive worker to use correct identifier

This commit is contained in:
Dmitriy Zaporozhets 2013-02-14 14:00:02 +02:00
parent ed3f44085e
commit b698094d4d
2 changed files with 12 additions and 11 deletions

View file

@ -21,14 +21,18 @@ class PostReceive
return false
end
# Ignore push from non-gitlab users
user = if identifier.nil?
raise identifier.inspect
user = if identifier.blank?
# Local push from gitlab
email = project.repository.commit(newrev).author.email rescue nil
User.find_by_email(email) if email
elsif /^[A-Z0-9._%a-z\-]+@(?:[A-Z0-9a-z\-]+\.)+[A-Za-z]{2,4}$/.match(identifier)
User.find_by_email(identifier)
elsif identifier =~ /key/
elsif identifier =~ /\Auser-\d+\Z/
# git push over http
user_id = identifier.gsub("user-", "")
User.find_by_id(user_id)
elsif identifier =~ /\Akey-\d+\Z/
# git push over ssh
key_id = identifier.gsub("key-", "")
Key.find_by_id(key_id).try(:user)
end

View file

@ -7,9 +7,6 @@ module Grack
@request = Rack::Request.new(env)
@auth = Request.new(env)
# Pass Gitolite update hook
ENV['GL_BYPASS_UPDATE_HOOK'] = "true"
# Need this patch due to the rails mount
@env['PATH_INFO'] = @request.path
@env['SCRIPT_NAME'] = ""
@ -35,8 +32,8 @@ module Grack
self.user = User.find_by_email(login) || User.find_by_username(login)
return false unless user.try(:valid_password?, password)
# Set GL_USER env variable
ENV['GL_USER'] = user.email
# Set GL_ID env variable
ENV['GL_ID'] = "user-#{user.id}"
end
# Git upload and receive