32183_notified_events_other_issue_attributes.patch

Yuichi HARADA, 2019-10-07 06:43

Download (4.94 KB)

View differences:

app/models/journal.rb
304 304
  end
305 305

  
306 306
  def send_notification
307
    if notify? && (Setting.notified_events.include?('issue_updated') ||
307
    return unless notify?
308
    if Setting.notified_events.include?('issue_updated') ||
308 309
        (Setting.notified_events.include?('issue_note_added') && notes.present?) ||
309 310
        (Setting.notified_events.include?('issue_status_updated') && new_status.present?) ||
310 311
        (Setting.notified_events.include?('issue_assigned_to_updated') && detail_for_attribute('assigned_to_id').present?) ||
311 312
        (Setting.notified_events.include?('issue_priority_updated') && new_value_for('priority_id').present?) ||
312
        (Setting.notified_events.include?('issue_fixed_version_updated') && detail_for_attribute('fixed_version_id').present?)
313
      )
313
        (Setting.notified_events.include?('issue_fixed_version_updated') && detail_for_attribute('fixed_version_id').present?) ||
314
        (Setting.notified_events.include?('issue_other_attributes_updated') && (
315
          (
316
            journalized.journalized_attribute_names - ['status_id', 'assigned_to_id', 'priority_id', 'fixed_version_id']
317
          ).any?{|attr_name| detail_for_attribute(attr_name).present?} ||
318
          (['attachment', 'relation', 'cf'] & details.collect(&:property)).any?
319
        ))
314 320
      Mailer.deliver_issue_edit(self)
315 321
    end
316 322
  end
config/locales/en.yml
589 589
  label_issue_assigned_to_updated: Assignee updated
590 590
  label_issue_priority_updated: Priority updated
591 591
  label_issue_fixed_version_updated: Target version updated
592
  label_issue_other_attributes_updated: Other issue attributes updated
592 593
  label_document: Document
593 594
  label_document_new: New document
594 595
  label_document_plural: Documents
lib/redmine/notifiable.rb
17 17
      notifications << Notifiable.new('issue_assigned_to_updated', 'issue_updated')
18 18
      notifications << Notifiable.new('issue_priority_updated', 'issue_updated')
19 19
      notifications << Notifiable.new('issue_fixed_version_updated', 'issue_updated')
20
      notifications << Notifiable.new('issue_other_attributes_updated', 'issue_updated')
20 21
      notifications << Notifiable.new('news_added')
21 22
      notifications << Notifiable.new('news_comment_added')
22 23
      notifications << Notifiable.new('document_added')
test/unit/journal_observer_test.rb
23 23
  fixtures :issues, :issue_statuses, :journals, :journal_details, :projects,
24 24
           :projects_trackers, :trackers, :enabled_modules, :enumerations,
25 25
           :users, :user_preferences, :email_addresses, :roles, :members, :member_roles,
26
           :versions
26
           :versions,
27
           :custom_fields, :custom_fields_trackers, :custom_values
27 28

  
28 29
  def setup
29 30
    User.current = nil
......
198 199
      assert_equal 0, ActionMailer::Base.deliveries.size
199 200
    end
200 201
  end
202

  
203
  def test_create_should_send_email_notification_with_issue_other_attributes_updated
204
    with_settings :notified_events => %w(issue_other_attributes_updated) do
205
      user = User.find_by_login('jsmith')
206

  
207
      # subject
208
      ActionMailer::Base.deliveries.clear
209
      issue = issues(:issues_001)
210
      issue.init_journal(user)
211
      issue.subject = 'Update subject'
212
      assert issue.save
213
      assert_equal 2, ActionMailer::Base.deliveries.size
214

  
215
      # custom field
216
      ActionMailer::Base.deliveries.clear
217
      issue = issues(:issues_003)
218
      issue.init_journal(user)
219
      issue.custom_field_values = {'2' => 'Update custom field'}
220
      assert issue.save
221
      assert_equal 2, ActionMailer::Base.deliveries.size
222
    end
223
  end
224

  
225
  def test_create_should_not_send_email_notification_without_issue_other_attributes_updated
226
    with_settings :notified_events => [] do
227
      user = User.find_by_login('jsmith')
228

  
229
      # subject
230
      ActionMailer::Base.deliveries.clear
231
      issue = issues(:issues_001)
232
      issue.init_journal(user)
233
      issue.subject = 'Update subject'
234
      assert issue.save
235
      assert_equal 0, ActionMailer::Base.deliveries.size
236

  
237
      # custom field
238
      ActionMailer::Base.deliveries.clear
239
      issue = issues(:issues_003)
240
      issue.init_journal(user)
241
      issue.custom_field_values = {'2' => 'Update custom field'}
242
      assert issue.save
243
      assert_equal 0, ActionMailer::Base.deliveries.size
244
    end
245
  end
201 246
end