Project

General

Profile

Patch #36265 » 0001-more-flexible-issue-notification-options.patch

Dmitry Makurin , 2021-12-01 10:23

View differences:

test/unit/journal_observer_test.rb (revision 153a4e26069b0f4182a4233516d7b4cb4aec72ac) → test/unit/journal_observer_test.rb (date 1638183313058)
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, :custom_fields, :custom_fields_trackers
27 27

  
28 28
  def setup
29 29
    User.current = nil
......
194 194
      issue.init_journal(user)
195 195
      issue.fixed_version = versions(:versions_003)
196 196

  
197
      assert issue.save
198
      assert_equal 0, ActionMailer::Base.deliveries.size
199
    end
200
  end
201

  
202
  def test_create_should_send_email_notification_with_issue_start_date_updated
203
    with_settings :notified_events => %w(issue_start_date_updated) do
204
      user = User.find_by_login('jsmith')
205
      issue = issues(:issues_001)
206
      issue.init_journal(user)
207
      issue.start_date = Date.current
208

  
209
      assert issue.save
210
      assert_equal 2, ActionMailer::Base.deliveries.size
211
    end
212
  end
213

  
214
  def test_create_should_not_send_email_notification_without_issue_start_date_updated
215
    with_settings :notified_events => [] do
216
      user = User.find_by_login('jsmith')
217
      issue = issues(:issues_001)
218
      issue.init_journal(user)
219
      issue.start_date = Date.current
220

  
221
      assert issue.save
222
      assert_equal 0, ActionMailer::Base.deliveries.size
223
    end
224
  end
225

  
226

  
227

  
228
  def test_create_should_send_email_notification_with_issue_due_date_updated
229
    with_settings :notified_events => %w(issue_due_date_updated) do
230
      user = User.find_by_login('jsmith')
231
      issue = issues(:issues_001)
232
      issue.init_journal(user)
233
      issue.due_date = Date.current
234

  
235
      assert issue.save
236
      assert_equal 2, ActionMailer::Base.deliveries.size
237
    end
238
  end
239

  
240
  def test_create_should_not_send_email_notification_without_issue_due_date_updated
241
    with_settings :notified_events => [] do
242
      user = User.find_by_login('jsmith')
243
      issue = issues(:issues_001)
244
      issue.init_journal(user)
245
      issue.due_date = Date.current
246

  
247
      assert issue.save
248
      assert_equal 0, ActionMailer::Base.deliveries.size
249
    end
250
  end
251

  
252
  def test_create_should_send_email_notification_with_issue_estimated_hours_updated
253
    with_settings :notified_events => %w(issue_estimated_hours_updated) do
254
      user = User.find_by_login('jsmith')
255
      issue = issues(:issues_001)
256
      issue.init_journal(user)
257
      issue.estimated_hours = '2h30'
258

  
259
      assert issue.save
260
      assert_equal 2, ActionMailer::Base.deliveries.size
261
    end
262
  end
263

  
264
  def test_create_should_not_send_email_notification_without_issue_estimated_hours_updated
265
    with_settings :notified_events => [] do
266
      user = User.find_by_login('jsmith')
267
      issue = issues(:issues_001)
268
      issue.init_journal(user)
269
      issue.estimated_hours = '2h30'
270

  
271
      assert issue.save
272
      assert_equal 0, ActionMailer::Base.deliveries.size
273
    end
274
  end
275

  
276
  def test_create_should_send_email_notification_with_issue_category_updated
277
    with_settings :notified_events => %w(issue_category_updated) do
278
      user = User.find_by_login('jsmith')
279
      issue = issues(:issues_001)
280
      issue.init_journal(user)
281
      issue.category_id = 2
282

  
283
      assert issue.save
284
      assert_equal 2, ActionMailer::Base.deliveries.size
285
    end
286
  end
287

  
288
  def test_create_should_not_send_email_notification_without_issue_category_updated
289
    with_settings :notified_events => [] do
290
      user = User.find_by_login('jsmith')
291
      issue = issues(:issues_001)
292
      issue.init_journal(user)
293
      issue.category_id = 2
294

  
295
      assert issue.save
296
      assert_equal 0, ActionMailer::Base.deliveries.size
297
    end
298
  end
299

  
300
  def test_create_should_send_email_notification_with_issue_description_updated
301
    with_settings :notified_events => %w(issue_description_updated) do
302
      user = User.find_by_login('jsmith')
303
      issue = issues(:issues_001)
304
      issue.init_journal(user)
305
      issue.description = 'description'
306

  
307
      assert issue.save
308
      assert_equal 2, ActionMailer::Base.deliveries.size
309
    end
310
  end
311

  
312
  def test_create_should_not_send_email_notification_without_issue_description_updated
313
    with_settings :notified_events => [] do
314
      user = User.find_by_login('jsmith')
315
      issue = issues(:issues_001)
316
      issue.init_journal(user)
317
      issue.description = 'description'
318

  
319
      assert issue.save
320
      assert_equal 0, ActionMailer::Base.deliveries.size
321
    end
322
  end
323

  
324
  def test_create_should_send_email_notification_with_issue_done_ratio_updated
325
    with_settings :notified_events => %w(issue_done_ratio_updated) do
326
      user = User.find_by_login('jsmith')
327
      issue = issues(:issues_001)
328
      issue.init_journal(user)
329
      issue.done_ratio = 30
330

  
331
      assert issue.save
332
      assert_equal 2, ActionMailer::Base.deliveries.size
333
    end
334
  end
335

  
336
  def test_create_should_not_send_email_notification_without_issue_done_ratio_updated
337
    with_settings :notified_events => [] do
338
      user = User.find_by_login('jsmith')
339
      issue = issues(:issues_001)
340
      issue.init_journal(user)
341
      issue.done_ratio = 30
342

  
343
      assert issue.save
344
      assert_equal 0, ActionMailer::Base.deliveries.size
345
    end
346
  end
347

  
348
  def test_create_should_send_email_notification_with_issue_parent_updated
349
    with_settings :notified_events => %w(issue_parent_updated) do
350
      user = User.find_by_login('jsmith')
351
      issue = issues(:issues_001)
352
      issue.init_journal(user)
353
      issue.parent = issues(:issues_002)
354

  
355
      assert issue.save
356
      assert_equal 2, ActionMailer::Base.deliveries.size
357
    end
358
  end
359

  
360
  def test_create_should_not_send_email_notification_without_issue_parent_updated
361
    with_settings :notified_events => [] do
362
      user = User.find_by_login('jsmith')
363
      issue = issues(:issues_001)
364
      issue.init_journal(user)
365
      issue.parent = issues(:issues_002)
366

  
367
      assert issue.save
368
      assert_equal 0, ActionMailer::Base.deliveries.size
369
    end
370
  end
371

  
372
  def test_create_should_send_email_notification_with_issue_project_updated
373
    with_settings :notified_events => %w(issue_project_updated) do
374
      user = User.find_by_login('jsmith')
375
      issue = issues(:issues_001)
376
      issue.init_journal(user)
377
      issue.project = projects(:projects_002)
378

  
379
      assert issue.save
380
      # Dave is not a member of project
381
      assert_equal 1, ActionMailer::Base.deliveries.size
382
    end
383
  end
384

  
385
  def test_create_should_not_send_email_notification_without_issue_project_updated
386
    with_settings :notified_events => [] do
387
      user = User.find_by_login('jsmith')
388
      issue = issues(:issues_001)
389
      issue.init_journal(user)
390
      issue.project = projects(:projects_002)
391

  
392
      assert issue.save
393
      assert_equal 0, ActionMailer::Base.deliveries.size
394
    end
395
  end
396

  
397
  def test_create_should_send_email_notification_with_issue_tracker_updated
398
    with_settings :notified_events => %w(issue_tracker_updated) do
399
      user = User.find_by_login('jsmith')
400
      issue = issues(:issues_001)
401
      issue.init_journal(user)
402
      issue.tracker = trackers(:trackers_002)
403

  
404
      assert issue.save
405
      assert_equal 2, ActionMailer::Base.deliveries.size
406
    end
407
  end
408

  
409
  def test_create_should_not_send_email_notification_without_issue_tracker_updated
410
    with_settings :notified_events => [] do
411
      user = User.find_by_login('jsmith')
412
      issue = issues(:issues_001)
413
      issue.init_journal(user)
414
      issue.tracker = trackers(:trackers_002)
415

  
416
      assert issue.save
417
      assert_equal 0, ActionMailer::Base.deliveries.size
418
    end
419
  end
420

  
421
  def test_create_should_send_email_notification_with_issue_subject_updated
422
    with_settings :notified_events => %w(issue_subject_updated) do
423
      user = User.find_by_login('jsmith')
424
      issue = issues(:issues_001)
425
      issue.init_journal(user)
426
      issue.subject = Time.current.to_s
427

  
428
      assert issue.save
429
      assert_equal 2, ActionMailer::Base.deliveries.size
430
    end
431
  end
432

  
433
  def test_create_should_not_send_email_notification_without_issue_subject_updated
434
    with_settings :notified_events => [] do
435
      user = User.find_by_login('jsmith')
436
      issue = issues(:issues_001)
437
      issue.init_journal(user)
438
      issue.subject = Time.current.to_s
439

  
440
      assert issue.save
441
      assert_equal 0, ActionMailer::Base.deliveries.size
442
    end
443
  end
444

  
445
  def test_create_should_send_email_notification_with_issue_attachment_updated
446
    with_settings :notified_events => %w(issue_attachment_updated) do
447
      user = User.find_by_login('jsmith')
448
      issue = issues(:issues_001)
449
      issue.init_journal(user)
450
      issue.save_attachments('1' => {'file' => mock_file_with_options(:original_filename => 'test.png')})
451
      issue.attach_saved_attachments
452

  
453
      assert issue.save
454
      assert_equal 2, ActionMailer::Base.deliveries.size
455
    end
456
  end
457

  
458
  def test_create_should_not_send_email_notification_without_issue_attachment_updated
459
    with_settings :notified_events => [] do
460
      user = User.find_by_login('jsmith')
461
      issue = issues(:issues_001)
462
      issue.init_journal(user)
463
      issue.save_attachments('1' => {'file' => mock_file_with_options(:original_filename => 'test.png')})
464
      issue.attach_saved_attachments
465

  
466
      assert issue.save
467
      assert_equal 0, ActionMailer::Base.deliveries.size
468
    end
469
  end
470

  
471
  def test_create_should_send_email_notification_with_issue_relation_updated
472
    with_settings :notified_events => %w(issue_relation_updated) do
473
      user = User.find_by_login('jsmith')
474
      issue = issues(:issues_001)
475
      rel = IssueRelation.new(:relation_type => "relates", :issue_from => Issue.find(3), :issue_to => Issue.find(1))
476
      rel.init_journals(user)
477
      rel.save
478

  
479
      # relation updated two issues #1 and #3
480
      assert issue.save
481
      assert_equal 4, ActionMailer::Base.deliveries.size
482
    end
483
  end
484

  
485
  def test_create_should_not_send_email_notification_without_issue_relation_updated
486
    with_settings :notified_events => [] do
487
      user = User.find_by_login('jsmith')
488
      issue = issues(:issues_001)
489
      rel = IssueRelation.new(:relation_type => "relates", :issue_from => Issue.find(3), :issue_to => Issue.find(1))
490
      rel.init_journals(user)
491
      rel.save
492

  
493
      assert issue.save
494
      assert_equal 0, ActionMailer::Base.deliveries.size
495
    end
496
  end
497

  
498
  def test_create_should_send_email_notification_with_issue_custom_value_updated
499
    with_settings :notified_events => %w(issue_custom_value_updated) do
500
      user = User.find_by_login('jsmith')
501
      issue = issues(:issues_001)
502
      issue.init_journal(user)
503
      issue.custom_field_values = {'2' => 'some value'}
504

  
505
      assert issue.save
506
      assert_equal 2, ActionMailer::Base.deliveries.size
507
    end
508
  end
509

  
510
  def test_create_should_not_send_email_notification_without_custom_value_updated
511
    with_settings :notified_events => [] do
512
      user = User.find_by_login('jsmith')
513
      issue = issues(:issues_001)
514
      issue.init_journal(user)
515
      issue.custom_field_values = {'2' => 'some value'}
516

  
197 517
      assert issue.save
198 518
      assert_equal 0, ActionMailer::Base.deliveries.size
199 519
    end
config/locales/en.yml (revision 153a4e26069b0f4182a4233516d7b4cb4aec72ac) → config/locales/en.yml (date 1638181575108)
622 622
  label_issue_assigned_to_updated: Assignee updated
623 623
  label_issue_priority_updated: Priority updated
624 624
  label_issue_fixed_version_updated: Target version updated
625
  label_issue_start_date_updated: Start date updated
626
  label_issue_due_date_updated: Due date updated
627
  label_issue_estimated_hours_updated: Estimated hours updated
628
  label_issue_category_updated: Category updated
629
  label_issue_description_updated: Description updated
630
  label_issue_done_ratio_updated: Done ratio updated
631
  label_issue_parent_updated: Parent issue updated
632
  label_issue_project_updated: Project updated
633
  label_issue_tracker_updated: Tracker updated
634
  label_issue_subject_updated: Subject updated
635
  label_issue_attachment_updated: Attachment updated
636
  label_issue_relation_updated: Relation updated
637
  label_issue_custom_value_updated: Custom value updated
625 638
  label_document: Document
626 639
  label_document_new: New document
627 640
  label_document_plural: Documents
app/models/journal.rb (revision 153a4e26069b0f4182a4233516d7b4cb4aec72ac) → app/models/journal.rb (date 1638183281874)
119 119
    details.detect {|detail| detail.prop_key == attribute}
120 120
  end
121 121

  
122
  # Returns the JournalDetail for the given property name
123
  def detail_for_property(property)
124
    details.detect {|detail| detail.property == property}
125
  end
126

  
122 127
  # Returns the new status if the journal contains a status change, otherwise nil
123 128
  def new_status
124 129
    s = new_value_for('status_id')
......
332 337
          (Setting.notified_events.include?('issue_status_updated') && new_status.present?) ||
333 338
          (Setting.notified_events.include?('issue_assigned_to_updated') && detail_for_attribute('assigned_to_id').present?) ||
334 339
          (Setting.notified_events.include?('issue_priority_updated') && new_value_for('priority_id').present?) ||
335
          (Setting.notified_events.include?('issue_fixed_version_updated') && detail_for_attribute('fixed_version_id').present?)
340
          (Setting.notified_events.include?('issue_fixed_version_updated') && detail_for_attribute('fixed_version_id').present?) ||
341
          (Setting.notified_events.include?('issue_start_date_updated') && detail_for_attribute('start_date').present?) ||
342
          (Setting.notified_events.include?('issue_due_date_updated') && detail_for_attribute('due_date').present?) ||
343
          (Setting.notified_events.include?('issue_estimated_hours_updated') && detail_for_attribute('estimated_hours').present?) ||
344
          (Setting.notified_events.include?('issue_category_updated') && detail_for_attribute('category_id').present?) ||
345
          (Setting.notified_events.include?('issue_description_updated') && detail_for_attribute('description').present?) ||
346
          (Setting.notified_events.include?('issue_done_ratio_updated') && detail_for_attribute('done_ratio').present?) ||
347
          (Setting.notified_events.include?('issue_parent_updated') && detail_for_attribute('parent_id').present?) ||
348
          (Setting.notified_events.include?('issue_project_updated') && detail_for_attribute('project_id').present?) ||
349
          (Setting.notified_events.include?('issue_tracker_updated') && detail_for_attribute('tracker_id').present?) ||
350
          (Setting.notified_events.include?('issue_subject_updated') && detail_for_attribute('subject').present?) ||
351
          (Setting.notified_events.include?('issue_attachment_updated') && detail_for_property('attachment').present?) ||
352
          (Setting.notified_events.include?('issue_relation_updated') && detail_for_property('relation').present?) ||
353
          (Setting.notified_events.include?('issue_custom_value_updated') && detail_for_property('cf').present?)
336 354
        )
337 355
      Mailer.deliver_issue_edit(self)
338 356
    end
lib/redmine/notifiable.rb (revision 153a4e26069b0f4182a4233516d7b4cb4aec72ac) → lib/redmine/notifiable.rb (date 1638181575120)
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_start_date_updated', 'issue_updated')
21
      notifications << Notifiable.new('issue_due_date_updated', 'issue_updated')
22
      notifications << Notifiable.new('issue_estimated_hours_updated', 'issue_updated')
23
      notifications << Notifiable.new('issue_category_updated', 'issue_updated')
24
      notifications << Notifiable.new('issue_description_updated', 'issue_updated')
25
      notifications << Notifiable.new('issue_done_ratio_updated', 'issue_updated')
26
      notifications << Notifiable.new('issue_parent_updated', 'issue_updated')
27
      notifications << Notifiable.new('issue_project_updated', 'issue_updated')
28
      notifications << Notifiable.new('issue_tracker_updated', 'issue_updated')
29
      notifications << Notifiable.new('issue_subject_updated', 'issue_updated')
30
      notifications << Notifiable.new('issue_attachment_updated', 'issue_updated')
31
      notifications << Notifiable.new('issue_relation_updated', 'issue_updated')
32
      notifications << Notifiable.new('issue_custom_value_updated', 'issue_updated')
20 33
      notifications << Notifiable.new('news_added')
21 34
      notifications << Notifiable.new('news_comment_added')
22 35
      notifications << Notifiable.new('document_added')
    (1-1/1)