diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-04-15 15:09:18 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-04-15 15:09:18 +0300 |
commit | b7c735c8ac11b8182807070fc6f84f2606e15427 (patch) | |
tree | e74b4d25abb8bbf23546f001dd94515e2840a3a3 /app/models/diff_note_position.rb | |
parent | 221b529789f4090341a825695aeb49b8df6dd11d (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/models/diff_note_position.rb')
-rw-r--r-- | app/models/diff_note_position.rb | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/app/models/diff_note_position.rb b/app/models/diff_note_position.rb index 78e4fbc49eb..716a56c6430 100644 --- a/app/models/diff_note_position.rb +++ b/app/models/diff_note_position.rb @@ -28,9 +28,20 @@ class DiffNotePosition < ApplicationRecord end def position=(position) + assign_attributes(self.class.position_to_attrs(position)) + end + + def self.create_or_update_for(note, params) + attrs = position_to_attrs(params[:position]) + attrs.merge!(params.slice(:diff_type, :line_code)) + attrs[:note_id] = note.id + + upsert(attrs, unique_by: [:note_id, :diff_type]) + end + + def self.position_to_attrs(position) position_attrs = position.to_h position_attrs[:diff_content_type] = position_attrs.delete(:position_type) - - assign_attributes(position_attrs) + position_attrs end end |