mailpatch-trunk.patch

Oxan -, 2009-10-27 20:30

Download (2.47 KB)

View differences:

app/models/mail_handler.rb (working copy)
152 152
  
153 153
  # Adds a note to an existing issue
154 154
  def receive_issue_reply(issue_id)
155
    status =  (get_keyword(:status) && IssueStatus.find_by_name(get_keyword(:status)))
156
    
155
    # Get issue
157 156
    issue = Issue.find_by_id(issue_id)
158 157
    return unless issue
158

  
159
    # Get project
160
    project = Project.find_by_identifier(get_keyword(:project))
161
    project = issue.project if project.nil?
162
   
163
    # Get other properties
164
    status =  (get_keyword(:status) && IssueStatus.find_by_name(get_keyword(:status)))
165
    priority = (get_keyword(:priority) && Enumeration.find_by_opt_and_name('IPRI', get_keyword(:priority)))
166
    category = (get_keyword(:category) && project.issue_categories.find_by_name(get_keyword(:category)))
167
    tracker = (get_keyword(:tracker) && project.trackers.find_by_name(get_keyword(:tracker)))
168
    target = (get_keyword(:target) && project.versions.find_by_name(get_keyword(:target)))
169
    doneratio = (get_keyword(:done))
170

  
159 171
    # check permission
160 172
    raise UnauthorizedAction unless user.allowed_to?(:add_issue_notes, issue.project) || user.allowed_to?(:edit_issues, issue.project)
161 173
    raise UnauthorizedAction unless status.nil? || user.allowed_to?(:edit_issues, issue.project)
......
163 175
    # add the note
164 176
    journal = issue.init_journal(user, plain_text_body)
165 177
    add_attachments(issue)
178

  
179
    # status
166 180
    # check workflow
167 181
    if status && issue.new_statuses_allowed_to(user).include?(status)
168 182
      issue.status = status
169 183
    end
184

  
185

  
186
    # priority, category, tracker, project, target version and done ratio
187
    issue.priority = priority if priority
188
    issue.category = category if category
189
    issue.tracker = tracker if tracker
190
    issue.project = project
191
    issue.done_ratio = doneratio if doneratio
192

  
193
    # target version
194
    if target.nil? && get_keyword(:target) == 'none'
195
       issue.fixed_version = nil
196
    elsif !target.nil?
197
       issue.fixed_version = target
198
    end  
199

  
200
    # custom fields
201
    issue.custom_field_values = issue.available_custom_fields.inject({}) do |h, c|
202
      if value = get_keyword(c.name, :override => true)
203
        h[c.id] = value
204
      end
205
      h
206
    end
207

  
208
    # save issue
170 209
    issue.save!
171 210
    logger.info "MailHandler: issue ##{issue.id} updated by #{user}" if logger && logger.info
172 211
    journal