Commit 8db947bcfe2f3e988c995696f0fd24d9edfdc3b0

Authored by Saito
1 parent 7f44599e

implements protected branches to smart http protocal

Showing 1 changed file with 19 additions and 4 deletions   Show diff stats
config/initializers/grack_auth.rb
... ... @@ -18,14 +18,29 @@ module Grack
18 18 elsif @env['REQUEST_METHOD'] == 'POST'
19 19 if @env['REQUEST_URI'].end_with?('git-upload-pack')
20 20 return project.dev_access_for?(user)
21   - elsif @env['REQUEST_URI'].end_with?('git-upload-pack')
22   - #TODO master branch protection
23   - return project.dev_access_for?(user)
  21 + elsif @env['REQUEST_URI'].end_with?('git-receive-pack')
  22 + if project.protected_branches.map(&:name).include?(current_ref)
  23 + project.master_access_for?(user)
  24 + else
  25 + project.dev_access_for?(user)
  26 + end
24 27 else
25 28 false
26 29 end
  30 + else
  31 + false
27 32 end
28   -
29 33 end# valid?
  34 +
  35 + def current_ref
  36 + if @env["HTTP_CONTENT_ENCODING"] =~ /gzip/
  37 + input = Zlib::GzipReader.new(@request.body).string
  38 + else
  39 + input = @request.body.string
  40 + end
  41 +
  42 + oldrev, newrev, ref = input.split(' ')
  43 + /refs\/heads\/([\w-]+)/.match(ref).to_a.last
  44 + end
30 45 end# Auth
31 46 end# Grack
... ...