Sha256: f480f4d564da262c4a7162d55029f032f99217d67ab5b4043fd5438e1a2a1456

Contents?: true

Size: 1.13 KB

Versions: 42

Compression:

Stored size: 1.13 KB

Contents

# note: role inheritence implemented via Ryan Bates' method
# outlined in https://github.com/ryanb/cancan/wiki/Role-Based-Authorization
module Virgo
  class Ability
    include CanCan::Ability

    def initialize(user)
      @user = user || User.new # for guest

      send(@user.role) if @user.role.present?
    end

    def anonymous
      can :read, Post do |post|
        post.published? && post.live
      end
    end

    def normal
      anonymous
    end

    def editor
      can :manage, :all
      can :manage, Virgo::User do |u|
        u == @user
      end
      cannot :index, Virgo::User
    end

    def contributor
      can :manage, Virgo::Post do |post|
        post.author == @user
      end

      can :manage, Virgo::Slideshow do |slideshow|
        slideshow.author == @user
      end

      can :manage, Virgo::Slide do |slide|
        can?(:manage, slide.slideshow)
      end

      can :read, Virgo::Post

      cannot :manage, Virgo::User
      cannot :manage, Virgo::Column
      cannot :manage, Virgo::Site
    end

    def admin
      can :manage, :all
    end

    def superuser
      can :manage, :all
    end
  end
end

Version data entries

42 entries across 42 versions & 1 rubygems

Version Path
virgo-0.3.17 app/models/virgo/ability.rb
virgo-0.3.16 app/models/virgo/ability.rb
virgo-0.3.15 app/models/virgo/ability.rb
virgo-0.3.14 app/models/virgo/ability.rb
virgo-0.3.13 app/models/virgo/ability.rb
virgo-0.3.12 app/models/virgo/ability.rb
virgo-0.3.11 app/models/virgo/ability.rb
virgo-0.3.10 app/models/virgo/ability.rb
virgo-0.3.9 app/models/virgo/ability.rb
virgo-0.3.8 app/models/virgo/ability.rb
virgo-0.3.7 app/models/virgo/ability.rb
virgo-0.3.6 app/models/virgo/ability.rb
virgo-0.3.4 app/models/virgo/ability.rb
virgo-0.3.3 app/models/virgo/ability.rb
virgo-0.3.2 app/models/virgo/ability.rb
virgo-0.3.1 app/models/virgo/ability.rb
virgo-0.3 app/models/virgo/ability.rb
virgo-0.2.9 app/models/virgo/ability.rb
virgo-0.2.8 app/models/virgo/ability.rb
virgo-0.2.7 app/models/virgo/ability.rb