Sha256: 1cd62d13c0c0512b13e72caca83310ea87c5259d0036a51b23d5d6dd3ca839c9

Contents?: true

Size: 1.99 KB

Versions: 4

Compression:

Stored size: 1.99 KB

Contents

module Knitkit
  class BaseController < ::ErpApp::ApplicationController
    before_filter :set_website, :clear_widget_params
    before_filter :set_login_path, :set_active_publication, :load_sections, :set_section, :except => [:view_current_publication]
    acts_as_themed_controller 

    layout 'knitkit/base'

    def website
      @website
    end

    def view_current_publication
      session[:website_version].delete_if{|item| item[:website_id] == @website.id}
      redirect_to request.env["HTTP_REFERER"]
    end
  
    protected
    def set_website
      @website = Website.find_by_host(request.host_with_port)
    end
    
    def load_sections
      @website_sections = @website.website_sections.positioned
    end

    def clear_widget_params
      session[:widgets] = {}
    end
    
    def set_section
      unless params[:section_id].nil?
        @website_section = WebsiteSection.find(params[:section_id])
        if @website_section.protected_with_capability?(:view)
          if !current_user and @website_section.path != @login_path
            redirect_to @login_path
          elsif current_user and !current_user.has_capability?(:view, @website_section)
            redirect_to Knitkit::Config.unauthorized_url
          end
        end
      else
        raise "No Id set"
      end
    end

    def set_login_path
      @login_path = @website.configurations.first.get_configuration_item(ConfigurationItemType.find_by_internal_identifier('login_url')).options.first.value
    end

    def set_active_publication
      @active_publication = @website.active_publication
      if !session[:website_version].blank? && !session[:website_version].empty?
        site_version_hash = session[:website_version].find{|item| item[:website_id] == @website.id}
        unless site_version_hash.nil?
          @active_publication = @website.published_websites.where('version = ?', site_version_hash[:version].to_f).first
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
knitkit-2.1.3 app/controllers/knitkit/base_controller.rb
knitkit-2.1.2 app/controllers/knitkit/base_controller.rb
knitkit-2.1.1 app/controllers/knitkit/base_controller.rb
knitkit-2.1.0 app/controllers/knitkit/base_controller.rb