diff options
author | Paul Slaughter <pslaughter@gitlab.com> | 2019-08-02 04:46:45 +0300 |
---|---|---|
committer | Paul Slaughter <pslaughter@gitlab.com> | 2019-08-02 04:46:45 +0300 |
commit | d62227a38b1e43ca4687bd4782f10bab16a866eb (patch) | |
tree | f80145077d4017f1cbe33923cbc658d1d46b7449 /app | |
parent | 325c321c72520245406c5bdb0c4c3df7f2020d61 (diff) | |
parent | d90865a9607a8fed4ebc9669aad6f0cf939720b5 (diff) |
Merge branch '10646-create-drafts-with-commit-id-ce' into 'master'
CE port of https://gitlab.com/gitlab-org/gitlab-ee/merge_requests/14520
See merge request gitlab-org/gitlab-ce!30284
Diffstat (limited to 'app')
-rw-r--r-- | app/models/concerns/diff_positionable_note.rb | 8 | ||||
-rw-r--r-- | app/models/diff_note.rb | 7 |
2 files changed, 8 insertions, 7 deletions
diff --git a/app/models/concerns/diff_positionable_note.rb b/app/models/concerns/diff_positionable_note.rb index 2d09eff0111..195d9e107c5 100644 --- a/app/models/concerns/diff_positionable_note.rb +++ b/app/models/concerns/diff_positionable_note.rb @@ -10,6 +10,8 @@ module DiffPositionableNote serialize :original_position, Gitlab::Diff::Position # rubocop:disable Cop/ActiveRecordSerialize serialize :position, Gitlab::Diff::Position # rubocop:disable Cop/ActiveRecordSerialize serialize :change_position, Gitlab::Diff::Position # rubocop:disable Cop/ActiveRecordSerialize + + validate :diff_refs_match_commit, if: :for_commit? end %i(original_position position change_position).each do |meth| @@ -71,4 +73,10 @@ module DiffPositionableNote self.position = result[:position] end end + + def diff_refs_match_commit + return if self.original_position.diff_refs == commit&.diff_refs + + errors.add(:commit_id, 'does not match the diff refs') + end end diff --git a/app/models/diff_note.rb b/app/models/diff_note.rb index f75c32633b1..861185dc222 100644 --- a/app/models/diff_note.rb +++ b/app/models/diff_note.rb @@ -20,7 +20,6 @@ class DiffNote < Note validates :noteable_type, inclusion: { in: -> (_note) { noteable_types } } validate :positions_complete validate :verify_supported - validate :diff_refs_match_commit, if: :for_commit? before_validation :set_line_code, if: :on_text? after_save :keep_around_commits @@ -154,12 +153,6 @@ class DiffNote < Note errors.add(:position, "is invalid") end - def diff_refs_match_commit - return if self.original_position.diff_refs == self.commit.diff_refs - - errors.add(:commit_id, 'does not match the diff refs') - end - def keep_around_commits shas = [ self.original_position.base_sha, |