diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2013-05-13 17:11:38 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2013-05-13 17:11:38 +0000 |
commit | 4a59b869c04ed3188e1d2de3b9f1879ee3876dec (patch) | |
tree | 8086a4033825feb3611051d871f5d3d72f648855 /app/models/user.rb | |
parent | 10ed306b1935834afa1aad304f1ee5c21cc807d1 (diff) | |
download | redmine-4a59b869c04ed3188e1d2de3b9f1879ee3876dec.tar.gz redmine-4a59b869c04ed3188e1d2de3b9f1879ee3876dec.zip |
Update notified_project_ids while saving record.
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@11840 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app/models/user.rb')
-rw-r--r-- | app/models/user.rb | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/app/models/user.rb b/app/models/user.rb index 25cfebac6..738554d85 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -105,6 +105,7 @@ class User < Principal before_create :set_mail_notification before_save :generate_password_if_needed, :update_hashed_password before_destroy :remove_references_before_destroy + after_save :update_notified_project_ids scope :in_group, lambda {|group| group_id = group.is_a?(Group) ? group.id : group.to_i @@ -133,6 +134,8 @@ class User < Principal @name = nil @projects_by_role = nil @membership_by_project_id = nil + @notified_projects_ids = nil + @notified_projects_ids_changed = false base_reload(*args) end @@ -325,11 +328,19 @@ class User < Principal end def notified_project_ids=(ids) - Member.update_all("mail_notification = #{connection.quoted_false}", ['user_id = ?', id]) - Member.update_all("mail_notification = #{connection.quoted_true}", ['user_id = ? AND project_id IN (?)', id, ids]) if ids && !ids.empty? - @notified_projects_ids = nil - notified_projects_ids + @notified_projects_ids_changed = true + @notified_projects_ids = ids + 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 self.class.valid_notification_options(self) @@ -550,6 +561,7 @@ class User < Principal 'lastname', 'mail', 'mail_notification', + 'notified_project_ids', 'language', 'custom_field_values', 'custom_fields', |