Module: SiteControllerExtensions

Defined in:
lib/site_controller_extensions.rb

Class Method Summary collapse

Class Method Details

.included(base) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/site_controller_extensions.rb', line 3

def self.included(base)
  base.class_eval {
    rescue_from ReaderError::AccessDenied, :with => :access_denied
    rescue_from ReaderError::LoginRequired, :with => :login_required
    rescue_from ReaderError::ActivationRequired, :with => :activation_required
    
    # NB. to control access without disabling the cache we have overridden Page.cache? 
    # to return false for any page that has a group association.
    
    def find_page_with_group_check(path)
      page = find_page_without_group_check(path)
      if page && page.restricted?
        raise ReaderError::LoginRequired, t("reader_extension.page_not_public") unless current_reader
        raise ReaderError::ActivationRequired, t("reader_extension.page_not_public") unless current_reader.activated?
        raise ReaderError::AccessDenied, t("reader_extension.page_permission_denied") unless page.visible_to?(current_reader)
      end
      page
    end
    alias_method_chain :find_page, :group_check
  }
end