Commit 09cbe95b20f87ac95dd84a3a033e3f0a1b9aa5a5

Authored by Drew Blessing
1 parent 6579de07

Add note for assignee changes

Change to username per @PixnBits suggestion
app/models/note.rb
... ... @@ -82,6 +82,18 @@ class Note < ActiveRecord::Base
82 82 }, without_protection: true)
83 83 end
84 84  
  85 + def create_assignee_change_note(noteable, project, author, assignee)
  86 + body = assignee.nil? ? '_Assignee removed_' : "_Reassigned to @#{assignee.username}_"
  87 +
  88 + create({
  89 + noteable: noteable,
  90 + project: project,
  91 + author: author,
  92 + note: body,
  93 + system: true
  94 + }, without_protection: true)
  95 + end
  96 +
85 97 def discussions_from_notes(notes)
86 98 discussion_ids = []
87 99 discussions = []
... ...
app/observers/issue_observer.rb
... ... @@ -19,6 +19,7 @@ class IssueObserver < BaseObserver
19 19 def after_update(issue)
20 20 if issue.is_being_reassigned?
21 21 notification.reassigned_issue(issue, current_user)
  22 + create_assignee_note(issue)
22 23 end
23 24  
24 25 issue.notice_added_references(issue.project, current_user)
... ... @@ -32,6 +33,10 @@ class IssueObserver < BaseObserver
32 33 Note.create_status_change_note(issue, issue.project, current_user, issue.state, current_commit)
33 34 end
34 35  
  36 + def create_assignee_note(issue)
  37 + Note.create_assignee_change_note(issue, issue.project, current_user, issue.assignee)
  38 + end
  39 +
35 40 def execute_hooks(issue)
36 41 issue.project.execute_hooks(issue.to_hook_data, :issue_hooks)
37 42 end
... ...
spec/models/note_spec.rb
... ... @@ -180,6 +180,31 @@ describe Note do
180 180 end
181 181 end
182 182  
  183 + describe '#create_assignee_change_note' do
  184 + let(:project) { create(:project) }
  185 + let(:thing) { create(:issue, project: project) }
  186 + let(:author) { create(:user) }
  187 + let(:assignee) { create(:user) }
  188 +
  189 + subject { Note.create_assignee_change_note(thing, project, author, assignee) }
  190 +
  191 + context 'creates and saves a Note' do
  192 + it { should be_a Note }
  193 + its(:id) { should_not be_nil }
  194 + end
  195 +
  196 + its(:noteable) { should == thing }
  197 + its(:project) { should == thing.project }
  198 + its(:author) { should == author }
  199 + its(:note) { should =~ /Reassigned to @#{assignee.username}/ }
  200 +
  201 + context 'assignee is removed' do
  202 + let(:assignee) { nil }
  203 +
  204 + its(:note) { should =~ /Assignee removed/ }
  205 + end
  206 + end
  207 +
183 208 describe '#create_cross_reference_note' do
184 209 let(:project) { create(:project_with_code) }
185 210 let(:author) { create(:user) }
... ... @@ -252,6 +277,7 @@ describe Note do
252 277 let(:issue) { create(:issue, project: project) }
253 278 let(:other) { create(:issue, project: project) }
254 279 let(:author) { create(:user) }
  280 + let(:assignee) { create(:user) }
255 281  
256 282 it 'should recognize user-supplied notes as non-system' do
257 283 @note = create(:note_on_issue)
... ... @@ -267,6 +293,11 @@ describe Note do
267 293 @note = Note.create_cross_reference_note(issue, other, author, project)
268 294 @note.should be_system
269 295 end
  296 +
  297 + it 'should identify assignee-change notes as system notes' do
  298 + @note = Note.create_assignee_change_note(issue, project, author, assignee)
  299 + @note.should be_system
  300 + end
270 301 end
271 302  
272 303 describe :authorization do
... ...