Update notified_project_ids while saving record.
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@11840 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
10ed306b19
commit
4a59b869c0
|
@ -55,7 +55,6 @@ class MyController < ApplicationController
|
||||||
@user.pref.attributes = params[:pref]
|
@user.pref.attributes = params[:pref]
|
||||||
if @user.save
|
if @user.save
|
||||||
@user.pref.save
|
@user.pref.save
|
||||||
@user.notified_project_ids = (@user.mail_notification == 'selected' ? params[:notified_project_ids] : [])
|
|
||||||
set_language_if_valid @user.language
|
set_language_if_valid @user.language
|
||||||
flash[:notice] = l(:notice_account_updated)
|
flash[:notice] = l(:notice_account_updated)
|
||||||
redirect_to my_account_path
|
redirect_to my_account_path
|
||||||
|
|
|
@ -94,7 +94,6 @@ class UsersController < ApplicationController
|
||||||
if @user.save
|
if @user.save
|
||||||
@user.pref.attributes = params[:pref]
|
@user.pref.attributes = params[:pref]
|
||||||
@user.pref.save
|
@user.pref.save
|
||||||
@user.notified_project_ids = (@user.mail_notification == 'selected' ? params[:notified_project_ids] : [])
|
|
||||||
|
|
||||||
Mailer.account_information(@user, @user.password).deliver if params[:send_information]
|
Mailer.account_information(@user, @user.password).deliver if params[:send_information]
|
||||||
|
|
||||||
|
@ -141,7 +140,6 @@ class UsersController < ApplicationController
|
||||||
|
|
||||||
if @user.save
|
if @user.save
|
||||||
@user.pref.save
|
@user.pref.save
|
||||||
@user.notified_project_ids = (@user.mail_notification == 'selected' ? params[:notified_project_ids] : [])
|
|
||||||
|
|
||||||
if was_activated
|
if was_activated
|
||||||
Mailer.account_activated(@user).deliver
|
Mailer.account_activated(@user).deliver
|
||||||
|
|
|
@ -105,6 +105,7 @@ class User < Principal
|
||||||
before_create :set_mail_notification
|
before_create :set_mail_notification
|
||||||
before_save :generate_password_if_needed, :update_hashed_password
|
before_save :generate_password_if_needed, :update_hashed_password
|
||||||
before_destroy :remove_references_before_destroy
|
before_destroy :remove_references_before_destroy
|
||||||
|
after_save :update_notified_project_ids
|
||||||
|
|
||||||
scope :in_group, lambda {|group|
|
scope :in_group, lambda {|group|
|
||||||
group_id = group.is_a?(Group) ? group.id : group.to_i
|
group_id = group.is_a?(Group) ? group.id : group.to_i
|
||||||
|
@ -133,6 +134,8 @@ class User < Principal
|
||||||
@name = nil
|
@name = nil
|
||||||
@projects_by_role = nil
|
@projects_by_role = nil
|
||||||
@membership_by_project_id = nil
|
@membership_by_project_id = nil
|
||||||
|
@notified_projects_ids = nil
|
||||||
|
@notified_projects_ids_changed = false
|
||||||
base_reload(*args)
|
base_reload(*args)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -325,12 +328,20 @@ class User < Principal
|
||||||
end
|
end
|
||||||
|
|
||||||
def notified_project_ids=(ids)
|
def notified_project_ids=(ids)
|
||||||
Member.update_all("mail_notification = #{connection.quoted_false}", ['user_id = ?', id])
|
@notified_projects_ids_changed = true
|
||||||
Member.update_all("mail_notification = #{connection.quoted_true}", ['user_id = ? AND project_id IN (?)', id, ids]) if ids && !ids.empty?
|
@notified_projects_ids = ids
|
||||||
@notified_projects_ids = nil
|
|
||||||
notified_projects_ids
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Updates per project notifications (after_save callback)
|
||||||
|
def update_notified_project_ids
|
||||||
|
if @notified_projects_ids_changed
|
||||||
|
ids = (mail_notification == 'selected' ? Array.wrap(notified_projects_ids).reject(&:blank?) : [])
|
||||||
|
members.update_all(:mail_notification => false)
|
||||||
|
members.where(:project_id => ids).update_all(:mail_notification => true) if ids.any?
|
||||||
|
end
|
||||||
|
end
|
||||||
|
private :update_notified_project_ids
|
||||||
|
|
||||||
def valid_notification_options
|
def valid_notification_options
|
||||||
self.class.valid_notification_options(self)
|
self.class.valid_notification_options(self)
|
||||||
end
|
end
|
||||||
|
@ -550,6 +561,7 @@ class User < Principal
|
||||||
'lastname',
|
'lastname',
|
||||||
'mail',
|
'mail',
|
||||||
'mail_notification',
|
'mail_notification',
|
||||||
|
'notified_project_ids',
|
||||||
'language',
|
'language',
|
||||||
'custom_field_values',
|
'custom_field_values',
|
||||||
'custom_fields',
|
'custom_fields',
|
||||||
|
|
|
@ -11,12 +11,13 @@
|
||||||
<%= 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(
|
||||||
'notified_project_ids[]',
|
'user[notified_project_ids][]',
|
||||||
project.id,
|
project.id,
|
||||||
@user.notified_projects_ids.include?(project.id)
|
@user.notified_projects_ids.include?(project.id)
|
||||||
) + ' ' + h(project.name)
|
) + ' ' + h(project.name)
|
||||||
)
|
)
|
||||||
end %>
|
end %>
|
||||||
|
<%= hidden_field_tag 'user[notified_project_ids][]', '' %>
|
||||||
<p><em class="info"><%= l(:text_user_mail_option) %></em></p>
|
<p><em class="info"><%= l(:text_user_mail_option) %></em></p>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
|
|
|
@ -364,17 +364,13 @@ class UsersControllerTest < ActionController::TestCase
|
||||||
u = User.find(2)
|
u = User.find(2)
|
||||||
assert_equal [1, 2, 5], u.projects.collect{|p| p.id}.sort
|
assert_equal [1, 2, 5], u.projects.collect{|p| p.id}.sort
|
||||||
assert_equal [1, 2, 5], u.notified_projects_ids.sort
|
assert_equal [1, 2, 5], u.notified_projects_ids.sort
|
||||||
assert_tag :tag => 'input',
|
assert_select 'input[name=?][value=?]', 'user[notified_project_ids][]', '1'
|
||||||
:attributes => {
|
|
||||||
:id => 'notified_project_ids_',
|
|
||||||
:value => 1,
|
|
||||||
}
|
|
||||||
assert_equal 'all', u.mail_notification
|
assert_equal 'all', u.mail_notification
|
||||||
put :update, :id => 2,
|
put :update, :id => 2,
|
||||||
:user => {
|
:user => {
|
||||||
:mail_notification => 'selected',
|
:mail_notification => 'selected',
|
||||||
},
|
:notified_project_ids => [1, 2]
|
||||||
:notified_project_ids => [1, 2]
|
}
|
||||||
u = User.find(2)
|
u = User.find(2)
|
||||||
assert_equal 'selected', u.mail_notification
|
assert_equal 'selected', u.mail_notification
|
||||||
assert_equal [1, 2], u.notified_projects_ids.sort
|
assert_equal [1, 2], u.notified_projects_ids.sort
|
||||||
|
|
Loading…
Reference in New Issue