Sha256: 352715b7d6663b3dc0969c2cff413ccadfd90951beea5671f19ecbae891c1d23

Contents?: true

Size: 1.14 KB

Versions: 6

Compression:

Stored size: 1.14 KB

Contents

class Ability
  include CanCan::Ability

  def initialize(user)
    if !user.nil? and (user.admin? or user.manager?)
      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

      can :index, :all
      can :read, :all
      can :history, :all
      can :export, :all

      can :comments, :all         #RailsAdminComments::Comments
      can :model_comments, :all   #RailsAdminComments::ModelComments

      user.ability.to_cancancan(self) if user.respond_to?(:ability) and user.ability

      if defined?(RailsAdminUserAbilities)
        cannot :manage, RailsAdminUserAbilities::UserAbility
      end
    end
  end

  def admin_ui(user)
    can :manage, :all
    can :manage, User
    can :user_abilities, User

    Enjoy.cancancan_admin_rules self
  end

  def manager_ui(user)
    can :read, :all
    can :show, :all
    cannot [:edit, :destroy, :new, :create], User
    can :edit, User, _id: user._id
    cannot :user_abilities, :all

    Enjoy.cancancan_manager_rules self
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
enjoy_cms-0.4.0.5 lib/generators/enjoy/cms/templates/ability.erb
enjoy_cms-0.4.0.4 lib/generators/enjoy/cms/templates/ability.erb
enjoy_cms-0.4.0.3 lib/generators/enjoy/cms/templates/ability.erb
enjoy_cms-0.4.0.2 lib/generators/enjoy/cms/templates/ability.erb
enjoy_cms-0.4.0.1 lib/generators/enjoy/cms/templates/ability.erb
enjoy_cms-0.4.0 lib/generators/enjoy/cms/templates/ability.erb