##// END OF EJS Templates
Show long text custom field changes as a diff (#15236)....
Jean-Philippe Lang -
r13572:e11f77a4b038
parent child
Show More
@@ -49,9 +49,17 class JournalsController < ApplicationController
49 if params[:detail_id].present?
49 if params[:detail_id].present?
50 @detail = @journal.details.find_by_id(params[:detail_id])
50 @detail = @journal.details.find_by_id(params[:detail_id])
51 else
51 else
52 @detail = @journal.details.detect {|d| d.prop_key == 'description'}
52 @detail = @journal.details.detect {|d| d.property == 'attr' && d.prop_key == 'description'}
53 end
54 unless @issue && @detail
55 render_404
56 return false
57 end
58 if @detail.property == 'cf'
59 unless @detail.custom_field && @detail.custom_field.visible_by?(@issue.project, User.current)
60 raise ::Unauthorized
61 end
53 end
62 end
54 (render_404; return false) unless @issue && @detail
55 @diff = Redmine::Helpers::Diff.new(@detail.value, @detail.old_value)
63 @diff = Redmine::Helpers::Diff.new(@detail.value, @detail.old_value)
56 end
64 end
57
65
@@ -294,6 +294,8 module IssuesHelper
294 # Returns the textual representation of a single journal detail
294 # Returns the textual representation of a single journal detail
295 def show_detail(detail, no_html=false, options={})
295 def show_detail(detail, no_html=false, options={})
296 multiple = false
296 multiple = false
297 show_diff = false
298
297 case detail.property
299 case detail.property
298 when 'attr'
300 when 'attr'
299 field = detail.prop_key.to_s.gsub(/\_id$/, "")
301 field = detail.prop_key.to_s.gsub(/\_id$/, "")
@@ -320,14 +322,21 module IssuesHelper
320 when 'is_private'
322 when 'is_private'
321 value = l(detail.value == "0" ? :general_text_No : :general_text_Yes) unless detail.value.blank?
323 value = l(detail.value == "0" ? :general_text_No : :general_text_Yes) unless detail.value.blank?
322 old_value = l(detail.old_value == "0" ? :general_text_No : :general_text_Yes) unless detail.old_value.blank?
324 old_value = l(detail.old_value == "0" ? :general_text_No : :general_text_Yes) unless detail.old_value.blank?
325
326 when 'description'
327 show_diff = true
323 end
328 end
324 when 'cf'
329 when 'cf'
325 custom_field = detail.custom_field
330 custom_field = detail.custom_field
326 if custom_field
331 if custom_field
327 multiple = custom_field.multiple?
328 label = custom_field.name
332 label = custom_field.name
329 value = format_value(detail.value, custom_field) if detail.value
333 if custom_field.format.class.change_as_diff
330 old_value = format_value(detail.old_value, custom_field) if detail.old_value
334 show_diff = true
335 else
336 multiple = custom_field.multiple?
337 value = format_value(detail.value, custom_field) if detail.value
338 old_value = format_value(detail.old_value, custom_field) if detail.old_value
339 end
331 end
340 end
332 when 'attachment'
341 when 'attachment'
333 label = l(:label_attachment)
342 label = l(:label_attachment)
@@ -373,7 +382,7 module IssuesHelper
373 end
382 end
374 end
383 end
375
384
376 if detail.property == 'attr' && detail.prop_key == 'description'
385 if show_diff
377 s = l(:text_journal_changed_no_detail, :label => label)
386 s = l(:text_journal_changed_no_detail, :label => label)
378 unless no_html
387 unless no_html
379 diff_link = link_to 'diff',
388 diff_link = link_to 'diff',
@@ -70,6 +70,9 module Redmine
70 class_attribute :form_partial
70 class_attribute :form_partial
71 self.form_partial = nil
71 self.form_partial = nil
72
72
73 class_attribute :change_as_diff
74 self.change_as_diff = false
75
73 def self.add(name)
76 def self.add(name)
74 self.format_name = name
77 self.format_name = name
75 Redmine::FieldFormat.add(name, self)
78 Redmine::FieldFormat.add(name, self)
@@ -293,6 +296,7 module Redmine
293 add 'text'
296 add 'text'
294 self.searchable_supported = true
297 self.searchable_supported = true
295 self.form_partial = 'custom_fields/formats/text'
298 self.form_partial = 'custom_fields/formats/text'
299 self.change_as_diff = true
296
300
297 def formatted_value(view, custom_field, value, customized=nil, html=false)
301 def formatted_value(view, custom_field, value, customized=nil, html=false)
298 if html
302 if html
@@ -51,7 +51,7 class JournalsControllerTest < ActionController::TestCase
51 assert_not_include journal, assigns(:journals)
51 assert_not_include journal, assigns(:journals)
52 end
52 end
53
53
54 def test_diff
54 def test_diff_for_description_change
55 get :diff, :id => 3, :detail_id => 4
55 get :diff, :id => 3, :detail_id => 4
56 assert_response :success
56 assert_response :success
57 assert_template 'diff'
57 assert_template 'diff'
@@ -60,6 +60,30 class JournalsControllerTest < ActionController::TestCase
60 assert_select 'span.diff_in', :text => /added/
60 assert_select 'span.diff_in', :text => /added/
61 end
61 end
62
62
63 def test_diff_for_custom_field
64 field = IssueCustomField.create!(:name => "Long field", :field_format => 'text')
65 journal = Journal.create!(:journalized => Issue.find(2), :notes => 'Notes', :user_id => 1)
66 detail = JournalDetail.create!(:journal => journal, :property => 'cf', :prop_key => field.id,
67 :old_value => 'Foo', :value => 'Bar')
68
69 get :diff, :id => journal.id, :detail_id => detail.id
70 assert_response :success
71 assert_template 'diff'
72
73 assert_select 'span.diff_out', :text => /Foo/
74 assert_select 'span.diff_in', :text => /Bar/
75 end
76
77 def test_diff_for_custom_field_should_be_denied_if_custom_field_is_not_visible
78 field = IssueCustomField.create!(:name => "Long field", :field_format => 'text', :visible => false, :role_ids => [1])
79 journal = Journal.create!(:journalized => Issue.find(2), :notes => 'Notes', :user_id => 1)
80 detail = JournalDetail.create!(:journal => journal, :property => 'cf', :prop_key => field.id,
81 :old_value => 'Foo', :value => 'Bar')
82
83 get :diff, :id => journal.id, :detail_id => detail.id
84 assert_response 302
85 end
86
63 def test_diff_should_default_to_description_diff
87 def test_diff_should_default_to_description_diff
64 get :diff, :id => 3
88 get :diff, :id => 3
65 assert_response :success
89 assert_response :success
@@ -203,12 +203,25 class IssuesHelperTest < ActionView::TestCase
203 assert_match '6.30', show_detail(detail, true)
203 assert_match '6.30', show_detail(detail, true)
204 end
204 end
205
205
206 test 'show_detail should not show values with a description attribute' do
207 detail = JournalDetail.new(:property => 'attr', :prop_key => 'description',
208 :old_value => 'Foo', :value => 'Bar')
209 assert_equal 'Description updated', show_detail(detail, true)
210 end
211
206 test 'show_detail should show old and new values with a custom field' do
212 test 'show_detail should show old and new values with a custom field' do
207 detail = JournalDetail.new(:property => 'cf', :prop_key => '1',
213 detail = JournalDetail.new(:property => 'cf', :prop_key => '1',
208 :old_value => 'MySQL', :value => 'PostgreSQL')
214 :old_value => 'MySQL', :value => 'PostgreSQL')
209 assert_equal 'Database changed from MySQL to PostgreSQL', show_detail(detail, true)
215 assert_equal 'Database changed from MySQL to PostgreSQL', show_detail(detail, true)
210 end
216 end
211
217
218 test 'show_detail should not show values with a long text custom field' do
219 field = IssueCustomField.create!(:name => "Long field", :field_format => 'text')
220 detail = JournalDetail.new(:property => 'cf', :prop_key => field.id,
221 :old_value => 'Foo', :value => 'Bar')
222 assert_equal 'Long field updated', show_detail(detail, true)
223 end
224
212 test 'show_detail should show added file' do
225 test 'show_detail should show added file' do
213 detail = JournalDetail.new(:property => 'attachment', :prop_key => '1',
226 detail = JournalDetail.new(:property => 'attachment', :prop_key => '1',
214 :old_value => nil, :value => 'error281.txt')
227 :old_value => nil, :value => 'error281.txt')
General Comments 0
You need to be logged in to leave comments. Login now