Sha256: 5104b9d7da47f91b0bd12ee314c031c19becf45ebbc4de722bfebee0abdf40f7

Contents?: true

Size: 1.12 KB

Versions: 5

Compression:

Stored size: 1.12 KB

Contents

module SiteControllerExtensions
  
  def self.included(base)
    base.class_eval {
      # to control access without ruining the cache we have set Page.cache? = false
      # for any page that has a group association. This should  prevent the relatively 
      # few private pages from being cached, and it remains safe to return any cached
      # page we find.
      
      def find_page_with_group_check(url)
        page = find_page_without_group_check(url)
        raise ReaderGroup::PermissionDenied if page && !page.visible_to?(current_reader)
        page
      end
        
      def show_page_with_group_check
        show_page_without_group_check
      rescue ReaderGroup::PermissionDenied
        if current_reader
          flash[:error] = "sorry_access_denied"
          redirect_to reader_permission_denied_url
        else
          flash[:explanation] = "page_not_public"
          flash[:error] = "please_log_in"
          store_location
          redirect_to reader_login_url
        end
      end
        
      alias_method_chain :find_page, :group_check
      alias_method_chain :show_page, :group_check
    }
  end
end



Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
radiant-reader_group-extension-1.1.2 lib/site_controller_extensions.rb
radiant-reader_group-extension-1.1.1 lib/site_controller_extensions.rb
radiant-reader_group-extension-1.1.0 lib/site_controller_extensions.rb
radiant-reader_group-extension-1.0.1 lib/site_controller_extensions.rb
radiant-reader_group-extension-1.0.0 lib/site_controller_extensions.rb