diff --git a/app/models/note.rb b/app/models/note.rb index 1578ae9c4cce4b89941b72db7c8172f016a9dabd..2c9980b1a0d4dff54a2eab3229deea0e692800cc 100644 --- a/app/models/note.rb +++ b/app/models/note.rb @@ -313,6 +313,14 @@ class Note < ActiveRecord::Base !system? end + # Since we're using `updated_at` as `last_edited_at`, it could be touched by transforming / resolving a note. + # This makes sure it is only marked as edited when the note body is updated. + def edited? + return false if updated_by.blank? + + super + end + def cross_reference_not_visible_for?(user) cross_reference? && !all_referenced_mentionables_allowed?(user) end diff --git a/changelogs/unreleased/57330-fix-comment-edited.yml b/changelogs/unreleased/57330-fix-comment-edited.yml new file mode 100644 index 0000000000000000000000000000000000000000..68cf6c03d4c9293d7025dd2365135b6be8304a2c --- /dev/null +++ b/changelogs/unreleased/57330-fix-comment-edited.yml @@ -0,0 +1,5 @@ +--- +title: Fix notes being marked as edited after resolving +merge_request: 26143 +author: +type: fixed diff --git a/spec/models/note_spec.rb b/spec/models/note_spec.rb index 385b8a7959f729cfa769381d97dc54efe7abc41f..eb6f6ff5faf911281bc905f32dc61d7a7f425497 100644 --- a/spec/models/note_spec.rb +++ b/spec/models/note_spec.rb @@ -208,6 +208,24 @@ describe Note do end end + describe "edited?" do + let(:note) { build(:note, updated_by_id: nil, created_at: Time.now, updated_at: Time.now + 5.hours) } + + context "with updated_by" do + it "returns true" do + note.updated_by = build(:user) + + expect(note.edited?).to be_truthy + end + end + + context "without updated_by" do + it "returns false" do + expect(note.edited?).to be_falsy + end + end + end + describe "confidential?" do it "delegates to noteable" do issue_note = build(:note, :on_issue)