diff --git a/app/models/mailer.rb b/app/models/mailer.rb index 2fe9673c9..748d0b745 100644 --- a/app/models/mailer.rb +++ b/app/models/mailer.rb @@ -629,8 +629,10 @@ class Mailer < ActionMailer::Base end end + non_working_week_days = Setting.non_working_week_days issues_by_assignee.each do |assignee, issues| if assignee.is_a?(User) && assignee.active? && issues.present? + next if assignee.pref.no_reminders_on_non_working_days == '1' && non_working_week_days.include?("#{assignee.today.cwday}") visible_issues = issues.select {|i| i.visible?(assignee)} visible_issues.sort!{|a, b| (a.due_date <=> b.due_date).nonzero? || (a.id <=> b.id)} reminder(assignee, visible_issues, days).deliver_later if visible_issues.present? diff --git a/app/models/user_preference.rb b/app/models/user_preference.rb index 21992f945..541462971 100644 --- a/app/models/user_preference.rb +++ b/app/models/user_preference.rb @@ -40,7 +40,8 @@ class UserPreference < ActiveRecord::Base 'default_issue_query', 'default_project_query', 'toolbar_language_options', - 'auto_watch_on') + 'auto_watch_on', + 'no_reminders_on_non_working_days') TEXTAREA_FONT_OPTIONS = ['monospace', 'proportional'] DEFAULT_TOOLBAR_LANGUAGE_OPTIONS = %w[c cpp csharp css diff go groovy html java javascript objc perl php python r ruby sass scala shell sql swift xml yaml] @@ -133,6 +134,9 @@ class UserPreference < ActiveRecord::Base def auto_watch_on=(values); self[:auto_watch_on]=values; end def auto_watch_on?(action); self.auto_watch_on.include?(action.to_s); end + def no_reminders_on_non_working_days; self[:no_reminders_on_non_working_days]; end + def no_reminders_on_non_working_days=(value); self[:no_reminders_on_non_working_days]=value; end + # Returns the names of groups that are displayed on user's page # Example: # preferences.my_page_groups diff --git a/app/views/users/_mail_notifications.html.erb b/app/views/users/_mail_notifications.html.erb index abf890e46..0a1bf2df0 100644 --- a/app/views/users/_mail_notifications.html.erb +++ b/app/views/users/_mail_notifications.html.erb @@ -35,4 +35,8 @@ <%= pref_fields.check_box :no_self_notified %>

+

+ <%= pref_fields.check_box :no_reminders_on_non_working_days %> + +

<% end %> diff --git a/config/locales/en.yml b/config/locales/en.yml index 2bbd776a3..8eaa9df8d 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -950,6 +950,7 @@ en: label_user_mail_option_only_owner: "Only for things I watch or I am the owner of" label_user_mail_no_self_notified: "I don't want to be notified of changes that I make myself" label_user_mail_notify_about_high_priority_issues_html: "Also notify me about issues with a priority of %{prio} or higher" + label_user_mail_no_reminders_on_non_working_days: "I don't want to receive email reminders on non-working days" label_registration_activation_by_email: account activation by email label_registration_manual_activation: manual account activation label_registration_automatic_activation: automatic account activation diff --git a/test/functional/users_controller_test.rb b/test/functional/users_controller_test.rb index e452371ff..a10600cb8 100644 --- a/test/functional/users_controller_test.rb +++ b/test/functional/users_controller_test.rb @@ -492,7 +492,8 @@ class UsersControllerTest < Redmine::ControllerTest 'comments_sorting' => 'desc', 'warn_on_leaving_unsaved' => '0', 'textarea_font' => 'proportional', - 'history_default_tab' => 'history' + 'history_default_tab' => 'history', + 'no_reminders_on_non_working_days' => '1' } } end @@ -504,6 +505,7 @@ class UsersControllerTest < Redmine::ControllerTest assert_equal '0', user.pref[:warn_on_leaving_unsaved] assert_equal 'proportional', user.pref[:textarea_font] assert_equal 'history', user.pref[:history_default_tab] + assert_equal '1', user.pref[:no_reminders_on_non_working_days] end def test_create_with_generate_password_should_email_the_password @@ -566,7 +568,8 @@ class UsersControllerTest < Redmine::ControllerTest 'hide_mail' => '1', 'time_zone' => 'Paris', 'comments_sorting' => 'desc', - 'warn_on_leaving_unsaved' => '0' + 'warn_on_leaving_unsaved' => '0', + 'no_reminders_on_non_working_days' => '1' } } end @@ -574,6 +577,7 @@ class UsersControllerTest < Redmine::ControllerTest assert_select 'select#pref_time_zone option[selected=selected]', :text => /Paris/ assert_select 'input#pref_no_self_notified[value="1"][checked=checked]' + assert_select 'input#pref_no_reminders_on_non_working_days[value="1"][checked=checked]' end def test_create_admin_should_send_security_notification diff --git a/test/unit/mailer_test.rb b/test/unit/mailer_test.rb index 889035a27..adb9de5cd 100644 --- a/test/unit/mailer_test.rb +++ b/test/unit/mailer_test.rb @@ -979,6 +979,25 @@ class MailerTest < ActiveSupport::TestCase end end + def test_reminders_with_non_working_days + user = User.find_by_login("dlopper") + with_settings :non_working_week_days => %W(#{user.today.cwday}) do + # Sending reminders to users who want to receive it on non-working days.(Default) + user.pref.no_reminders_on_non_working_days = '0' + user.pref.save! + ActionMailer::Base.deliveries.clear + Mailer.reminders(:users => [user.id]) + assert_equal 1, ActionMailer::Base.deliveries.size + + # Not sending reminders to users who not want to receive it on non-working days. + user.pref.no_reminders_on_non_working_days = '1' + user.pref.save! + ActionMailer::Base.deliveries.clear + Mailer.reminders(:users => [user.id]) + assert_equal 0, ActionMailer::Base.deliveries.size + end + end + def test_security_notification set_language_if_valid User.find(1).language with_settings :emails_footer => "footer without link" do