Sha256: cfb55f141589e01149233222c7b342d430ad8e69672a84f6c58ef33b90c8efc0

Contents?: true

Size: 1.13 KB

Versions: 12

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 :manage, User, :id => user.id
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
wheels-0.1.10 app/models/ability.rb
wheels-0.1.9 app/models/ability.rb
wheels-0.1.8 app/models/ability.rb
wheels-0.1.7 app/models/ability.rb
wheels-0.1.6 app/models/ability.rb
wheels-0.1.5 app/models/ability.rb
wheels-0.1.4 app/models/ability.rb
wheels-0.1.3 app/models/ability.rb
wheels-0.1.2 app/models/ability.rb
wheels-0.1.1 app/models/ability.rb
wheels-0.1.0 app/models/ability.rb
wheels-0.0.49 app/models/ability.rb