Project

General

Profile

Feature #37978 » add-email-notification-option-only-i-watch.patch

Takenori TAKAKI, 2024-03-21 09:10

View differences:

app/models/project.rb
626 626

  
627 627
  # Returns the users that should be notified on project events
628 628
  def notified_users
629
    users.where('members.mail_notification = ? OR users.mail_notification = ?', true, 'all')
629
    users.where('(members.mail_notification = ? OR users.mail_notification = ?) AND users.mail_notification <> ?', true, 'all', 'only_i_watch')
630 630
  end
631 631

  
632 632
  # Returns a scope of all custom fields enabled for project issues
app/models/user.rb
77 77
    ['selected', :label_user_mail_option_selected],
78 78
    ['only_my_events', :label_user_mail_option_only_my_events],
79 79
    ['only_assigned', :label_user_mail_option_only_assigned],
80
    ['only_i_watch', :label_user_mail_option_only_i_watch],
80 81
    ['only_owner', :label_user_mail_option_only_owner],
81 82
    ['none', :label_user_mail_option_none]
82 83
  ]
......
816 817
  def notify_about?(object)
817 818
    if mail_notification == 'all'
818 819
      true
819
    elsif mail_notification.blank? || mail_notification == 'none'
820
    elsif mail_notification.blank? || mail_notification == 'none' || mail_notification == 'only_i_watch'
820 821
      false
821 822
    else
822 823
      case object
config/locales/en.yml
946 946
  label_user_mail_option_none: "No events"
947 947
  label_user_mail_option_only_my_events: "Only for things I watch or I'm involved in"
948 948
  label_user_mail_option_only_assigned: "Only for things I watch or I am assigned to"
949
  label_user_mail_option_only_i_watch: "Only for things I watch"
949 950
  label_user_mail_option_only_owner: "Only for things I watch or I am the owner of"
950 951
  label_user_mail_no_self_notified: "I don't want to be notified of changes that I make myself"
951 952
  label_user_mail_notify_about_high_priority_issues_html: "Also notify me about issues with a priority of <em>%{prio}</em> or higher"
config/locales/ja.yml
759 759
  label_user_mail_option_none: "通知しない"
760 760
  label_user_mail_option_only_my_events: "ウォッチ中または自分が関係しているもの"
761 761
  label_user_mail_option_only_assigned: "ウォッチ中または自分が担当しているもの"
762
  label_user_mail_option_only_i_watch: "ウォッチ中のもの"
762 763
  label_user_mail_option_only_owner: "ウォッチ中または自分が作成したもの"
763 764
  label_user_mail_no_self_notified: 自分自身による変更の通知は不要
764 765
  label_registration_activation_by_email: メールでアカウントを有効化
test/unit/project_test.rb
1051 1051
    only_owned_user = User.generate!(:mail_notification => 'only_owner')
1052 1052
    Member.create!(:project => project, :roles => [role], :principal => only_owned_user)
1053 1053

  
1054
    only_i_watch_user = User.generate!(:mail_notification => 'only_i_watch')
1055
    Member.create!(:project => project, :roles => [role], :mail_notification => true, :principal => only_i_watch_user)
1056

  
1054 1057
    assert project.notified_users.include?(user_with_membership_notification),
1055 1058
           "should include members with a mail notification"
1056 1059
    assert project.notified_users.include?(all_events_user),
......
1063 1066
           "should not include users with the 'only_assigned' notification option"
1064 1067
    assert !project.notified_users.include?(only_owned_user),
1065 1068
           "should not include users with the 'only_owner' notification option"
1069
    assert !project.notified_users.include?(only_i_watch_user),
1070
           "should not include users with the 'only_i_watch' notification option"
1066 1071
  end
1067 1072

  
1068 1073
  def test_override_roles_without_builtin_group_memberships
test/unit/user_test.rb
1043 1043

  
1044 1044
  def test_valid_notification_options
1045 1045
    # without memberships
1046
    assert_equal 5, User.find(7).valid_notification_options.size
1046
    assert_equal 6, User.find(7).valid_notification_options.size
1047 1047
    # with memberships
1048
    assert_equal 6, User.find(2).valid_notification_options.size
1048
    assert_equal 7, User.find(2).valid_notification_options.size
1049 1049
  end
1050 1050

  
1051 1051
  def test_valid_notification_options_class_method
1052
    assert_equal 5, User.valid_notification_options.size
1053
    assert_equal 5, User.valid_notification_options(User.find(7)).size
1054
    assert_equal 6, User.valid_notification_options(User.find(2)).size
1052
    assert_equal 6, User.valid_notification_options.size
1053
    assert_equal 6, User.valid_notification_options(User.find(7)).size
1054
    assert_equal 7, User.valid_notification_options(User.find(2)).size
1055 1055
  end
1056 1056

  
1057 1057
  def test_notified_project_ids_setter_should_coerce_to_unique_integer_array
......
1261 1261
        assert_equal expected.include?(option), user.notify_about?(issue)
1262 1262
      end
1263 1263
    end
1264

  
1265
    [author, assignee, member].each do |user|
1266
      user.mail_notification = 'all'
1267
      assert user.notify_about?(issue)
1268
      %w(none only_i_watch).each do |option|
1269

  
1270
        user.mail_notification = option
1271
        assert !user.notify_about?(issue)
1272
      end
1273
    end
1264 1274
  end
1265 1275

  
1266 1276
  def test_notify_about_issue_for_previous_assignee
......
1292 1302

  
1293 1303
    User::MAIL_NOTIFICATION_OPTIONS.map(&:first).each do |option|
1294 1304
      user.mail_notification = option
1295
      assert_equal (option != 'none'), user.notify_about?(news)
1305
      assert_equal (option != 'none' && option != 'only_i_watch'), user.notify_about?(news)
1296 1306
    end
1297 1307
  end
1298 1308

  
    (1-1/1)