move admin rack to its own file
This commit is contained in:
parent
7ab963f859
commit
17b5e7b066
2 changed files with 20 additions and 19 deletions
|
|
@ -30,24 +30,6 @@ end
|
||||||
|
|
||||||
if AppConfig[:mount_resque_web]
|
if AppConfig[:mount_resque_web]
|
||||||
require 'resque/server'
|
require 'resque/server'
|
||||||
|
require File.join(Rails.root, 'lib/admin_rack')
|
||||||
class AdminRack
|
|
||||||
def initialize(app)
|
|
||||||
@app = app
|
|
||||||
end
|
|
||||||
|
|
||||||
def call(env)
|
|
||||||
user = env['warden'].authenticate(:scope => :user)
|
|
||||||
if user && user.admin?
|
|
||||||
@app.call(env)
|
|
||||||
else
|
|
||||||
[307, {"Location" => '/'}, self]
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def each(&block)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
Resque::Server.use AdminRack
|
Resque::Server.use AdminRack
|
||||||
end
|
end
|
||||||
|
|
|
||||||
19
lib/admin_rack.rb
Normal file
19
lib/admin_rack.rb
Normal file
|
|
@ -0,0 +1,19 @@
|
||||||
|
class AdminRack
|
||||||
|
def initialize(app)
|
||||||
|
@app = app
|
||||||
|
end
|
||||||
|
|
||||||
|
def call(env)
|
||||||
|
user = env['warden'].authenticate(:scope => :user)
|
||||||
|
if user && user.admin?
|
||||||
|
@app.call(env)
|
||||||
|
else
|
||||||
|
[307, {"Location" => '/'}, self]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def each(&block)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
Loading…
Reference in a new issue