Sha256: ba24cf690f581ff25d0da7a3258823d8a4047532c4c313bdc6a05fee58d3c59b

Contents?: true

Size: 1.09 KB

Versions: 22

Compression:

Stored size: 1.09 KB

Contents

class Ability
  include CanCan::Ability
  def self.initializers
    @initializers ||= []
  end

  def self.initializer(*method_names)
    method_names.each{|t| initializers << t}
  end
  initializer :init_wheels

  def initialize(user)
    user ||= User.nobody
    puts all_aces_for(user).map{|t| "#{t.resource_class_name} #{t.options.inspect}"}.join("\n")
    self.class.initializers.each{|t| self.send(t, user)}
    all_aces_for(user).each do |ace|
      ace.configure(self)
    end
  end

  def all_aces_for(user)
    (user.access_control_entries + user.role.access_control_entries)
  end

  def init_wheels(user)
    can :read, :all
    roles = Role.all
    def roles.find_by_name(name); self.select{|t| t.name==name}[0]; end;
    case user.role.id
      when roles.find_by_name("Super").id
        can :manage, :all
      when roles.find_by_name("Admin").id
        can :manage, :all
      when roles.find_by_name("User").id
        can :manage, Gallery, :user_id => user.id
        can :manage, Blog, :user_id => user.id
        can :edit, Profile, :user_id => user.id
        cannot :read, User
    end
  end
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
wheels-0.0.48 app/models/ability.rb
wheels-0.0.47 app/models/ability.rb
wheels-0.0.46 app/models/ability.rb
wheels-0.0.45 app/models/ability.rb
wheels-0.0.44 app/models/ability.rb
wheels-0.0.43 app/models/ability.rb
wheels-0.0.42 app/models/ability.rb
wheels-0.0.41 app/models/ability.rb
wheels-0.0.40 app/models/ability.rb
wheels-0.0.39 app/models/ability.rb
wheels-0.0.38 app/models/ability.rb
wheels-0.0.37 app/models/ability.rb
wheels-0.0.36 app/models/ability.rb
wheels-0.0.35 app/models/ability.rb
wheels-0.0.34 app/models/ability.rb
wheels-0.0.33 app/models/ability.rb
wheels-0.0.32 app/models/ability.rb
wheels-0.0.31 app/models/ability.rb
wheels-0.0.30 app/models/ability.rb
wheels-0.0.29 app/models/ability.rb