Adds To and Cc as watchers when submitting an issue by email (#2245).

Only works if the sender has the 'Add issue watchers' permission.

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@2077 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang
2008-11-30 16:00:45 +00:00
parent 94899e0339
commit 84e70634fb
3 changed files with 67 additions and 0 deletions

View File

@@ -92,7 +92,11 @@ class MailHandler < ActionMailer::Base
issue.save!
add_attachments(issue)
logger.info "MailHandler: issue ##{issue.id} created by #{user}" if logger && logger.info
# send notification before adding watchers since they were cc'ed
Mailer.deliver_issue_add(issue) if Setting.notified_events.include?('issue_added')
# add To and Cc as watchers
add_watchers(issue)
issue
end
@@ -139,6 +143,18 @@ class MailHandler < ActionMailer::Base
end
end
# Adds To and Cc as watchers of the given object if the sender has the
# appropriate permission
def add_watchers(obj)
if user.allowed_to?("add_#{obj.class.name.underscore}_watchers".to_sym, obj.project)
addresses = [email.to, email.cc].flatten.compact.uniq.collect {|a| a.strip.downcase}
unless addresses.empty?
watchers = User.find_active(:all, :conditions => ['LOWER(mail) IN (?)', addresses])
watchers.each {|w| obj.add_watcher(w)}
end
end
end
def get_keyword(attr)
if @@handler_options[:allow_override].include?(attr.to_s) && email.plain_text_body =~ /^#{attr}:[ \t]*(.+)$/i
$1.strip