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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
e01dd08e
Commit
e01dd08e
authored
Sep 09, 2020
by
Alex Kalderimis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Deal with model exclusions correctly
This involves custom handling for polymorphic models, and null-safety.
parent
bd0e3267
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
13 additions
and
9 deletions
+13
-9
app/models/concerns/relative_positioning.rb
app/models/concerns/relative_positioning.rb
+6
-6
ee/app/models/concerns/epic_tree_sorting.rb
ee/app/models/concerns/epic_tree_sorting.rb
+7
-3
No files found.
app/models/concerns/relative_positioning.rb
View file @
e01dd08e
...
...
@@ -74,7 +74,7 @@ module RelativePositioning
end
def
relative_siblings
(
relation
=
scoped_items
)
object
.
relative_siblings
(
relation
)
object
.
exclude_self
(
relation
)
end
# Handles the possibility that the position is already occupied by a sibling
...
...
@@ -114,7 +114,7 @@ module RelativePositioning
def
scoped_items
r
=
model_class
.
relative_positioning_query_base
(
object
)
r
=
r
.
id_not_in
(
ignoring
.
id
)
if
ignoring
.
present?
r
=
object
.
exclude_self
(
r
,
excluded:
ignoring
)
if
ignoring
.
present?
r
end
...
...
@@ -597,9 +597,9 @@ module RelativePositioning
.
update_all
(
"relative_position = relative_position +
#{
delta
}
"
)
end
# This method is used to exclude the current self
from a relation. Customize
# this if `id <> :id` is not sufficient
def
relative_siblings
(
relation
)
relation
.
id_not_in
(
id
)
# This method is used to exclude the current self
(or another object)
#
from a relation. Customize
this if `id <> :id` is not sufficient
def
exclude_self
(
relation
,
excluded:
self
)
relation
.
id_not_in
(
excluded
.
id
)
end
end
ee/app/models/concerns/epic_tree_sorting.rb
View file @
e01dd08e
...
...
@@ -34,9 +34,13 @@ module EpicTreeSorting
end
end
override
:relative_siblings
def
relative_siblings
(
relation
)
relation
.
where
.
not
(
'object_type = ? AND id = ?'
,
self
.
class
.
table_name
.
singularize
,
self
.
id
)
override
:exclude_self
def
exclude_self
(
relation
,
excluded:
self
)
return
relation
unless
excluded
&
.
id
.
present?
object_type
=
excluded
.
try
(
:object_type
)
||
excluded
.
class
.
table_name
.
singularize
relation
.
where
.
not
(
'object_type = ? AND id = ?'
,
object_type
,
excluded
.
id
)
end
end
end
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