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
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)
if arg
key = arg.shift
@ -214,27 +223,29 @@ module OrbitCoreLib
setup_vars
unless @no_authorization
if @user_type
@open = false
@visitor = false
@user_type.each do |user_type|
open = false
visitor = false
case user_type
when :admin
open ||= check_admin
@open ||= check_admin
when :manager
open ||= check_manager
@open ||= check_manager
when :sub_manager
open ||= check_sub_manager
@open ||= check_sub_manager
when :approver
open ||= check_sub_manager
@open ||= check_sub_manager
when :user
@open ||= true
when :visitor
set_current_user
open ||= true
visitor ||= true
@open ||= true
@visitor ||= true
end
check_backend_openness if visitor
authenticate_user! unless visitor
redirect_to root_url unless open
end
check_backend_openness if @visitor
authenticate_user! unless @visitor
redirect_to root_url unless @open
else
authenticate_user!
check_user_can_use