Sha256: 09f5ab31f191b5cfd6e7468fe8b728625879678541669702c375ccd65ffc6aee

Contents?: true

Size: 1.56 KB

Versions: 5

Compression:

Stored size: 1.56 KB

Contents

module Effective
  class PagesController < ApplicationController
    include Effective::CrudController

    def show
      @pages = Effective::Page.all
      @pages = @pages.published unless EffectiveResources.authorized?(self, :admin, :effective_pages)

      @page = @pages.find(params[:id])

      raise ActionController::RoutingError.new('Not Found') if @page.menu_root_with_children?

      if @page.authenticate_user? || @page.roles.present?
        authenticate_user!
      end

      raise Effective::AccessDenied.new('Access Denied', :show, @page) unless @page.roles_permit?(current_user)
      EffectiveResources.authorize!(self, :show, @page)

      @page_title = @page.title
      @meta_description = @page.meta_description
      @canonical_url = effective_pages.page_url(@page)

      if EffectiveResources.authorized?(self, :admin, :effective_pages)
        flash.now[:warning] = [
          'Hi Admin!',
          ('You are viewing a draft page.' unless @page.published?),
          ("<a href='#{effective_pages.edit_admin_page_path(@page)}' class='alert-link' data-turbolinks='false'>Click here to edit this page</a>.")
        ].compact.join(' ')
      end

      template = File.join(EffectivePages.pages_path, @page.template)
      layout = File.join(EffectivePages.layouts_path, @page.layout)

      respond_to do |format|
        format.html { render(template, layout: layout, locals: { page: @page }) }
      end
    end

    private

    def admin_edit?
      EffectiveResources.authorized?(self, :admin, :effective_pages) && (params[:edit].to_s == 'true')
    end

  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
effective_pages-3.8.3 app/controllers/effective/pages_controller.rb
effective_pages-3.8.2 app/controllers/effective/pages_controller.rb
effective_pages-3.8.1 app/controllers/effective/pages_controller.rb
effective_pages-3.8.0 app/controllers/effective/pages_controller.rb
effective_pages-3.7.11 app/controllers/effective/pages_controller.rb