2011-11-15 21:58:27 +00:00
|
|
|
module Grack
|
|
|
|
class Auth < Base
|
|
|
|
def initialize(app)
|
|
|
|
@app = app
|
|
|
|
end
|
|
|
|
|
2011-11-17 21:57:30 +00:00
|
|
|
# TODO tests!!!
|
|
|
|
def call(env)
|
|
|
|
super
|
|
|
|
if git?
|
2011-11-20 21:58:53 +00:00
|
|
|
return render_not_found if project.blank?
|
2011-11-15 21:58:27 +00:00
|
|
|
|
2011-11-17 21:57:30 +00:00
|
|
|
return ::Rack::Auth::Basic.new(@app) do |u, p|
|
2012-12-25 15:55:56 +00:00
|
|
|
user = User.auth_by_token_or_login_pass(u, p) and
|
2013-03-07 08:06:34 +00:00
|
|
|
ability = ::Ability.new(user) and ability.can?(action, project) and
|
|
|
|
ENV['GL_ID'] = "user-#{user.id}"
|
2011-11-17 21:57:30 +00:00
|
|
|
end.call(env) unless project.public? and read? # need auth
|
2011-11-15 21:58:27 +00:00
|
|
|
end
|
2011-11-17 21:57:30 +00:00
|
|
|
@app.call(env) # next app in stack
|
2011-11-15 21:58:27 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|