diff app/models/wiki_page.rb @ 441:cbce1fd3b1b7 redmine-1.2

Update to Redmine 1.2-stable branch (Redmine SVN rev 6000)
author Chris Cannam
date Mon, 06 Jun 2011 14:24:13 +0100
parents 051f544170fe
children 0c939c159af4
line wrap: on
line diff
--- a/app/models/wiki_page.rb	Thu Mar 03 11:42:28 2011 +0000
+++ b/app/models/wiki_page.rb	Mon Jun 06 14:24:13 2011 +0100
@@ -32,6 +32,7 @@
 
   acts_as_searchable :columns => ['title', 'text'],
                      :include => [{:wiki => :project}, :content],
+                     :permission => :view_wiki_pages,
                      :project_key => "#{Wiki.table_name}.project_id"
 
   attr_accessor :redirect_existing_links
@@ -41,6 +42,12 @@
   validates_uniqueness_of :title, :scope => :wiki_id, :case_sensitive => false
   validates_associated :content
   
+  # eager load information about last updates, without loading text
+  named_scope :with_updated_on, {
+    :select => "#{WikiPage.table_name}.*, #{WikiContent.table_name}.updated_on",
+    :joins => "LEFT JOIN #{WikiContent.table_name} ON #{WikiContent.table_name}.page_id = #{WikiPage.table_name}.id"
+  }
+  
   # Wiki pages that are protected by default
   DEFAULT_PROTECTED_PAGES = %w(sidebar)
   
@@ -121,6 +128,18 @@
     content.text if content
   end
   
+  def updated_on
+    unless @updated_on
+      if time = read_attribute(:updated_on)
+        # content updated_on was eager loaded with the page
+        @updated_on = Time.parse(time) rescue nil
+      else
+        @updated_on = content && content.updated_on
+      end
+    end
+    @updated_on
+  end
+  
   # Returns true if usr is allowed to edit the page, otherwise false
   def editable_by?(usr)
     !protected? || usr.allowed_to?(:protect_wiki_pages, wiki.project)