]> source.dussan.org Git - redmine.git/commitdiff
Fixed that standard fields disabled still appear in email notifications (#14584).
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Mon, 5 Aug 2013 17:08:26 +0000 (17:08 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Mon, 5 Aug 2013 17:08:26 +0000 (17:08 +0000)
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@12079 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/helpers/issues_helper.rb
app/views/mailer/_issue.html.erb
app/views/mailer/_issue.text.erb
test/unit/mailer_test.rb

index 2e45d2e976ec4fee9970107e6c238222754d7fe4..bc7fbab854377a8077cb715fdacdc1ea95260728 100644 (file)
@@ -231,6 +231,28 @@ module IssuesHelper
     out
   end
 
+  def email_issue_attributes(issue, user)
+    items = []
+    %w(author status priority assigned_to category fixed_version).each do |attribute|
+      unless issue.disabled_core_fields.include?(attribute+"_id")
+        items << "#{l("field_#{attribute}")}: #{issue.send attribute}"
+      end
+    end
+    issue.visible_custom_field_values(user).each do |value|
+      items << "#{value.custom_field.name}: #{show_value(value)}"
+    end
+    items
+  end
+
+  def render_email_issue_attributes(issue, user, html=false)
+    items = email_issue_attributes(issue, user)
+    if html
+      content_tag('ul', items.map{|s| content_tag('li', s)}.join("\n").html_safe)
+    else
+      items.map{|s| "* #{s}"}.join("\n")
+    end
+  end
+
   # Returns the textual representation of a journal details
   # as an array of strings
   def details_to_strings(details, no_html=false, options={})
index aee365e5681eb084609d7d36dd10005747bec543..6b84a5be10b027fe921a9d13aa16d52090d011e7 100644 (file)
@@ -1,16 +1,6 @@
 <h1><%= link_to(h("#{issue.tracker.name} ##{issue.id}: #{issue.subject}"), issue_url) %></h1>
 
-<ul>
-<li><%=l(:field_author)%>: <%=h issue.author %></li>
-<li><%=l(:field_status)%>: <%=h issue.status %></li>
-<li><%=l(:field_priority)%>: <%=h issue.priority %></li>
-<li><%=l(:field_assigned_to)%>: <%=h issue.assigned_to %></li>
-<li><%=l(:field_category)%>: <%=h issue.category %></li>
-<li><%=l(:field_fixed_version)%>: <%=h issue.fixed_version %></li>
-<% issue.visible_custom_field_values(users.first).each do |c| %>
-  <li><%=h c.custom_field.name %>: <%=h show_value(c) %></li>
-<% end %>
-</ul>
+<%= render_email_issue_attributes(issue, users.first, true) %>
 
 <%= textilizable(issue, :description, :only_path => false) %>
 
index a2d5a41b2e382e3be3c497356a543b211c6b3eb7..0034c441ff16f0d04628954914f23d75e455a2e8 100644 (file)
@@ -1,14 +1,7 @@
 <%= "#{issue.tracker.name} ##{issue.id}: #{issue.subject}" %>
 <%= issue_url %>
 
-* <%=l(:field_author)%>: <%= issue.author %>
-* <%=l(:field_status)%>: <%= issue.status %>
-* <%=l(:field_priority)%>: <%= issue.priority %>
-* <%=l(:field_assigned_to)%>: <%= issue.assigned_to %>
-* <%=l(:field_category)%>: <%= issue.category %>
-* <%=l(:field_fixed_version)%>: <%= issue.fixed_version %>
-<% issue.visible_custom_field_values(users.first).each do |c| %>* <%= c.custom_field.name %>: <%= show_value(c) %>
-<% end -%>
+<%= render_email_issue_attributes(issue, users.first) %>
 ----------------------------------------
 <%= issue.description %>
 
index 3cacf4f8716c169441b81cf1b4db89f07e33e28f..a2f371632dd24e8333a3cd7e9487f3267eafd24a 100644 (file)
@@ -317,6 +317,29 @@ class MailerTest < ActiveSupport::TestCase
     assert !last_email.bcc.include?(user.mail)
   end
 
+  def test_issue_add_should_include_enabled_fields
+    Setting.default_language = 'en'
+    issue = Issue.find(2)
+    assert Mailer.deliver_issue_add(issue)
+    assert_mail_body_match '* Target version: 1.0', last_email
+    assert_select_email do
+      assert_select 'li', :text => 'Target version: 1.0'
+    end
+  end
+
+  def test_issue_add_should_not_include_disabled_fields
+    Setting.default_language = 'en'
+    issue = Issue.find(2)
+    tracker = issue.tracker
+    tracker.core_fields -= ['fixed_version_id']
+    tracker.save!
+    assert Mailer.deliver_issue_add(issue)
+    assert_mail_body_no_match 'Target version', last_email
+    assert_select_email do
+      assert_select 'li', :text => /Target version/, :count => 0
+    end
+  end
+
   # test mailer methods for each language
   def test_issue_add
     issue = Issue.find(1)