Fix bug in open_for, it now takes all the open_for into account

Add open_for_user
This commit is contained in:
chris 2013-10-17 14:20:49 +08:00
parent a67be030c5
commit 7b1b1fa2d3
1 changed files with 22 additions and 11 deletions

View File

@ -188,6 +188,15 @@ module OrbitCoreLib
end end
end end
def open_for_user(arg = nil)
if arg
key = arg.shift
prepend_before_filter key[0] => key[1] {|f| f.open_for :user}
else
prepend_before_filter {|f| f.open_for :user}
end
end
def open_for_visitor(arg = nil) def open_for_visitor(arg = nil)
if arg if arg
key = arg.shift key = arg.shift
@ -214,27 +223,29 @@ module OrbitCoreLib
setup_vars setup_vars
unless @no_authorization unless @no_authorization
if @user_type if @user_type
@open = false
@visitor = false
@user_type.each do |user_type| @user_type.each do |user_type|
open = false
visitor = false
case user_type case user_type
when :admin when :admin
open ||= check_admin @open ||= check_admin
when :manager when :manager
open ||= check_manager @open ||= check_manager
when :sub_manager when :sub_manager
open ||= check_sub_manager @open ||= check_sub_manager
when :approver when :approver
open ||= check_sub_manager @open ||= check_sub_manager
when :user
@open ||= true
when :visitor when :visitor
set_current_user set_current_user
open ||= true @open ||= true
visitor ||= true @visitor ||= true
end end
check_backend_openness if visitor
authenticate_user! unless visitor
redirect_to root_url unless open
end end
check_backend_openness if @visitor
authenticate_user! unless @visitor
redirect_to root_url unless @open
else else
authenticate_user! authenticate_user!
check_user_can_use check_user_can_use