Project

General

Profile

Feature #30112 » 30112-stop-reminder-on-non-working-days.patch

Yuichi HARADA, 2018-12-26 01:26

View differences:

app/models/mailer.rb
581 581
      end
582 582
    end
583 583

  
584
    non_working_week_days = Setting.non_working_week_days
584 585
    issues_by_assignee.each do |assignee, issues|
585 586
      if assignee.is_a?(User) && assignee.active? && issues.present?
587
        next if assignee.pref.no_reminders_on_non_working_days == '1' && non_working_week_days.include?("#{assignee.today.cwday}")
586 588
        visible_issues = issues.select {|i| i.visible?(assignee)}
587 589
        visible_issues.sort!{|a, b| (a.due_date <=> b.due_date).nonzero? || (a.id <=> b.id)}
588 590
        reminder(assignee, visible_issues, days).deliver_later if visible_issues.present?
app/models/user_preference.rb
30 30
    'comments_sorting',
31 31
    'warn_on_leaving_unsaved',
32 32
    'no_self_notified',
33
    'textarea_font'
33
    'textarea_font',
34
    'no_reminders_on_non_working_days'
34 35

  
35 36
  TEXTAREA_FONT_OPTIONS = ['monospace', 'proportional']
36 37

  
......
73 74
    end
74 75
  end
75 76

  
76
  def comments_sorting; self[:comments_sorting] end
77
  def comments_sorting=(order); self[:comments_sorting]=order end
77
  def comments_sorting; self[:comments_sorting]; end
78
  def comments_sorting=(order); self[:comments_sorting]=order; end
78 79

  
79 80
  def warn_on_leaving_unsaved; self[:warn_on_leaving_unsaved] || '1'; end
80 81
  def warn_on_leaving_unsaved=(value); self[:warn_on_leaving_unsaved]=value; end
......
82 83
  def no_self_notified; (self[:no_self_notified] == true || self[:no_self_notified] == '1'); end
83 84
  def no_self_notified=(value); self[:no_self_notified]=value; end
84 85

  
85
  def activity_scope; Array(self[:activity_scope]) ; end
86
  def activity_scope=(value); self[:activity_scope]=value ; end
86
  def activity_scope; Array(self[:activity_scope]); end
87
  def activity_scope=(value); self[:activity_scope]=value; end
87 88

  
88
  def textarea_font; self[:textarea_font] end
89
  def textarea_font; self[:textarea_font]; end
89 90
  def textarea_font=(value); self[:textarea_font]=value; end
90 91

  
92
  def no_reminders_on_non_working_days; self[:no_reminders_on_non_working_days]; end
93
  def no_reminders_on_non_working_days=(value); self[:no_reminders_on_non_working_days]=value; end
94

  
91 95
  # Returns the names of groups that are displayed on user's page
92 96
  # Example:
93 97
  #   preferences.my_page_groups
app/views/users/_mail_notifications.html.erb
10 10
<%= content_tag 'fieldset', :id => 'notified-projects', :style => (@user.mail_notification == 'selected' ? '' : 'display:none;') do %>
11 11
  <legend><%= toggle_checkboxes_link("#notified-projects input[type=checkbox]") %><%=l(:label_project_plural)%></legend>
12 12
  <%= render_project_nested_lists(@user.projects) do |project|
13
        content_tag('label', 
13
        content_tag('label',
14 14
          check_box_tag(
15 15
            'user[notified_project_ids][]',
16 16
             project.id,
......
28 28
  <%= pref_fields.check_box :no_self_notified %>
29 29
  <label for="pref_no_self_notified"><%= l(:label_user_mail_no_self_notified) %></label>
30 30
</p>
31
<p>
32
  <%= pref_fields.check_box :no_reminders_on_non_working_days %>
33
  <label for="pref_no_reminders_on_non_working_days"><%= l(:label_user_mail_no_reminders_on_non_working_days) %></label>
34
</p>
31 35
<% end %>
config/locales/en.yml
889 889
  label_user_mail_option_only_assigned: "Only for things I watch or I am assigned to"
890 890
  label_user_mail_option_only_owner: "Only for things I watch or I am the owner of"
891 891
  label_user_mail_no_self_notified: "I don't want to be notified of changes that I make myself"
892
  label_user_mail_no_reminders_on_non_working_days: "I don't want to receive email reminders on non-working days"
892 893
  label_registration_activation_by_email: account activation by email
893 894
  label_registration_manual_activation: manual account activation
894 895
  label_registration_automatic_activation: automatic account activation
test/functional/users_controller_test.rb
244 244
          'time_zone' => 'Paris',
245 245
          'comments_sorting' => 'desc',
246 246
          'warn_on_leaving_unsaved' => '0',
247
          'textarea_font' => 'proportional'
247
          'textarea_font' => 'proportional',
248
          'no_reminders_on_non_working_days' => '1'
248 249
        }
249 250
      }
250 251
    end
......
255 256
    assert_equal 'desc', user.pref[:comments_sorting]
256 257
    assert_equal '0', user.pref[:warn_on_leaving_unsaved]
257 258
    assert_equal 'proportional', user.pref[:textarea_font]
259
    assert_equal '1', user.pref[:no_reminders_on_non_working_days]
258 260
  end
259 261

  
260 262
  def test_create_with_generate_password_should_email_the_password
......
317 319
          'hide_mail' => '1',
318 320
          'time_zone' => 'Paris',
319 321
          'comments_sorting' => 'desc',
320
          'warn_on_leaving_unsaved' => '0'
322
          'warn_on_leaving_unsaved' => '0',
323
          'no_reminders_on_non_working_days' => '1'
321 324
        }
322 325
      }
323 326
    end
......
325 328

  
326 329
    assert_select 'select#pref_time_zone option[selected=selected]', :text => /Paris/
327 330
    assert_select 'input#pref_no_self_notified[value="1"][checked=checked]'
331
    assert_select 'input#pref_no_reminders_on_non_working_days[value="1"][checked=checked]'
328 332
  end
329 333

  
330 334
  def test_create_admin_should_send_security_notification
test/unit/mailer_test.rb
642 642
    end
643 643
  end
644 644

  
645
  def test_reminders_with_non_working_days
646
    user = User.find_by_login("dlopper")
647
    with_settings :non_working_week_days => %W(#{user.today.cwday}) do
648
      # Sending reminders to users who want to receive it on non-working days.(Default)
649
      user.pref.no_reminders_on_non_working_days = '0'
650
      user.pref.save!
651
      ActionMailer::Base.deliveries.clear
652
      Mailer.reminders(:users => [user.id])
653
      assert_equal 1, ActionMailer::Base.deliveries.size
654

  
655
      # Not sending reminders to users who not want to receive it on non-working days.
656
      user.pref.no_reminders_on_non_working_days = '1'
657
      user.pref.save!
658
      ActionMailer::Base.deliveries.clear
659
      Mailer.reminders(:users => [user.id])
660
      assert_equal 0, ActionMailer::Base.deliveries.size
661
    end
662
  end
663

  
645 664
  def test_security_notification
646 665
    set_language_if_valid User.find(1).language
647 666
    with_settings :emails_footer => "footer without link" do
(2-2/3)