Commit 8db947bc authored by Saito's avatar Saito

implements protected branches to smart http protocal

parent 7f44599e
......@@ -18,14 +18,29 @@ module Grack
elsif @env['REQUEST_METHOD'] == 'POST'
if @env['REQUEST_URI'].end_with?('git-upload-pack')
return project.dev_access_for?(user)
elsif @env['REQUEST_URI'].end_with?('git-upload-pack')
#TODO master branch protection
return project.dev_access_for?(user)
elsif @env['REQUEST_URI'].end_with?('git-receive-pack')
if project.protected_branches.map(&:name).include?(current_ref)
project.master_access_for?(user)
else
project.dev_access_for?(user)
end
else
false
end
else
false
end
end# valid?
def current_ref
if @env["HTTP_CONTENT_ENCODING"] =~ /gzip/
input = Zlib::GzipReader.new(@request.body).string
else
input = @request.body.string
end
oldrev, newrev, ref = input.split(' ')
/refs\/heads\/([\w-]+)/.match(ref).to_a.last
end
end# Auth
end# Grack
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment