]> source.dussan.org Git - redmine.git/commitdiff
Mail handler: check workflow for status set/change.
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Sun, 30 Nov 2008 14:55:45 +0000 (14:55 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Sun, 30 Nov 2008 14:55:45 +0000 (14:55 +0000)
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@2074 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/models/mail_handler.rb

index f8e60b6b59edff03af7b6fe58817c747cfe36f69..8554982110b929d5d10c30f27aa9cc13991c0024 100644 (file)
@@ -31,7 +31,7 @@ class MailHandler < ActionMailer::Base
     @@handler_options[:allow_override] ||= []
     # Project needs to be overridable if not specified
     @@handler_options[:allow_override] << 'project' unless @@handler_options[:issue].has_key?(:project)
-    # Status needs to be overridable if not specified
+    # Status overridable by default
     @@handler_options[:allow_override] << 'status' unless @@handler_options[:issue].has_key?(:status)    
     super email
   end
@@ -78,11 +78,15 @@ class MailHandler < ActionMailer::Base
     tracker = (get_keyword(:tracker) && project.trackers.find_by_name(get_keyword(:tracker))) || project.trackers.find(:first)
     category = (get_keyword(:category) && project.issue_categories.find_by_name(get_keyword(:category)))
     priority = (get_keyword(:priority) && Enumeration.find_by_opt_and_name('IPRI', get_keyword(:priority)))
-    status =  (get_keyword(:status) && IssueStatus.find_by_name(get_keyword(:status))) || IssueStatus.default
+    status =  (get_keyword(:status) && IssueStatus.find_by_name(get_keyword(:status)))
 
     # check permission
     raise UnauthorizedAction unless user.allowed_to?(:add_issues, project)
-    issue = Issue.new(:author => user, :project => project, :tracker => tracker, :category => category, :priority => priority, :status => status)
+    issue = Issue.new(:author => user, :project => project, :tracker => tracker, :category => category, :priority => priority)
+    # check workflow
+    if status && issue.new_statuses_allowed_to(user).include?(status)
+      issue.status = status
+    end
     issue.subject = email.subject.chomp.toutf8
     issue.description = email.plain_text_body.chomp
     issue.save!
@@ -114,7 +118,10 @@ class MailHandler < ActionMailer::Base
     # add the note
     journal = issue.init_journal(user, email.plain_text_body.chomp)
     add_attachments(issue)
-    issue.status = status unless status.nil?
+    # check workflow
+    if status && issue.new_statuses_allowed_to(user).include?(status)
+      issue.status = status
+    end
     issue.save!
     logger.info "MailHandler: issue ##{issue.id} updated by #{user}" if logger && logger.info
     Mailer.deliver_issue_edit(journal) if Setting.notified_events.include?('issue_updated')