summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHeinrich Lee Yu <heinrich@gitlab.com>2019-03-14 12:00:12 +0800
committerHeinrich Lee Yu <heinrich@gitlab.com>2019-03-14 12:46:23 +0800
commitf5f243a0366d7069205c5a5a4ceb326bc0c7180e (patch)
tree076e494087a6be11cab1e45c6f5b472626981427
parenta59b7cee0afc152efba6aa4c430c14c0b038107a (diff)
downloadgitlab-ce-f5f243a0366d7069205c5a5a4ceb326bc0c7180e.tar.gz
Hide "Edited" when note is transformed or resolved
Makes `Note#edited?` return `false` when the note body was not edited
-rw-r--r--app/models/note.rb8
-rw-r--r--changelogs/unreleased/57330-fix-comment-edited.yml5
-rw-r--r--spec/models/note_spec.rb18
3 files changed, 31 insertions, 0 deletions
diff --git a/app/models/note.rb b/app/models/note.rb
index 1578ae9c4cc..2c9980b1a0d 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 00000000000..68cf6c03d4c
--- /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 385b8a7959f..eb6f6ff5faf 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)