notified = notified.select {|u| u.active? && u.notify_about?(self)}
notified += project.notified_users
+ notified += project.users.preload(:preference).select(&:notify_about_high_priority_issues?) if priority.high?
notified.uniq!
# Remove users that can not view the issue
notified.reject! {|user| !visible?(user)}
end
end
+ def notify_about_high_priority_issues?
+ self.pref.notify_about_high_priority_issues
+ end
+
def self.current=(user)
RequestStore.store[:current_user] = user
end
'comments_sorting',
'warn_on_leaving_unsaved',
'no_self_notified',
+ 'notify_about_high_priority_issues',
'textarea_font',
'recently_used_projects',
'history_default_tab',
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 notify_about_high_priority_issues; (self[:notify_about_high_priority_issues] == true || self[:notify_about_high_priority_issues] == '1'); end
+ def notify_about_high_priority_issues=(value); self[:notify_about_high_priority_issues]=value; end
+
def activity_scope; Array(self[:activity_scope]) ; end
def activity_scope=(value); self[:activity_scope]=value ; end
<%= content_tag 'fieldset', :id => 'notified-projects', :style => (@user.mail_notification == 'selected' ? '' : 'display:none;') do %>
<legend><%= toggle_checkboxes_link("#notified-projects input[type=checkbox]") %><%=l(:label_project_plural)%></legend>
<%= render_project_nested_lists(@user.projects) do |project|
- content_tag('label',
+ content_tag('label',
check_box_tag(
'user[notified_project_ids][]',
project.id,
<% end %>
<%= fields_for :pref, @user.pref do |pref_fields| %>
+
+<% if IssuePriority.default_or_middle and high_priority = IssuePriority.where(['position > ?', IssuePriority.default_or_middle.position]).first %>
+<p>
+ <%= pref_fields.check_box :notify_about_high_priority_issues %>
+ <label for="pref_notify_about_high_priority_issues"><%= t(:label_user_mail_notify_about_high_priority_issues_html, prio: high_priority.name.downcase) %></label>
+</p>
+<% end %>
<p>
<%= pref_fields.check_box :no_self_notified %>
<label for="pref_no_self_notified"><%= l(:label_user_mail_no_self_notified) %></label>
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_notify_about_high_priority_issues_html: "Also notify me about issues with a priority of <em>%{prio}</em> or higher"
label_registration_activation_by_email: account activation by email
label_registration_manual_activation: manual account activation
label_registration_automatic_activation: automatic account activation
assert [mail.bcc, mail.cc].flatten.include?('foobar@example.com')
end
+ def test_my_account_notify_about_high_priority_issues_preference
+
+ # normally, preference should be shown
+ get :account
+ assert_select 'label[for="pref_notify_about_high_priority_issues"]'
+
+ # preference should be persisted
+ put :account, :params => {
+ :pref => {
+ notify_about_high_priority_issues: '1'
+ }
+ }
+ assert User.find(2).notify_about_high_priority_issues?
+
+ # preference should be hidden if there aren't any priorities
+ Issue.destroy_all
+ IssuePriority.destroy_all
+ get :account
+ assert_select 'label[for="pref_notify_about_high_priority_issues"]', false
+
+ # preference should be hidden if there isn't a "high" priority
+ a = IssuePriority.create! name: 'A'
+ get :account
+ assert_select 'label[for="pref_notify_about_high_priority_issues"]', false
+
+ # preference should be shown if there are at least two priorities (one low, one high)
+ b = IssuePriority.create! name: 'B'
+ get :account
+ assert_select 'label[for="pref_notify_about_high_priority_issues"]'
+
+ # preference should be hidden if the highest priority is the default one,
+ # because that means that there is no "high" priority
+ b.update! is_default: true
+ get :account
+ assert_select 'label[for="pref_notify_about_high_priority_issues"]', false
+ end
+
def test_my_account_should_show_destroy_link
get :account
assert_select 'a[href="/my/account/destroy"]'
assert !issue.recipients.include?(issue.assigned_to.mail)
end
+ test "Issue#recipients should include users who want to be notified about high issues but only when issue has high priority" do
+ user = User.generate!
+ user.pref.update! notify_about_high_priority_issues: true
+ Member.create!(:project_id => 1, :principal => user, :role_ids => [1])
+
+ # creation with high prio
+ issue = Issue.generate!(priority: IssuePriority.find(6))
+ assert issue.recipients.include?(user.mail)
+
+ # creation with default prio
+ issue = Issue.generate!
+ assert !issue.recipients.include?(user.mail)
+
+ # update prio to high
+ issue.update! priority: IssuePriority.find(6)
+ assert issue.recipients.include?(user.mail)
+
+ # update prio to low
+ issue.update! priority: IssuePriority.find(4)
+ assert !issue.recipients.include?(user.mail)
+ end
+
+ test "Authors who don't want to be self-notified should not receive emails even when issue has high priority" do
+ user = User.generate!
+ user.pref.update! notify_about_high_priority_issues: true
+ user.pref.update! no_self_notified: true
+
+ project = Project.find(1)
+ project.memberships.destroy_all
+ Member.create!(:project_id => 1, :principal => user, :role_ids => [1])
+
+ ActionMailer::Base.deliveries.clear
+ Issue.create(author: user,
+ priority: IssuePriority.find(6),
+ subject: 'test create',
+ project: project,
+ tracker: Tracker.first,
+ status: IssueStatus.first)
+ assert ActionMailer::Base.deliveries.empty?
+ end
+
def test_last_journal_id_with_journals_should_return_the_journal_id
assert_equal 2, Issue.find(1).last_journal_id
end