diff --git a/app/models/mailer.rb b/app/models/mailer.rb index 492ca976d..779acf13f 100644 --- a/app/models/mailer.rb +++ b/app/models/mailer.rb @@ -581,8 +581,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 7373290c5..604bc4833 100644 --- a/app/models/user_preference.rb +++ b/app/models/user_preference.rb @@ -30,7 +30,8 @@ class UserPreference < ActiveRecord::Base 'comments_sorting', 'warn_on_leaving_unsaved', 'no_self_notified', - 'textarea_font' + 'textarea_font', + 'no_reminders_on_non_working_days' TEXTAREA_FONT_OPTIONS = ['monospace', 'proportional'] @@ -73,8 +74,8 @@ class UserPreference < ActiveRecord::Base end end - def comments_sorting; self[:comments_sorting] end - def comments_sorting=(order); self[:comments_sorting]=order end + def comments_sorting; self[:comments_sorting]; end + def comments_sorting=(order); self[:comments_sorting]=order; end def warn_on_leaving_unsaved; self[:warn_on_leaving_unsaved] || '1'; end def warn_on_leaving_unsaved=(value); self[:warn_on_leaving_unsaved]=value; end @@ -82,12 +83,15 @@ class UserPreference < ActiveRecord::Base def no_self_notified; (self[:no_self_notified] == true || self[:no_self_notified] == '1'); end def no_self_notified=(value); self[:no_self_notified]=value; end - def activity_scope; Array(self[:activity_scope]) ; end - def activity_scope=(value); self[:activity_scope]=value ; end + def activity_scope; Array(self[:activity_scope]); end + def activity_scope=(value); self[:activity_scope]=value; end - def textarea_font; self[:textarea_font] end + def textarea_font; self[:textarea_font]; end def textarea_font=(value); self[:textarea_font]=value; 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 85842de56..56490fee0 100644 --- a/app/views/users/_mail_notifications.html.erb +++ b/app/views/users/_mail_notifications.html.erb @@ -10,7 +10,7 @@ <%= content_tag 'fieldset', :id => 'notified-projects', :style => (@user.mail_notification == 'selected' ? '' : 'display:none;') do %> <%= toggle_checkboxes_link("#notified-projects input[type=checkbox]") %><%=l(:label_project_plural)%> <%= render_project_nested_lists(@user.projects) do |project| - content_tag('label', + content_tag('label', check_box_tag( 'user[notified_project_ids][]', project.id, @@ -28,4 +28,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 cdc79640b..93392b058 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -889,6 +889,7 @@ en: label_user_mail_option_only_assigned: "Only for things I watch or I am assigned to" 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_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 1f2dd4f32..a7a4a9d35 100644 --- a/test/functional/users_controller_test.rb +++ b/test/functional/users_controller_test.rb @@ -244,7 +244,8 @@ class UsersControllerTest < Redmine::ControllerTest 'time_zone' => 'Paris', 'comments_sorting' => 'desc', 'warn_on_leaving_unsaved' => '0', - 'textarea_font' => 'proportional' + 'textarea_font' => 'proportional', + 'no_reminders_on_non_working_days' => '1' } } end @@ -255,6 +256,7 @@ class UsersControllerTest < Redmine::ControllerTest assert_equal 'desc', user.pref[:comments_sorting] assert_equal '0', user.pref[:warn_on_leaving_unsaved] assert_equal 'proportional', user.pref[:textarea_font] + assert_equal '1', user.pref[:no_reminders_on_non_working_days] end def test_create_with_generate_password_should_email_the_password @@ -317,7 +319,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 @@ -325,6 +328,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 d61479202..1c6c5f8ab 100644 --- a/test/unit/mailer_test.rb +++ b/test/unit/mailer_test.rb @@ -642,6 +642,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