Project

General

Profile

Feature #37978 » add-email-notification-option-only-i-watch.patch

Takenori TAKAKI, 2024-03-21 09:10

View differences:

app/models/project.rb
# Returns the users that should be notified on project events
def notified_users
users.where('members.mail_notification = ? OR users.mail_notification = ?', true, 'all')
users.where('(members.mail_notification = ? OR users.mail_notification = ?) AND users.mail_notification <> ?', true, 'all', 'only_i_watch')
end
# Returns a scope of all custom fields enabled for project issues
app/models/user.rb
['selected', :label_user_mail_option_selected],
['only_my_events', :label_user_mail_option_only_my_events],
['only_assigned', :label_user_mail_option_only_assigned],
['only_i_watch', :label_user_mail_option_only_i_watch],
['only_owner', :label_user_mail_option_only_owner],
['none', :label_user_mail_option_none]
]
......
def notify_about?(object)
if mail_notification == 'all'
true
elsif mail_notification.blank? || mail_notification == 'none'
elsif mail_notification.blank? || mail_notification == 'none' || mail_notification == 'only_i_watch'
false
else
case object
config/locales/en.yml
label_user_mail_option_none: "No events"
label_user_mail_option_only_my_events: "Only for things I watch or I'm involved in"
label_user_mail_option_only_assigned: "Only for things I watch or I am assigned to"
label_user_mail_option_only_i_watch: "Only for things I watch"
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"
config/locales/ja.yml
label_user_mail_option_none: "通知しない"
label_user_mail_option_only_my_events: "ウォッチ中または自分が関係しているもの"
label_user_mail_option_only_assigned: "ウォッチ中または自分が担当しているもの"
label_user_mail_option_only_i_watch: "ウォッチ中のもの"
label_user_mail_option_only_owner: "ウォッチ中または自分が作成したもの"
label_user_mail_no_self_notified: 自分自身による変更の通知は不要
label_registration_activation_by_email: メールでアカウントを有効化
test/unit/project_test.rb
only_owned_user = User.generate!(:mail_notification => 'only_owner')
Member.create!(:project => project, :roles => [role], :principal => only_owned_user)
only_i_watch_user = User.generate!(:mail_notification => 'only_i_watch')
Member.create!(:project => project, :roles => [role], :mail_notification => true, :principal => only_i_watch_user)
assert project.notified_users.include?(user_with_membership_notification),
"should include members with a mail notification"
assert project.notified_users.include?(all_events_user),
......
"should not include users with the 'only_assigned' notification option"
assert !project.notified_users.include?(only_owned_user),
"should not include users with the 'only_owner' notification option"
assert !project.notified_users.include?(only_i_watch_user),
"should not include users with the 'only_i_watch' notification option"
end
def test_override_roles_without_builtin_group_memberships
test/unit/user_test.rb
def test_valid_notification_options
# without memberships
assert_equal 5, User.find(7).valid_notification_options.size
assert_equal 6, User.find(7).valid_notification_options.size
# with memberships
assert_equal 6, User.find(2).valid_notification_options.size
assert_equal 7, User.find(2).valid_notification_options.size
end
def test_valid_notification_options_class_method
assert_equal 5, User.valid_notification_options.size
assert_equal 5, User.valid_notification_options(User.find(7)).size
assert_equal 6, User.valid_notification_options(User.find(2)).size
assert_equal 6, User.valid_notification_options.size
assert_equal 6, User.valid_notification_options(User.find(7)).size
assert_equal 7, User.valid_notification_options(User.find(2)).size
end
def test_notified_project_ids_setter_should_coerce_to_unique_integer_array
......
assert_equal expected.include?(option), user.notify_about?(issue)
end
end
[author, assignee, member].each do |user|
user.mail_notification = 'all'
assert user.notify_about?(issue)
%w(none only_i_watch).each do |option|
user.mail_notification = option
assert !user.notify_about?(issue)
end
end
end
def test_notify_about_issue_for_previous_assignee
......
User::MAIL_NOTIFICATION_OPTIONS.map(&:first).each do |option|
user.mail_notification = option
assert_equal (option != 'none'), user.notify_about?(news)
assert_equal (option != 'none' && option != 'only_i_watch'), user.notify_about?(news)
end
end
(1-1/3)