Sha256: 17bebc64df33df6652dc1b779d1a043b55ca9033e1f488b6add97043352929be

Contents?: true

Size: 1.13 KB

Versions: 17

Compression:

Stored size: 1.13 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_type} #{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
        can :edit, User, :id => user.id
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
wheels-0.1.30 app/models/ability.rb
wheels-0.1.28 app/models/ability.rb
wheels-0.1.27 app/models/ability.rb
wheels-0.1.25 app/models/ability.rb
wheels-0.1.24 app/models/ability.rb
wheels-0.1.23 app/models/ability.rb
wheels-0.1.22 app/models/ability.rb
wheels-0.1.21 app/models/ability.rb
wheels-0.1.20 app/models/ability.rb
wheels-0.1.19 app/models/ability.rb
wheels-0.1.18 app/models/ability.rb
wheels-0.1.17 app/models/ability.rb
wheels-0.1.16 app/models/ability.rb
wheels-0.1.15 app/models/ability.rb
wheels-0.1.14 app/models/ability.rb
wheels-0.1.13 app/models/ability.rb
wheels-0.1.12 app/models/ability.rb