Feature #1935 » never_notify.patch
| app/controllers/my_controller.rb | ||
|---|---|---|
|
@user.mail_notification = (params[:notification_option] == 'all')
|
||
|
@user.pref.attributes = params[:pref]
|
||
|
@user.pref[:no_self_notified] = (params[:no_self_notified] == '1')
|
||
|
@user.never_notify = (params[:notification_option] == 'never')
|
||
|
if @user.save
|
||
|
@user.pref.save
|
||
|
@user.notified_project_ids = (params[:notification_option] == 'selected' ? params[:notified_project_ids] : [])
|
||
| ... | ... | |
|
end
|
||
|
end
|
||
|
@notification_options = [[l(:label_user_mail_option_all), 'all'],
|
||
|
[l(:label_user_mail_option_none), 'none']]
|
||
|
[l(:label_user_mail_option_none), 'none'],
|
||
|
[l(:label_user_mail_option_never), 'never']]
|
||
|
# Only users that belong to more than 1 project can select projects for which they are notified
|
||
|
# Note that @user.membership.size would fail since AR ignores :include association option when doing a count
|
||
|
@notification_options.insert 1, [l(:label_user_mail_option_selected), 'selected'] if @user.memberships.length > 1
|
||
|
@notification_option = @user.mail_notification? ? 'all' : (@user.notified_projects_ids.empty? ? 'none' : 'selected')
|
||
|
@notification_option = @user.mail_notification? ? 'all' : (@user.notified_projects_ids.empty? ? 'none' : 'selected')
|
||
|
@notification_option = 'never' if @user.never_notify?
|
||
|
end
|
||
|
# Manage user's password
|
||
| app/models/issue.rb | ||
|---|---|---|
|
def recipients
|
||
|
recipients = project.recipients
|
||
|
# Author and assignee are always notified unless they have been locked
|
||
|
recipients << author.mail if author && author.active?
|
||
|
recipients << assigned_to.mail if assigned_to && assigned_to.active?
|
||
|
recipients << author.mail if author && author.active? && !author.never_notify?
|
||
|
recipients << assigned_to.mail if assigned_to && assigned_to.active? && !assigned_to.never_notify?
|
||
|
recipients.compact.uniq
|
||
|
end
|
||
|
|
||
| app/models/user.rb | ||
|---|---|---|
|
end
|
||
|
end
|
||
|
|
||
|
def never_notify?
|
||
|
self.pref[:never_notify] == true
|
||
|
end
|
||
|
def never_notify=(notify)
|
||
|
self.pref[:never_notify] = notify
|
||
|
self.pref.save!
|
||
|
self.pref[:never_notify]
|
||
|
end
|
||
|
def self.current=(user)
|
||
|
@current_user = user
|
||
|
end
|
||
| app/views/my/account.rhtml | ||
|---|---|---|
|
<h3><%=l(:field_mail_notification)%></h3>
|
||
|
<div class="box">
|
||
|
<%= select_tag 'notification_option', options_for_select(@notification_options, @notification_option),
|
||
|
:onchange => 'if ($("notification_option").value == "selected") {Element.show("notified-projects")} else {Element.hide("notified-projects")}' %>
|
||
|
:onchange => 'if ($("notification_option").value == "selected") {Element.show("notified-projects")} else {Element.hide("notified-projects")}; if ($("notification_option").value != "never") {Element.show("self_notification")} else {Element.hide("self_notification")};' %>
|
||
|
<% content_tag 'div', :id => 'notified-projects', :style => (@notification_option == 'selected' ? '' : 'display:none;') do %>
|
||
|
<p><% User.current.projects.each do |project| %>
|
||
|
<label><%= check_box_tag 'notified_project_ids[]', project.id, @user.notified_projects_ids.include?(project.id) %> <%=h project.name %></label><br />
|
||
|
<% end %></p>
|
||
|
<p><em><%= l(:text_user_mail_option) %></em></p>
|
||
|
<% end %>
|
||
|
<p><label><%= check_box_tag 'no_self_notified', 1, @user.pref[:no_self_notified] %> <%= l(:label_user_mail_no_self_notified) %></label></p>
|
||
|
<% content_tag 'p', :id => 'self_notification', :style => (@notification_option != 'never' ? '' : 'display:none;') do %>
|
||
|
<label><%= check_box_tag 'no_self_notified', 1, @user.pref[:no_self_notified] %> <%= l(:label_user_mail_no_self_notified) %></label>
|
||
|
<% end %>
|
||
|
</div>
|
||
|
<h3><%=l(:label_preferences)%></h3>
|
||
| lang/de.yml | ||
|---|---|---|
|
label_user_mail_option_all: "Für alle Ereignisse in all meinen Projekten"
|
||
|
label_user_mail_option_selected: "Für alle Ereignisse in den ausgewählten Projekten..."
|
||
|
label_user_mail_option_none: "Nur für Dinge, die ich beobachte oder an denen ich beteiligt bin"
|
||
|
label_user_mail_option_never: "Nie per Email benachrichtigen"
|
||
|
label_user_mail_no_self_notified: "Ich möchte nicht über Änderungen benachrichtigt werden, die ich selbst durchführe."
|
||
|
label_registration_activation_by_email: Kontoaktivierung durch E-Mail
|
||
|
label_registration_manual_activation: Manuelle Kontoaktivierung
|
||
| lang/en.yml | ||
|---|---|---|
|
label_user_mail_option_all: "For any event on all my projects"
|
||
|
label_user_mail_option_selected: "For any event on the selected projects only..."
|
||
|
label_user_mail_option_none: "Only for things I watch or I'm involved in"
|
||
|
label_user_mail_option_never: "Never notify me by mail"
|
||
|
label_user_mail_no_self_notified: "I don't want to be notified of changes that I make myself"
|
||
|
label_registration_activation_by_email: account activation by email
|
||
|
label_registration_manual_activation: manual account activation
|
||
| test/unit/user_test.rb | ||
|---|---|---|
|
require File.dirname(__FILE__) + '/../test_helper'
|
||
|
class UserTest < Test::Unit::TestCase
|
||
|
fixtures :users, :members, :projects
|
||
|
fixtures :users, :members, :projects, :issues, :user_preferences
|
||
|
def setup
|
||
|
@admin = User.find(1)
|
||
| ... | ... | |
|
assert !@jsmith.projects.first.recipients.include?(@jsmith.mail)
|
||
|
end
|
||
|
|
||
|
def test_mail_notification_never
|
||
|
assert Issue.first.recipients.include?(@jsmith.mail)
|
||
|
@jsmith.mail_notification = false
|
||
|
@jsmith.notified_project_ids = []
|
||
|
@jsmith.never_notify = true
|
||
|
@jsmith.save
|
||
|
@jsmith.reload
|
||
|
assert @jsmith.preference[:never_notify] == true
|
||
|
assert !Issue.first.recipients.include?(@jsmith.mail)
|
||
|
end
|
||
|
|
||
|
def test_comments_sorting_preference
|
||
|
assert !@jsmith.wants_comments_in_reverse_order?
|
||
|
@jsmith.pref.comments_sorting = 'asc'
|
||
| test/unit/watcher_test.rb | ||
|---|---|---|
|
@user.save
|
||
|
@issue.reload
|
||
|
assert @issue.watcher_recipients.include?(@user.mail)
|
||
|
|
||
|
@user.never_notify = true
|
||
|
@user.save
|
||
|
@issue.reload
|
||
|
assert !@issue.watcher_recipients.include?(@user.mail)
|
||
|
end
|
||
|
|
||
|
def test_unwatch
|
||
| vendor/plugins/acts_as_watchable/lib/acts_as_watchable.rb | ||
|---|---|---|
|
|
||
|
# Returns an array of watchers' email addresses
|
||
|
def watcher_recipients
|
||
|
self.watchers.collect { |w| w.user.mail if w.user.active? }.compact
|
||
|
self.watchers.collect { |w| w.user.mail if w.user.active? && !w.user.never_notify? }.compact
|
||
|
end
|
||
|
module ClassMethods
|
||