Sha256: 172463ee641d7fb5ac8cb3984eee388832e131a8ef60e9f8434f42a4221458c3

Contents?: true

Size: 1.58 KB

Versions: 15

Compression:

Stored size: 1.58 KB

Contents

class ReaderPage < Page
  include WillPaginate::ViewHelpers
  attr_accessor :reader, :group
  
  description %{ Presents readers and groups with configurable access control. }
  
  def current_reader
    Reader.current
  end
  
  def readers
    if group
      group.readers.visible_to(current_reader)
    else
      Reader.visible_to(current_reader)
    end
  end
  
  def groups
    Group.visible_to(current_reader)
  end
    
  def cache?
    public?
  end
  
  def public?
    Radiant.config['reader.directory_visibility'] == 'public'
  end
  
  def visible?
    public? || current_reader
  end
  
  def url_for(thing)
    if thing.is_a?(Reader)
      File.join(self.url, thing.id)
    elsif thing.is_a?(Group)
      File.join(self.url, thing.slug)
    end
  end
  
  def find_by_url(url, live = true, clean = false)
    url = clean_url(url) if clean
    my_url = self.url
    return false unless url =~ /^#{Regexp.quote(my_url)}(.*)/
    raise ReaderError::AccessDenied unless visible?
    
    params = $1.split('/').compact
    self.group = Group.find_by_slug(params.first) if params.first =~ /\w/
    self.reader = Reader.find_by_id(params.last) if params.last !~ /\D/

    raise ReaderError::AccessDenied, "Group visibility denied" if group && !group.visible_to?(current_reader)
    raise ReaderError::AccessDenied, "Reader visibility denied: #{current_reader} (#{current_reader.preferred_name}) cannot see #{reader} (#{reader.preferred_name})" if reader && !reader.visible_to?(current_reader)
    raise ActiveRecord::RecordNotFound if reader && group && !reader.has_group?(group)

    self
  end
  
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
radiant-reader-extension-3.0.38 app/models/reader_page.rb
radiant-reader-extension-3.0.37 app/models/reader_page.rb
radiant-reader-extension-3.0.36 app/models/reader_page.rb
radiant-reader-extension-3.0.35 app/models/reader_page.rb
radiant-reader-extension-3.0.33 app/models/reader_page.rb
radiant-reader-extension-3.0.32 app/models/reader_page.rb
radiant-reader-extension-3.0.31 app/models/reader_page.rb
radiant-reader-extension-3.0.30 app/models/reader_page.rb
radiant-reader-extension-3.0.29 app/models/reader_page.rb
radiant-reader-extension-3.0.28 app/models/reader_page.rb
radiant-reader-extension-3.0.27 app/models/reader_page.rb
radiant-reader-extension-3.0.26 app/models/reader_page.rb
radiant-reader-extension-3.0.25 app/models/reader_page.rb
radiant-reader-extension-3.0.24 app/models/reader_page.rb
radiant-reader-extension-3.0.23 app/models/reader_page.rb