More flexible mail notifications settings at user level. A user has now 3 options:
* notification on any event on all his projects * notification on any event on selected projects only (if the user belongs to more than 1 project) * notification only for things that he watches or he is involded in (eg. issues that he watches or he is author or assignee) git-svn-id: http://redmine.rubyforge.org/svn/trunk@855 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
@@ -143,6 +143,15 @@ class Issue < ActiveRecord::Base
|
||||
project.assignable_users
|
||||
end
|
||||
|
||||
# Returns the mail adresses of users that should be notified for the issue
|
||||
def recipients
|
||||
recipients = project.recipients
|
||||
# Author and assignee are always notified
|
||||
recipients << author.mail if author
|
||||
recipients << assigned_to.mail if assigned_to
|
||||
recipients.compact.uniq
|
||||
end
|
||||
|
||||
def spent_hours
|
||||
@spent_hours ||= time_entries.sum(:hours) || 0
|
||||
end
|
||||
|
||||
+5
-17
@@ -30,13 +30,7 @@ class Mailer < ActionMailer::Base
|
||||
|
||||
def issue_add(issue)
|
||||
set_language_if_valid(Setting.default_language)
|
||||
# Sends to all project members
|
||||
@recipients = issue.project.members.collect { |m| m.user.mail if m.user.mail_notification }.compact
|
||||
# Sends to author and assignee (even if they turned off mail notification)
|
||||
@recipients << issue.author.mail if issue.author
|
||||
@recipients << issue.assigned_to.mail if issue.assigned_to
|
||||
@recipients.compact!
|
||||
@recipients.uniq!
|
||||
@recipients = issue.recipients
|
||||
@from = Setting.mail_from
|
||||
@subject = "[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}] #{issue.status.name} - #{issue.subject}"
|
||||
@body['issue'] = issue
|
||||
@@ -44,14 +38,8 @@ class Mailer < ActionMailer::Base
|
||||
|
||||
def issue_edit(journal)
|
||||
set_language_if_valid(Setting.default_language)
|
||||
# Sends to all project members
|
||||
issue = journal.journalized
|
||||
@recipients = issue.project.members.collect { |m| m.user.mail if m.user.mail_notification }.compact
|
||||
# Sends to author and assignee (even if they turned off mail notification)
|
||||
@recipients << issue.author.mail if issue.author
|
||||
@recipients << issue.assigned_to.mail if issue.assigned_to
|
||||
@recipients.compact!
|
||||
@recipients.uniq!
|
||||
@recipients = issue.recipients
|
||||
# Watchers in cc
|
||||
@cc = issue.watcher_recipients - @recipients
|
||||
@from = Setting.mail_from
|
||||
@@ -62,7 +50,7 @@ class Mailer < ActionMailer::Base
|
||||
|
||||
def document_added(document)
|
||||
set_language_if_valid(Setting.default_language)
|
||||
@recipients = document.project.users.collect { |u| u.mail if u.mail_notification }.compact
|
||||
@recipients = document.project.recipients
|
||||
@from = Setting.mail_from
|
||||
@subject = "[#{document.project.name}] #{l(:label_document_new)}: #{document.title}"
|
||||
@body['document'] = document
|
||||
@@ -81,7 +69,7 @@ class Mailer < ActionMailer::Base
|
||||
url = {:only_path => false, :host => Setting.host_name, :controller => 'documents', :action => 'show', :id => container.id}
|
||||
added_to = "#{l(:label_document)}: #{container.title}"
|
||||
end
|
||||
@recipients = container.project.users.collect { |u| u.mail if u.mail_notification }.compact
|
||||
@recipients = container.project.recipients
|
||||
@from = Setting.mail_from
|
||||
@subject = "[#{container.project.name}] #{l(:label_attachment_new)}"
|
||||
@body['attachments'] = attachments
|
||||
@@ -91,7 +79,7 @@ class Mailer < ActionMailer::Base
|
||||
|
||||
def news_added(news)
|
||||
set_language_if_valid(Setting.default_language)
|
||||
@recipients = news.project.users.collect { |u| u.mail if u.mail_notification }.compact
|
||||
@recipients = news.project.recipients
|
||||
@from = Setting.mail_from
|
||||
@subject = "[#{news.project.name}] #{l(:label_news)}: #{news.title}"
|
||||
@body['news'] = news
|
||||
|
||||
@@ -118,6 +118,11 @@ class Project < ActiveRecord::Base
|
||||
members.select {|m| m.role.assignable?}.collect {|m| m.user}
|
||||
end
|
||||
|
||||
# Returns the mail adresses of users that should be always notified on project events
|
||||
def recipients
|
||||
members.select {|m| m.mail_notification? || m.user.mail_notification?}.collect {|m| m.user.mail}
|
||||
end
|
||||
|
||||
# Returns an array of all custom fields enabled for project issues
|
||||
# (explictly associated custom fields and custom fields enabled for all projects)
|
||||
def custom_fields_for_issues(tracker)
|
||||
|
||||
@@ -50,6 +50,11 @@ class User < ActiveRecord::Base
|
||||
validates_confirmation_of :password, :allow_nil => true
|
||||
validates_associated :custom_values, :on => :update
|
||||
|
||||
def before_create
|
||||
self.mail_notification = false
|
||||
true
|
||||
end
|
||||
|
||||
def before_save
|
||||
# update hashed_password if password was set
|
||||
self.hashed_password = User.hash_password(self.password) if self.password
|
||||
@@ -131,6 +136,18 @@ class User < ActiveRecord::Base
|
||||
token.value
|
||||
end
|
||||
|
||||
# Return an array of project ids for which the user has explicitly turned mail notifications on
|
||||
def notified_projects_ids
|
||||
@notified_projects_ids ||= memberships.select {|m| m.mail_notification?}.collect(&:project_id)
|
||||
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
|
||||
end
|
||||
|
||||
def self.find_by_rss_key(key)
|
||||
token = Token.find_by_value(key)
|
||||
token && token.user.active? ? token.user : nil
|
||||
|
||||
Reference in New Issue
Block a user