Project

General

Profile

Feature #35189 » feature-35189.patch

Mizuki ISHIKAWA, 2021-06-17 06:56

View differences:

app/models/user.rb
76 76
    ['all', :label_user_mail_option_all],
77 77
    ['selected', :label_user_mail_option_selected],
78 78
    ['only_my_events', :label_user_mail_option_only_my_events],
79
    ['only_bookmarked_projects', :label_user_mail_option_only_bookmarked_projects],
79 80
    ['only_assigned', :label_user_mail_option_only_assigned],
80 81
    ['only_owner', :label_user_mail_option_only_owner],
81 82
    ['none', :label_user_mail_option_none]
......
509 510
      members.update_all(:mail_notification => false)
510 511
      members.where(:project_id => ids).update_all(:mail_notification => true) if ids.any?
511 512
    end
513
    if saved_change_to_mail_notification? && mail_notification == 'only_bookmarked_projects'
514
      ids = self.bookmarked_project_ids
515
      self.members.update_all(mail_notification: false)
516
      self.members.where(project_id: ids).update_all(mail_notification: true) if ids.any?
517
    end
512 518
  end
513 519
  private :update_notified_project_ids
514 520

  
......
827 833
      case object
828 834
      when Issue
829 835
        case mail_notification
830
        when 'selected', 'only_my_events'
836
        when 'selected', 'only_my_events', 'only_bookmarked_projects'
831 837
          # user receives notifications for created/assigned issues on unselected projects
832 838
          object.author == self || is_or_belongs_to?(object.assigned_to) || is_or_belongs_to?(object.previous_assignee)
833 839
        when 'only_assigned'
app/models/user_preference.rb
26 26
  serialize :others
27 27

  
28 28
  before_save :set_others_hash, :clear_unused_block_settings
29
  after_save :update_notified_project_ids
29 30

  
30 31
  safe_attributes(
31 32
    'hide_mail',
......
193 194
    my_page_settings.keep_if {|block, settings| blocks.include?(block)}
194 195
  end
195 196
  private :clear_unused_block_settings
197

  
198
  def update_notified_project_ids
199
    return if self.user.mail_notification != 'only_bookmarked_projects' || self.saved_change_to_others.blank?
200

  
201
    saved_change_to_bookmarked_project_ids = self.saved_change_to_others.compact.pluck(:bookmarked_project_ids)
202
    if saved_change_to_bookmarked_project_ids[0] != saved_change_to_bookmarked_project_ids[1]
203
      ids = self.user.bookmarked_project_ids
204
      self.user.members.update_all(mail_notification: false)
205
      self.user.members.where(project_id: ids).update_all(mail_notification: true) if ids.any?
206
    end
207
  end
208
  private :update_notified_project_ids
196 209
end
config/locales/en.yml
935 935
  label_user_mail_option_only_my_events: "Only for things I watch or I'm involved in"
936 936
  label_user_mail_option_only_assigned: "Only for things I watch or I am assigned to"
937 937
  label_user_mail_option_only_owner: "Only for things I watch or I am the owner of"
938
  label_user_mail_option_only_bookmarked_projects: "For any event on the my bookmarked projects"
938 939
  label_user_mail_no_self_notified: "I don't want to be notified of changes that I make myself"
939 940
  label_user_mail_notify_about_high_priority_issues_html: "Also notify me about issues with a priority of <em>%{prio}</em> or higher"
940 941
  label_registration_activation_by_email: account activation by email
config/locales/ja.yml
768 768
  label_user_mail_option_only_my_events: "ウォッチ中または自分が関係しているもの"
769 769
  label_user_mail_option_only_assigned: "ウォッチ中または自分が担当しているもの"
770 770
  label_user_mail_option_only_owner: "ウォッチ中または自分が作成したもの"
771
  label_user_mail_option_only_bookmarked_projects: "ブックマークしているプロジェクトのすべての通知"
771 772
  label_user_mail_no_self_notified: 自分自身による変更の通知は不要
772 773
  label_registration_activation_by_email: メールでアカウントを有効化
773 774
  label_registration_manual_activation: 手動でアカウントを有効化
test/functional/my_controller_test.rb
510 510
    assert [mail.bcc, mail.cc].flatten.include?('foobar@example.com')
511 511
  end
512 512

  
513
  def test_update_account_mail_notification_to_only_bookmarked_projects_should_update_members
514
    user = User.find(2)
515
    jump_box = Redmine::ProjectJumpBox.new user
516
    jump_box.bookmark_project user.members.order(:id).first.project
517
    jump_box.delete_project_bookmark user.members.order(:id).second.project
518
    jump_box.delete_project_bookmark user.members.order(:id).third.project
519

  
520
    assert_equal 'all', user.mail_notification
521
    assert_equal [true, true, true], user.members.order(:id).pluck(:mail_notification)
522
    put(
523
      :account,
524
      params: {
525
        user: {
526
          mail_notification: 'only_bookmarked_projects'
527

  
528
        }
529
      }
530
    )
531

  
532
    assert_equal 'only_bookmarked_projects', user.reload.mail_notification
533
    assert_equal [true, false, false], user.members.order(:id).pluck(:mail_notification)
534
  end
535

  
513 536
  def test_my_account_notify_about_high_priority_issues_preference
514 537
    # normally, preference should be shown
515 538
    get :account
test/functional/projects_controller_test.rb
1305 1305
    refute jb.bookmark?(Project.find('ecookbook'))
1306 1306
  end
1307 1307

  
1308
  def test_bookmark_should_change_bookmark_and_update_members_if_mail_notification_is_only_bookmarked_projects
1309
    user = User.find(2)
1310
    @request.session[:user_id] = user.id
1311
    user.update(mail_notification: 'only_bookmarked_projects')
1312
    assert_equal [false, false, false], user.members.order(:id).pluck(:mail_notification)
1313

  
1314
    post(:bookmark, :params => {:id => 'ecookbook'})
1315
    assert_equal [true, false, false], user.members.order(:id).pluck(:mail_notification)
1316

  
1317
    delete(:bookmark, :params => {:id => 'ecookbook'})
1318
    assert_equal [false, false, false], user.members.order(:id).pluck(:mail_notification)
1319
  end
1320

  
1308 1321
  def test_index_jump_without_project_id_should_redirect_to_active_tab
1309 1322
    get(:index, :params => {:jump => 'issues'})
1310 1323
    assert_redirected_to '/issues'
test/unit/project_test.rb
1020 1020
    only_my_events_user = User.generate!(:mail_notification => 'only_my_events')
1021 1021
    Member.create!(:project => project, :roles => [role], :principal => only_my_events_user)
1022 1022

  
1023
    only_bookmarked_projects_user = User.generate!(:mail_notification => 'only_bookmarked_projects')
1024
    Member.create!(:project => project, :roles => [role], :principal => only_bookmarked_projects_user)
1025

  
1023 1026
    only_assigned_user = User.generate!(:mail_notification => 'only_assigned')
1024 1027
    Member.create!(:project => project, :roles => [role], :principal => only_assigned_user)
1025 1028

  
......
1034 1037
           "should not include users with the 'none' notification option"
1035 1038
    assert !project.notified_users.include?(only_my_events_user),
1036 1039
           "should not include users with the 'only_my_events' notification option"
1040
    assert !project.notified_users.include?(only_bookmarked_projects_user),
1041
           "should not include users with the 'only_bookmarked_projects' notification option"
1037 1042
    assert !project.notified_users.include?(only_assigned_user),
1038 1043
           "should not include users with the 'only_assigned' notification option"
1039 1044
    assert !project.notified_users.include?(only_owned_user),
test/unit/user_test.rb
1036 1036

  
1037 1037
  def test_valid_notification_options
1038 1038
    # without memberships
1039
    assert_equal 5, User.find(7).valid_notification_options.size
1039
    assert_equal 6, User.find(7).valid_notification_options.size
1040 1040
    # with memberships
1041
    assert_equal 6, User.find(2).valid_notification_options.size
1041
    assert_equal 7, User.find(2).valid_notification_options.size
1042 1042
  end
1043 1043

  
1044 1044
  def test_valid_notification_options_class_method
1045
    assert_equal 5, User.valid_notification_options.size
1046
    assert_equal 5, User.valid_notification_options(User.find(7)).size
1047
    assert_equal 6, User.valid_notification_options(User.find(2)).size
1045
    assert_equal 6, User.valid_notification_options.size
1046
    assert_equal 6, User.valid_notification_options(User.find(7)).size
1047
    assert_equal 7, User.valid_notification_options(User.find(2)).size
1048 1048
  end
1049 1049

  
1050 1050
  def test_notified_project_ids_setter_should_coerce_to_unique_integer_array
......
1243 1243
    issue = Issue.generate!(:project => project, :assigned_to => assignee, :author => author)
1244 1244

  
1245 1245
    tests = {
1246
      author => %w(all only_my_events only_owner selected),
1247
      assignee => %w(all only_my_events only_assigned selected),
1246
      author => %w(all only_my_events only_owner selected only_bookmarked_projects),
1247
      assignee => %w(all only_my_events only_assigned selected only_bookmarked_projects),
1248 1248
      member => %w(all)
1249 1249
    }
1250 1250

  
(1-1/5)