Sha256: 053de67799abc5a0d80639112c23322dce063e0f03da8370bda5dbd7eca42fde

Contents?: true

Size: 777 Bytes

Versions: 12

Compression:

Stored size: 777 Bytes

Contents

class Ability
  include CanCanNamespace::Ability
  
  attr_accessor :context, :user

  def initialize(user, context = nil)
    alias_action :delete, :to => :destroy

    @user = (user || User.new) # guest user (not logged in)
    @context = context
    
    case @user.role_type_id
      when RoleType.default.id then default
      when RoleType.redactor.id then redactor
      when RoleType.moderator.id then moderator
      when RoleType.admin.id then admin
    end
  end
  
  def default
    # TODO
  end
  
  def redactor
    # TODO
  end
  
  def moderator
    # TODO
  end
  
  def admin
    can :manage, :all
    can :manage, :all, :context => :manage
    
    # User cannot destroy self account
    cannot :destroy, User, :id => @user.id, :context => :manage
  end
end

Version data entries

12 entries across 10 versions & 4 rubygems

Version Path
sunrise-core-0.2.2 lib/generators/sunrise/templates/models/defaults/ability.rb
sunrise-core-0.2.1 lib/generators/sunrise/templates/models/defaults/ability.rb
sunrise-core-0.2.1 spec/tmp/app/models/defaults/ability.rb
sunrise-widgets-0.1.1 spec/dummy/app/models/defaults/ability.rb
sunrise-locales-0.1.0 spec/dummy/app/models/defaults/ability.rb
sunrise-core-0.2.0 spec/tmp/app/models/defaults/ability.rb
sunrise-core-0.2.0 lib/generators/sunrise/templates/models/defaults/ability.rb
sunrise-widgets-0.1.0 spec/dummy/app/models/defaults/ability.rb
sunrise-questions-0.1.0 spec/dummy/app/models/defaults/ability.rb
sunrise-core-0.1.5 lib/generators/sunrise/templates/models/defaults/ability.rb
sunrise-core-0.1.4 lib/generators/sunrise/templates/models/defaults/ability.rb
sunrise-core-0.1.3 lib/generators/sunrise/templates/models/defaults/ability.rb