rosa-build/lib/grack/auth.rb

23 lines
648 B
Ruby
Raw Normal View History

2012-01-30 20:39:34 +00:00
# -*- encoding : utf-8 -*-
module Grack
class Auth < Base
def initialize(app)
@app = app
end
# TODO tests!!!
def call(env)
super
if git?
return render_not_found if project.blank?
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
ability = ::Ability.new(user) and ability.can?(action, project) # project.members.include?(user)
end.call(env) unless project.public? and read? # need auth
end
@app.call(env) # next app in stack
end
end
end