Project

General

Profile

Feature #35189 » feature-35189-v4.patch

Marius BĂLTEANU, 2023-11-05 10:50

View differences:

app/controllers/projects_controller.rb
263 263
  end
264 264

  
265 265
  def bookmark
266
    jump_box = Redmine::ProjectJumpBox.new User.current
266
    user = User.current
267
    jump_box = Redmine::ProjectJumpBox.new user
267 268
    if request.delete?
268 269
      jump_box.delete_project_bookmark @project
270
      user.update_notified_bookmarked_project_ids(@project)
269 271
    elsif request.post?
270 272
      jump_box.bookmark_project @project
273
      user.update_notified_bookmarked_project_ids(@project)
271 274
    end
272 275
    respond_to do |format|
273 276
      format.js
app/models/user.rb
75 75
  MAIL_NOTIFICATION_OPTIONS = [
76 76
    ['all', :label_user_mail_option_all],
77 77
    ['selected', :label_user_mail_option_selected],
78
    ['bookmarked', :label_user_mail_option_bookmarked],
78 79
    ['only_my_events', :label_user_mail_option_only_my_events],
79 80
    ['only_assigned', :label_user_mail_option_only_assigned],
80 81
    ['only_owner', :label_user_mail_option_only_owner],
......
498 499
  # Updates per project notifications (after_save callback)
499 500
  def update_notified_project_ids
500 501
    if @notified_projects_ids_changed
501
      ids = (mail_notification == 'selected' ? Array.wrap(notified_projects_ids).reject(&:blank?) : [])
502
      ids = []
503
      if mail_notification == 'selected'
504
        ids = Array.wrap(notified_projects_ids).reject(&:blank?)
505
      elsif mail_notification == 'bookmarked'
506
        ids = Array.wrap(bookmarked_project_ids).reject(&:blank?)
507
      end
502 508
      members.update_all(:mail_notification => false)
503 509
      members.where(:project_id => ids).update_all(:mail_notification => true) if ids.any?
504 510
    end
505 511
  end
506 512
  private :update_notified_project_ids
507 513

  
514
  def update_notified_bookmarked_project_ids(project_id)
515
    if mail_notification == 'bookmarked'
516
      @notified_projects_ids_changed = true
517
      self.update_notified_project_ids
518
    end
519
  end
520

  
508 521
  def valid_notification_options
509 522
    self.class.valid_notification_options(self)
510 523
  end
......
834 847
      case object
835 848
      when Issue
836 849
        case mail_notification
837
        when 'selected', 'only_my_events'
850
        when 'selected', 'only_my_events', 'bookmarked'
838 851
          # user receives notifications for created/assigned issues on unselected projects
839 852
          object.author == self || is_or_belongs_to?(object.assigned_to) || is_or_belongs_to?(object.previous_assignee)
840 853
        when 'only_assigned'
config/locales/en.yml
942 942
  label_search_titles_only: Search titles only
943 943
  label_user_mail_option_all: "For any event on all my projects"
944 944
  label_user_mail_option_selected: "For any event on the selected projects only..."
945
  label_user_mail_option_bookmarked: "For any event on my bookmarked projects"
945 946
  label_user_mail_option_none: "No events"
946 947
  label_user_mail_option_only_my_events: "Only for things I watch or I'm involved in"
947 948
  label_user_mail_option_only_assigned: "Only for things I watch or I am assigned to"
config/locales/ja.yml
756 756
  label_search_titles_only: タイトルのみ
757 757
  label_user_mail_option_all: "参加しているプロジェクトのすべての通知"
758 758
  label_user_mail_option_selected: "選択したプロジェクトのすべての通知..."
759
  label_user_mail_option_bookmarked: "ブックマークしているプロジェクトのすべての通知"
759 760
  label_user_mail_option_none: "通知しない"
760 761
  label_user_mail_option_only_my_events: "ウォッチ中または自分が関係しているもの"
761 762
  label_user_mail_option_only_assigned: "ウォッチ中または自分が担当しているもの"
test/functional/projects_controller_test.rb
1499 1499
    refute jb.bookmark?(Project.find('ecookbook'))
1500 1500
  end
1501 1501

  
1502
  def test_bookmark_should_update_notified_project_ids_if_mail_notification_is_bookmarked
1503
    user = User.find(2)
1504
    @request.session[:user_id] = user.id
1505
    user.update(mail_notification: 'bookmarked')
1506

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

  
1510
    delete(:bookmark, :params => {:id => 'ecookbook'})
1511
    assert_equal [false, false, false], user.members.order(:id).pluck(:mail_notification)
1512
  end
1513

  
1502 1514
  def test_index_jump_without_project_id_should_redirect_to_active_tab
1503 1515
    get(:index, :params => {:jump => 'issues'})
1504 1516
    assert_redirected_to '/issues'
test/unit/project_test.rb
1045 1045
    only_my_events_user = User.generate!(:mail_notification => 'only_my_events')
1046 1046
    Member.create!(:project => project, :roles => [role], :principal => only_my_events_user)
1047 1047

  
1048
    bookmarked_user = User.generate!(:mail_notification => 'bookmarked')
1049
    Member.create!(:project => project, :roles => [role], :principal => bookmarked_user)
1050

  
1048 1051
    only_assigned_user = User.generate!(:mail_notification => 'only_assigned')
1049 1052
    Member.create!(:project => project, :roles => [role], :principal => only_assigned_user)
1050 1053

  
......
1059 1062
           "should not include users with the 'none' notification option"
1060 1063
    assert !project.notified_users.include?(only_my_events_user),
1061 1064
           "should not include users with the 'only_my_events' notification option"
1065
    assert !project.notified_users.include?(bookmarked_user),
1066
           "should not include users with the 'bookmarked' notification option"
1062 1067
    assert !project.notified_users.include?(only_assigned_user),
1063 1068
           "should not include users with the 'only_assigned' notification option"
1064 1069
    assert !project.notified_users.include?(only_owned_user),
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
......
1250 1250
    issue = Issue.generate!(:project => project, :assigned_to => assignee, :author => author)
1251 1251

  
1252 1252
    tests = {
1253
      author => %w(all only_my_events only_owner selected),
1254
      assignee => %w(all only_my_events only_assigned selected),
1253
      author => %w(all only_my_events only_owner selected bookmarked),
1254
      assignee => %w(all only_my_events only_assigned selected bookmarked),
1255 1255
      member => %w(all)
1256 1256
    }
1257 1257

  
(5-5/5)