]> source.dussan.org Git - redmine.git/commitdiff
Handle the case of a text formatter that doesn't support section edit (#2222).
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Fri, 18 Nov 2011 16:41:54 +0000 (16:41 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Fri, 18 Nov 2011 16:41:54 +0000 (16:41 +0000)
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@7831 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/controllers/wiki_controller.rb
lib/redmine/wiki_formatting.rb
test/unit/lib/redmine/wiki_formatting.rb

index ba37a511f811a0927d71af782e19ff9d222fedec..b247867d10a03ad011e6f54c9f98ac039e33d837 100644 (file)
@@ -85,7 +85,10 @@ class WikiController < ApplicationController
       end
     end
     @editable = editable?
-    @sections_editable = @editable && User.current.allowed_to?(:edit_wiki_pages, @page.project) && params[:version].nil?
+    @sections_editable = @editable && User.current.allowed_to?(:edit_wiki_pages, @page.project) &&
+      params[:version].nil? &&
+      Redmine::WikiFormatting.supports_section_edit?
+
     render :action => 'show'
   end
 
@@ -103,7 +106,7 @@ class WikiController < ApplicationController
     @content.version = @page.content.version
     
     @text = @content.text
-    if params[:section].present?
+    if params[:section].present? && Redmine::WikiFormatting.supports_section_edit?
       @section = params[:section].to_i
       @text, @section_hash = Redmine::WikiFormatting.formatter.new(@text).get_section(@section)
       render_404 if @text.blank?
@@ -131,7 +134,7 @@ class WikiController < ApplicationController
     
     @content.comments = params[:content][:comments]
     @text = params[:content][:text]
-    if params[:section].present?
+    if params[:section].present? && Redmine::WikiFormatting.supports_section_edit?
       @section = params[:section].to_i
       @section_hash = params[:section_hash]
       @content.text = Redmine::WikiFormatting.formatter.new(@content.text).update_section(params[:section].to_i, @text, @section_hash)
index 2f25fe0e69dda6e9e0303b24a2808e769c9d635d..63f833dce33fec4aefb1c2f1af056a1c3ad455b9 100644 (file)
@@ -62,6 +62,11 @@ module Redmine
         text
       end
 
+      # Returns true if the text formatter supports single section edit
+      def supports_section_edit?
+        (formatter.instance_methods & ['update_section', :update_section]).any?
+      end
+
       # Returns a cache key for the given text +format+, +object+ and +attribute+ or nil if no caching should be done
       def cache_key_for(format, object, attribute)
         if object && attribute && !object.new_record? && object.respond_to?(:updated_on) && !format.blank?
index 606642e1f661ec2c58f069df5c7244a2232640af..909acdea753c838b8decf1f4e653c8b49f0694ab 100644 (file)
@@ -42,4 +42,14 @@ EXPECTED
 
     assert_equal expected.gsub(%r{[\r\n\t]}, ''), Redmine::WikiFormatting::NullFormatter::Formatter.new(raw).to_html.gsub(%r{[\r\n\t]}, '')
   end
+
+  def test_supports_section_edit
+    with_settings :text_formatting => 'textile' do
+      assert_equal true, Redmine::WikiFormatting.supports_section_edit?
+    end
+    
+    with_settings :text_formatting => '' do
+      assert_equal false, Redmine::WikiFormatting.supports_section_edit?
+    end
+  end
 end