Sha256: 96e35c9ad2ba4aa067f54bc1a9bd4a95b053679ef03ae425a4436191d57af5cb

Contents?: true

Size: 788 Bytes

Versions: 7

Compression:

Stored size: 788 Bytes

Contents

class Ability
  include CanCan::Ability

  def initialize(user)
    alias_action :destroy, to: :delete

    @user = user

    if @user
      case @user.user_role_type.id
        when ::UserRoleType.default.id then default
        when ::UserRoleType.redactor.id then redactor
        when ::UserRoleType.moderator.id then moderator
        when ::UserRoleType.admin.id then admin
      end
    else
      guest
    end
  end

  def guest
  end

  def default
    guest
  end

  def redactor
    default
  end

  def moderator
    default
    can :manage, Dashboard
    can [:read, :create], AdminComment
    can :destroy, AdminComment, author_id: @user.id
    cannot :destroy, User, id: @user.id
  end

  def admin
    can :manage, :all

    cannot :destroy, User, id: @user.id
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
ab_admin-0.3.6 lib/generators/ab_admin/install/templates/models/ability.rb
ab_admin-0.3.5 lib/generators/ab_admin/install/templates/models/ability.rb
ab_admin-0.3.4 lib/generators/ab_admin/install/templates/models/ability.rb
ab_admin-0.3.3 lib/generators/ab_admin/install/templates/models/ability.rb
ab_admin-0.3.2 lib/generators/ab_admin/install/templates/models/ability.rb
ab_admin-0.3.1 lib/generators/ab_admin/install/templates/models/ability.rb
ab_admin-0.3.0 lib/generators/ab_admin/install/templates/models/ability.rb