2012-01-30 20:39:34 +00:00
|
|
|
# -*- encoding : utf-8 -*-
|
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-03-22 14:50:15 +00:00
|
|
|
user = User.find_for_database_authentication(:login => u) and !user.access_locked? and user.valid_password?(p) and
|
2011-11-20 21:58:53 +00:00
|
|
|
ability = ::Ability.new(user) and ability.can?(action, project) # project.members.include?(user)
|
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
|