Sha256: 1e208837e09061c274503f4793b4eca461422ab5e48916df2af5b0e0de81cfb3

Contents?: true

Size: 1.71 KB

Versions: 19

Compression:

Stored size: 1.71 KB

Contents

# Create a generator for an override file for this class
# sample below:
# class Ability < CmsAbility
#
#   def setup_role(role_detail, user)
#     if role_detail.command.eql?('contents.blog')
#       can :manage, Blog
#     else
#       warn "#{ role_detail.command } is not yet handled."
#     end
#   end
#
# end
class CmsAbility
  include CanCan::Ability

  def initialize(user)

    if user
      if user.type.eql?(:super_user)
        can :manage, :all
      else
        if user.role && user.role.role_details
          user.role.role_details.each do |role_detail|
            can :view, role_detail.command if role_detail.can_view?
            can :manage, role_detail.command if role_detail.can_manage?

            if role_detail.can_manage?
              case role_detail.command
                when 'settings.roles'
                  can :manage, Cms::Fortress::Role, site_id: user.site_id
                when 'settings.sites'
                  can :update, Comfy::Cms::Site, site_id: user.site_id
                when 'settings.users'
                  can :manage, Cms::Fortress::User, site_id: user.site_id
                when 'contents.pages'
                  can :manage, Comfy::Cms::Page, site_id: user.site_id
                when 'contents.files'
                  can :manage, Comfy::Cms::File, site_id: user.site_id
                when 'designs.layouts'
                  can :manage, Comfy::Cms::Layout, site_id: user.site_id
                when 'designs.snippets'
                  can :manage, Comfy::Cms::Snippet, site_id: user.site_id
                else
                  setup_role(role_detail, user) if defined?(setup_role)
              end
            end
          end
        end
      end

    end

  end

end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
cms-fortress-1.3.15 app/models/cms_ability.rb
cms-fortress-1.3.14 app/models/cms_ability.rb
cms-fortress-1.3.13 app/models/cms_ability.rb
cms-fortress-1.3.12 app/models/cms_ability.rb
cms-fortress-1.3.11 app/models/cms_ability.rb
cms-fortress-1.3.10 app/models/cms_ability.rb
cms-fortress-1.3.9 app/models/cms_ability.rb
cms-fortress-1.3.8 app/models/cms_ability.rb
cms-fortress-1.3.7 app/models/cms_ability.rb
cms-fortress-1.3.6 app/models/cms_ability.rb
cms-fortress-1.3.5 app/models/cms_ability.rb
cms-fortress-1.3.4 app/models/cms_ability.rb
cms-fortress-1.3.3 app/models/cms_ability.rb
cms-fortress-1.3.2 app/models/cms_ability.rb
cms-fortress-1.3.1 app/models/cms_ability.rb
cms-fortress-1.3.0 app/models/cms_ability.rb
cms-fortress-1.3.0.rc3 app/models/cms_ability.rb
cms-fortress-1.3.0.rc2 app/models/cms_ability.rb
cms-fortress-1.3.0.rc1 app/models/cms_ability.rb