Patch by Mizuki ISHIKAWA. git-svn-id: https://svn.redmine.org/redmine/trunk@22438 e93f8b46-1217-0410-a6f0-8f06a7374b81pull/147/head
end | end | ||||
def bookmark | def bookmark | ||||
jump_box = Redmine::ProjectJumpBox.new User.current | |||||
user = User.current | |||||
jump_box = Redmine::ProjectJumpBox.new user | |||||
if request.delete? | if request.delete? | ||||
jump_box.delete_project_bookmark @project | jump_box.delete_project_bookmark @project | ||||
user.update_notified_bookmarked_project_ids(@project) | |||||
elsif request.post? | elsif request.post? | ||||
jump_box.bookmark_project @project | jump_box.bookmark_project @project | ||||
user.update_notified_bookmarked_project_ids(@project) | |||||
end | end | ||||
respond_to do |format| | respond_to do |format| | ||||
format.js | format.js |
MAIL_NOTIFICATION_OPTIONS = [ | MAIL_NOTIFICATION_OPTIONS = [ | ||||
['all', :label_user_mail_option_all], | ['all', :label_user_mail_option_all], | ||||
['selected', :label_user_mail_option_selected], | ['selected', :label_user_mail_option_selected], | ||||
['bookmarked', :label_user_mail_option_bookmarked], | |||||
['only_my_events', :label_user_mail_option_only_my_events], | ['only_my_events', :label_user_mail_option_only_my_events], | ||||
['only_assigned', :label_user_mail_option_only_assigned], | ['only_assigned', :label_user_mail_option_only_assigned], | ||||
['only_owner', :label_user_mail_option_only_owner], | ['only_owner', :label_user_mail_option_only_owner], | ||||
# Updates per project notifications (after_save callback) | # Updates per project notifications (after_save callback) | ||||
def update_notified_project_ids | def update_notified_project_ids | ||||
if @notified_projects_ids_changed | if @notified_projects_ids_changed | ||||
ids = (mail_notification == 'selected' ? Array.wrap(notified_projects_ids).reject(&:blank?) : []) | |||||
ids = [] | |||||
if mail_notification == 'selected' | |||||
ids = Array.wrap(notified_projects_ids).reject(&:blank?) | |||||
elsif mail_notification == 'bookmarked' | |||||
ids = Array.wrap(bookmarked_project_ids).reject(&:blank?) | |||||
end | |||||
members.update_all(:mail_notification => false) | members.update_all(:mail_notification => false) | ||||
members.where(:project_id => ids).update_all(:mail_notification => true) if ids.any? | members.where(:project_id => ids).update_all(:mail_notification => true) if ids.any? | ||||
end | end | ||||
end | end | ||||
private :update_notified_project_ids | private :update_notified_project_ids | ||||
def update_notified_bookmarked_project_ids(project_id) | |||||
if mail_notification == 'bookmarked' | |||||
@notified_projects_ids_changed = true | |||||
self.update_notified_project_ids | |||||
end | |||||
end | |||||
def valid_notification_options | def valid_notification_options | ||||
self.class.valid_notification_options(self) | self.class.valid_notification_options(self) | ||||
end | end | ||||
case object | case object | ||||
when Issue | when Issue | ||||
case mail_notification | case mail_notification | ||||
when 'selected', 'only_my_events' | |||||
when 'selected', 'only_my_events', 'bookmarked' | |||||
# user receives notifications for created/assigned issues on unselected projects | # user receives notifications for created/assigned issues on unselected projects | ||||
object.author == self || is_or_belongs_to?(object.assigned_to) || is_or_belongs_to?(object.previous_assignee) | object.author == self || is_or_belongs_to?(object.assigned_to) || is_or_belongs_to?(object.previous_assignee) | ||||
when 'only_assigned' | when 'only_assigned' |
label_search_titles_only: Search titles only | label_search_titles_only: Search titles only | ||||
label_user_mail_option_all: "For any event on all my projects" | 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_selected: "For any event on the selected projects only..." | ||||
label_user_mail_option_bookmarked: "For any event on my bookmarked projects" | |||||
label_user_mail_option_none: "No events" | 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_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_assigned: "Only for things I watch or I am assigned to" |
label_search_titles_only: タイトルのみ | label_search_titles_only: タイトルのみ | ||||
label_user_mail_option_all: "参加しているプロジェクトのすべての通知" | label_user_mail_option_all: "参加しているプロジェクトのすべての通知" | ||||
label_user_mail_option_selected: "選択したプロジェクトのすべての通知..." | label_user_mail_option_selected: "選択したプロジェクトのすべての通知..." | ||||
label_user_mail_option_bookmarked: "ブックマークしているプロジェクトのすべての通知" | |||||
label_user_mail_option_none: "通知しない" | label_user_mail_option_none: "通知しない" | ||||
label_user_mail_option_only_my_events: "ウォッチ中または自分が関係しているもの" | label_user_mail_option_only_my_events: "ウォッチ中または自分が関係しているもの" | ||||
label_user_mail_option_only_assigned: "ウォッチ中または自分が担当しているもの" | label_user_mail_option_only_assigned: "ウォッチ中または自分が担当しているもの" |
refute jb.bookmark?(Project.find('ecookbook')) | refute jb.bookmark?(Project.find('ecookbook')) | ||||
end | end | ||||
def test_bookmark_should_update_notified_project_ids_if_mail_notification_is_bookmarked | |||||
user = User.find(2) | |||||
@request.session[:user_id] = user.id | |||||
user.update(mail_notification: 'bookmarked') | |||||
post(:bookmark, :params => {:id => 'ecookbook'}) | |||||
assert_equal [true, false, false], user.members.order(:id).pluck(:mail_notification) | |||||
delete(:bookmark, :params => {:id => 'ecookbook'}) | |||||
assert_equal [false, false, false], user.members.order(:id).pluck(:mail_notification) | |||||
end | |||||
def test_index_jump_without_project_id_should_redirect_to_active_tab | def test_index_jump_without_project_id_should_redirect_to_active_tab | ||||
get(:index, :params => {:jump => 'issues'}) | get(:index, :params => {:jump => 'issues'}) | ||||
assert_redirected_to '/issues' | assert_redirected_to '/issues' |
only_my_events_user = User.generate!(:mail_notification => 'only_my_events') | only_my_events_user = User.generate!(:mail_notification => 'only_my_events') | ||||
Member.create!(:project => project, :roles => [role], :principal => only_my_events_user) | Member.create!(:project => project, :roles => [role], :principal => only_my_events_user) | ||||
bookmarked_user = User.generate!(:mail_notification => 'bookmarked') | |||||
Member.create!(:project => project, :roles => [role], :principal => bookmarked_user) | |||||
only_assigned_user = User.generate!(:mail_notification => 'only_assigned') | only_assigned_user = User.generate!(:mail_notification => 'only_assigned') | ||||
Member.create!(:project => project, :roles => [role], :principal => only_assigned_user) | Member.create!(:project => project, :roles => [role], :principal => only_assigned_user) | ||||
"should not include users with the 'none' notification option" | "should not include users with the 'none' notification option" | ||||
assert !project.notified_users.include?(only_my_events_user), | assert !project.notified_users.include?(only_my_events_user), | ||||
"should not include users with the 'only_my_events' notification option" | "should not include users with the 'only_my_events' notification option" | ||||
assert !project.notified_users.include?(bookmarked_user), | |||||
"should not include users with the 'bookmarked' notification option" | |||||
assert !project.notified_users.include?(only_assigned_user), | assert !project.notified_users.include?(only_assigned_user), | ||||
"should not include users with the 'only_assigned' notification option" | "should not include users with the 'only_assigned' notification option" | ||||
assert !project.notified_users.include?(only_owned_user), | assert !project.notified_users.include?(only_owned_user), |
def test_valid_notification_options | def test_valid_notification_options | ||||
# without memberships | # without memberships | ||||
assert_equal 5, User.find(7).valid_notification_options.size | |||||
assert_equal 6, User.find(7).valid_notification_options.size | |||||
# with memberships | # with memberships | ||||
assert_equal 6, User.find(2).valid_notification_options.size | |||||
assert_equal 7, User.find(2).valid_notification_options.size | |||||
end | end | ||||
def test_valid_notification_options_class_method | 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 | end | ||||
def test_notified_project_ids_setter_should_coerce_to_unique_integer_array | def test_notified_project_ids_setter_should_coerce_to_unique_integer_array | ||||
issue = Issue.generate!(:project => project, :assigned_to => assignee, :author => author) | issue = Issue.generate!(:project => project, :assigned_to => assignee, :author => author) | ||||
tests = { | tests = { | ||||
author => %w(all only_my_events only_owner selected), | |||||
assignee => %w(all only_my_events only_assigned selected), | |||||
author => %w(all only_my_events only_owner selected bookmarked), | |||||
assignee => %w(all only_my_events only_assigned selected bookmarked), | |||||
member => %w(all) | member => %w(all) | ||||
} | } | ||||