Skip to content

Instantly share code, notes, and snippets.

@azuby
Created November 3, 2011 07:11
Show Gist options
  • Save azuby/1335962 to your computer and use it in GitHub Desktop.
Save azuby/1335962 to your computer and use it in GitHub Desktop.
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