Sha256: 8b16001cba1a28cb0d100f1aa82fd598ad0626afdfdaac7db9ca70cb0c55d569

Contents?: true

Size: 973 Bytes

Versions: 3

Compression:

Stored size: 973 Bytes

Contents

class Ability
  include CanCan::Ability

  def initialize(user)
    if !user.nil? and (user.admin? or user.manager?)
      can :read, :all
      can :access, :rails_admin   # grant access to rails_admin
      can :dashboard              # grant access to the dashboard

      if user.admin?
        admin_ui(user)
      elsif user.manager?
        manager_ui(user)
      end

      cannot [:new, :create], Enjoy::Seo
      cannot [:new, :create], Enjoy::SitemapData
    end
  end

  def admin_ui(user)
    can :manage, :all
  end

  def manager_ui(user)
    cannot :manage, Enjoy::Menu
    cannot [:edit, :destroy, :new, :create], User
    can :edit, user

    manager_models.each do |model|
      can manager_actions, model
    end
  end

  def manager_actions
    [:edit, :new, :create, :nested_set, :sort_embedded]
  end

  def manager_models
    [
      Enjoy::Page, Enjoy::News,
      Enjoy::Seo, Enjoy::SitemapData,
      RailsAdminSettings::Settings
    ]
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
enjoy_cms-0.3.1.2 lib/generators/enjoy/templates/ability.erb
enjoy_cms-0.3.1.1 lib/generators/enjoy/templates/ability.erb
enjoy_cms-0.3.1 lib/generators/enjoy/templates/ability.erb