Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Léo-Paul Géneau
gitlab-ce
Commits
d7fa6679
Commit
d7fa6679
authored
Oct 04, 2018
by
Mario de la Ossa
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Backport CE changes from draft_notes addition in EE
parent
42822a7d
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
82 additions
and
67 deletions
+82
-67
app/models/concerns/diff_positionable_note.rb
app/models/concerns/diff_positionable_note.rb
+81
-0
app/models/diff_note.rb
app/models/diff_note.rb
+1
-67
No files found.
app/models/concerns/diff_positionable_note.rb
0 → 100644
View file @
d7fa6679
# frozen_string_literal: true
module
DiffPositionableNote
extend
ActiveSupport
::
Concern
included
do
before_validation
:set_original_position
,
on: :create
before_validation
:update_position
,
on: :create
,
if: :on_text?
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
end
%i(original_position position change_position)
.
each
do
|
meth
|
define_method
"
#{
meth
}
="
do
|
new_position
|
if
new_position
.
is_a?
(
String
)
new_position
=
JSON
.
parse
(
new_position
)
rescue
nil
end
if
new_position
.
is_a?
(
Hash
)
new_position
=
new_position
.
with_indifferent_access
new_position
=
Gitlab
::
Diff
::
Position
.
new
(
new_position
)
end
return
if
new_position
==
read_attribute
(
meth
)
super
(
new_position
)
end
end
def
on_text?
position
&
.
position_type
==
"text"
end
def
on_image?
position
&
.
position_type
==
"image"
end
def
supported?
for_commit?
||
self
.
noteable
.
has_complete_diff_refs?
end
def
active?
(
diff_refs
=
nil
)
return
false
unless
supported?
return
true
if
for_commit?
diff_refs
||=
noteable
.
diff_refs
self
.
position
.
diff_refs
==
diff_refs
end
def
set_original_position
return
unless
position
self
.
original_position
=
self
.
position
.
dup
unless
self
.
original_position
&
.
complete?
end
def
update_position
return
unless
supported?
return
if
for_commit?
return
if
active?
return
unless
position
tracer
=
Gitlab
::
Diff
::
PositionTracer
.
new
(
project:
self
.
project
,
old_diff_refs:
self
.
position
.
diff_refs
,
new_diff_refs:
self
.
noteable
.
diff_refs
,
paths:
self
.
position
.
paths
)
result
=
tracer
.
trace
(
self
.
position
)
return
unless
result
if
result
[
:outdated
]
self
.
change_position
=
result
[
:position
]
else
self
.
position
=
result
[
:position
]
end
end
end
app/models/diff_note.rb
View file @
d7fa6679
...
...
@@ -5,14 +5,11 @@
# A note of this type can be resolvable.
class
DiffNote
<
Note
include
NoteOnDiff
include
DiffPositionableNote
include
Gitlab
::
Utils
::
StrongMemoize
NOTEABLE_TYPES
=
%w(MergeRequest Commit)
.
freeze
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
validates
:original_position
,
presence:
true
validates
:position
,
presence:
true
validates
:line_code
,
presence:
true
,
line_code:
true
,
if: :on_text?
...
...
@@ -21,8 +18,6 @@ class DiffNote < Note
validate
:verify_supported
validate
:diff_refs_match_commit
,
if: :for_commit?
before_validation
:set_original_position
,
on: :create
before_validation
:update_position
,
on: :create
,
if: :on_text?
before_validation
:set_line_code
,
if: :on_text?
after_save
:keep_around_commits
after_commit
:create_diff_file
,
on: :create
...
...
@@ -31,31 +26,6 @@ class DiffNote < Note
DiffDiscussion
end
%i(original_position position change_position)
.
each
do
|
meth
|
define_method
"
#{
meth
}
="
do
|
new_position
|
if
new_position
.
is_a?
(
String
)
new_position
=
JSON
.
parse
(
new_position
)
rescue
nil
end
if
new_position
.
is_a?
(
Hash
)
new_position
=
new_position
.
with_indifferent_access
new_position
=
Gitlab
::
Diff
::
Position
.
new
(
new_position
)
end
return
if
new_position
==
read_attribute
(
meth
)
super
(
new_position
)
end
end
def
on_text?
position
.
position_type
==
"text"
end
def
on_image?
position
.
position_type
==
"image"
end
def
create_diff_file
return
unless
should_create_diff_file?
...
...
@@ -87,15 +57,6 @@ class DiffNote < Note
self
.
diff_file
.
line_code
(
self
.
diff_line
)
end
def
active?
(
diff_refs
=
nil
)
return
false
unless
supported?
return
true
if
for_commit?
diff_refs
||=
noteable
.
diff_refs
self
.
position
.
diff_refs
==
diff_refs
end
def
created_at_diff?
(
diff_refs
)
return
false
unless
supported?
return
true
if
for_commit?
...
...
@@ -141,37 +102,10 @@ class DiffNote < Note
for_commit?
||
self
.
noteable
.
has_complete_diff_refs?
end
def
set_original_position
self
.
original_position
=
self
.
position
.
dup
unless
self
.
original_position
&
.
complete?
end
def
set_line_code
self
.
line_code
=
self
.
position
.
line_code
(
self
.
project
.
repository
)
end
def
update_position
return
unless
supported?
return
if
for_commit?
return
if
active?
tracer
=
Gitlab
::
Diff
::
PositionTracer
.
new
(
project:
self
.
project
,
old_diff_refs:
self
.
position
.
diff_refs
,
new_diff_refs:
self
.
noteable
.
diff_refs
,
paths:
self
.
position
.
paths
)
result
=
tracer
.
trace
(
self
.
position
)
return
unless
result
if
result
[
:outdated
]
self
.
change_position
=
result
[
:position
]
else
self
.
position
=
result
[
:position
]
end
end
def
verify_supported
return
if
supported?
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment