Sha256: 77d3eca054cfcdab5b5399d71d94c95d55eb20a577fe4cb3257930d34b3bb0a8

Contents?: true

Size: 1.96 KB

Versions: 7

Compression:

Stored size: 1.96 KB

Contents

class Manage::CmsTemplatesController < Manage::ApplicationController
  before_action :check_permissions
  before_action :block_basic_users

  cache_sweeper :cms_content_sweeper
  
  def index
    @cms_templates = CmsTemplate.order(:name)
  end

  def new
    @cms_template = CmsTemplate.new
    render action: 'edit'
  end
  
  def create
    @cms_template = CmsTemplate.new
    update
  end

  def edit
    @cms_template = CmsTemplate.find(params[:id])
  end

  def update
    @cms_template ||= CmsTemplate.find(params[:id])
    @cms_template.assign_attributes(cms_template_params)
    
    begin
      puts Cms::ContentController.renderer.new('action_dispatch.request.path_parameters' => {
        controller: '/cms/content', action: 'show', id: @cms_template.pages.last || CmsPage.new }).render inline: @cms_template.content
    rescue ScriptError, StandardError => e
      flash.now[:error] = "<pre title=\"#{ERB::Util.html_escape(e.backtrace.join("\n"))}\">#{ERB::Util.html_escape(e.message)}</pre>".html_safe
      render action: 'edit' and return
    end
    
    # this must come after the render_to_string so that we capture template
    # options embedded in snippets
    @cms_template.options = @cms_template_options
    
    if !@cms_template.save
      flash.now[:error] = @cms_template.errors.full_messages.join('<br>').html_safe
      render action: 'edit'
    else
      flash[:notice] = 'Template saved.'
      redirect_to action: 'edit', id: @cms_template
    end
  end

  protected

    def check_permissions
      if !user_has_permission?(:manage_cms)
        render '/imagine_cms/errors/permission_denied', layout: false
        return false
      end
    end

    def block_basic_users
      return true unless UseCmsAccessLevels
      unless user_has_permission?(:manage_cms_full_access)
        render '/imagine_cms/errors/permission_denied'
        return false
      end
    end

    def cms_template_params
      params.require(:cms_template).permit(:name, :content)
    end
    
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
imagine_cms-5.2.6 app/controllers/manage/cms_templates_controller.rb
imagine_cms-5.2.5 app/controllers/manage/cms_templates_controller.rb
imagine_cms-5.2.4 app/controllers/manage/cms_templates_controller.rb
imagine_cms-5.2.3 app/controllers/manage/cms_templates_controller.rb
imagine_cms-5.2.2 app/controllers/manage/cms_templates_controller.rb
imagine_cms-5.2.1 app/controllers/manage/cms_templates_controller.rb
imagine_cms-5.2.0 app/controllers/manage/cms_templates_controller.rb