Commit 0253c949a2569e02eba7585a794e0db4aaee4406
Exists in
spb-stable
and in
3 other branches
Merge pull request #5933 from dblessing/feature/assignee_changes_in_timeline
Add note for assignee changes
Showing
3 changed files
with
48 additions
and
0 deletions
Show diff stats
app/models/note.rb
| @@ -82,6 +82,18 @@ class Note < ActiveRecord::Base | @@ -82,6 +82,18 @@ class Note < ActiveRecord::Base | ||
| 82 | }, without_protection: true) | 82 | }, without_protection: true) |
| 83 | end | 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 | def discussions_from_notes(notes) | 97 | def discussions_from_notes(notes) |
| 86 | discussion_ids = [] | 98 | discussion_ids = [] |
| 87 | discussions = [] | 99 | discussions = [] |
app/observers/issue_observer.rb
| @@ -19,6 +19,7 @@ class IssueObserver < BaseObserver | @@ -19,6 +19,7 @@ class IssueObserver < BaseObserver | ||
| 19 | def after_update(issue) | 19 | def after_update(issue) |
| 20 | if issue.is_being_reassigned? | 20 | if issue.is_being_reassigned? |
| 21 | notification.reassigned_issue(issue, current_user) | 21 | notification.reassigned_issue(issue, current_user) |
| 22 | + create_assignee_note(issue) | ||
| 22 | end | 23 | end |
| 23 | 24 | ||
| 24 | issue.notice_added_references(issue.project, current_user) | 25 | issue.notice_added_references(issue.project, current_user) |
| @@ -32,6 +33,10 @@ class IssueObserver < BaseObserver | @@ -32,6 +33,10 @@ class IssueObserver < BaseObserver | ||
| 32 | Note.create_status_change_note(issue, issue.project, current_user, issue.state, current_commit) | 33 | Note.create_status_change_note(issue, issue.project, current_user, issue.state, current_commit) |
| 33 | end | 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 | def execute_hooks(issue) | 40 | def execute_hooks(issue) |
| 36 | issue.project.execute_hooks(issue.to_hook_data, :issue_hooks) | 41 | issue.project.execute_hooks(issue.to_hook_data, :issue_hooks) |
| 37 | end | 42 | end |
spec/models/note_spec.rb
| @@ -180,6 +180,31 @@ describe Note do | @@ -180,6 +180,31 @@ describe Note do | ||
| 180 | end | 180 | end |
| 181 | end | 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 | describe '#create_cross_reference_note' do | 208 | describe '#create_cross_reference_note' do |
| 184 | let(:project) { create(:project_with_code) } | 209 | let(:project) { create(:project_with_code) } |
| 185 | let(:author) { create(:user) } | 210 | let(:author) { create(:user) } |
| @@ -252,6 +277,7 @@ describe Note do | @@ -252,6 +277,7 @@ describe Note do | ||
| 252 | let(:issue) { create(:issue, project: project) } | 277 | let(:issue) { create(:issue, project: project) } |
| 253 | let(:other) { create(:issue, project: project) } | 278 | let(:other) { create(:issue, project: project) } |
| 254 | let(:author) { create(:user) } | 279 | let(:author) { create(:user) } |
| 280 | + let(:assignee) { create(:user) } | ||
| 255 | 281 | ||
| 256 | it 'should recognize user-supplied notes as non-system' do | 282 | it 'should recognize user-supplied notes as non-system' do |
| 257 | @note = create(:note_on_issue) | 283 | @note = create(:note_on_issue) |
| @@ -267,6 +293,11 @@ describe Note do | @@ -267,6 +293,11 @@ describe Note do | ||
| 267 | @note = Note.create_cross_reference_note(issue, other, author, project) | 293 | @note = Note.create_cross_reference_note(issue, other, author, project) |
| 268 | @note.should be_system | 294 | @note.should be_system |
| 269 | end | 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 | end | 301 | end |
| 271 | 302 | ||
| 272 | describe :authorization do | 303 | describe :authorization do |