Created
November 3, 2011 07:11
-
-
Save azuby/1335962 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def initialize(user) | |
if !user.nil? && !user.role.nil? | |
if user.company_id == 1 # if internal employee | |
can :manage, :all | |
else # if consumer | |
user.permissions.each do |permission| | |
if permission.is_internal? | |
# NEEDS CHECK FOR WHETHER permission.subject_class.constantize has user or users that equal user.id OR user.subordinates.find(ID) | |
can permission.action.to_sym, permission.subject_class.constantize, | |
:company => { :id => user.company_id} | |
else | |
can permission.action.to_sym, permission.subject_class.constantize | |
end | |
end # permissions iterator | |
end # if syncin employee | |
end # if no user | |
end # initialize |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment