Browse Source

Enable users to receive email notifications about high issues (only) (#32628).

Patch by Jan Schulz-Hofen.


git-svn-id: http://svn.redmine.org/redmine/trunk@19449 e93f8b46-1217-0410-a6f0-8f06a7374b81
tags/4.2.0
Go MAEDA 4 years ago
parent
commit
d48769f152

+ 1
- 0
app/models/issue.rb View File

notified = notified.select {|u| u.active? && u.notify_about?(self)} notified = notified.select {|u| u.active? && u.notify_about?(self)}


notified += project.notified_users notified += project.notified_users
notified += project.users.preload(:preference).select(&:notify_about_high_priority_issues?) if priority.high?
notified.uniq! notified.uniq!
# Remove users that can not view the issue # Remove users that can not view the issue
notified.reject! {|user| !visible?(user)} notified.reject! {|user| !visible?(user)}

+ 4
- 0
app/models/user.rb View File

end end
end end


def notify_about_high_priority_issues?
self.pref.notify_about_high_priority_issues
end

def self.current=(user) def self.current=(user)
RequestStore.store[:current_user] = user RequestStore.store[:current_user] = user
end end

+ 4
- 0
app/models/user_preference.rb View File

'comments_sorting', 'comments_sorting',
'warn_on_leaving_unsaved', 'warn_on_leaving_unsaved',
'no_self_notified', 'no_self_notified',
'notify_about_high_priority_issues',
'textarea_font', 'textarea_font',
'recently_used_projects', 'recently_used_projects',
'history_default_tab', 'history_default_tab',
def no_self_notified; (self[:no_self_notified] == true || self[:no_self_notified] == '1'); end 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 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; Array(self[:activity_scope]) ; end
def activity_scope=(value); self[:activity_scope]=value ; end def activity_scope=(value); self[:activity_scope]=value ; end



+ 8
- 1
app/views/users/_mail_notifications.html.erb View File

<%= content_tag 'fieldset', :id => 'notified-projects', :style => (@user.mail_notification == 'selected' ? '' : 'display:none;') do %> <%= 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> <legend><%= toggle_checkboxes_link("#notified-projects input[type=checkbox]") %><%=l(:label_project_plural)%></legend>
<%= render_project_nested_lists(@user.projects) do |project| <%= render_project_nested_lists(@user.projects) do |project|
content_tag('label',
content_tag('label',
check_box_tag( check_box_tag(
'user[notified_project_ids][]', 'user[notified_project_ids][]',
project.id, project.id,
<% end %> <% end %>


<%= fields_for :pref, @user.pref do |pref_fields| %> <%= 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> <p>
<%= pref_fields.check_box :no_self_notified %> <%= pref_fields.check_box :no_self_notified %>
<label for="pref_no_self_notified"><%= l(:label_user_mail_no_self_notified) %></label> <label for="pref_no_self_notified"><%= l(:label_user_mail_no_self_notified) %></label>

+ 1
- 0
config/locales/en.yml View File

label_user_mail_option_only_assigned: "Only for things I watch or I am assigned to" 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_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_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_activation_by_email: account activation by email
label_registration_manual_activation: manual account activation label_registration_manual_activation: manual account activation
label_registration_automatic_activation: automatic account activation label_registration_automatic_activation: automatic account activation

+ 37
- 0
test/functional/my_controller_test.rb View File

assert [mail.bcc, mail.cc].flatten.include?('foobar@example.com') assert [mail.bcc, mail.cc].flatten.include?('foobar@example.com')
end 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 def test_my_account_should_show_destroy_link
get :account get :account
assert_select 'a[href="/my/account/destroy"]' assert_select 'a[href="/my/account/destroy"]'

+ 41
- 0
test/unit/issue_test.rb View File

assert !issue.recipients.include?(issue.assigned_to.mail) assert !issue.recipients.include?(issue.assigned_to.mail)
end 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 def test_last_journal_id_with_journals_should_return_the_journal_id
assert_equal 2, Issue.find(1).last_journal_id assert_equal 2, Issue.find(1).last_journal_id
end end

Loading…
Cancel
Save