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
...
@@ -74,7 +74,7 @@ module RelativePositioning
end
end
def
relative_siblings
(
relation
=
scoped_items
)
def
relative_siblings
(
relation
=
scoped_items
)
object
.
relative_siblings
(
relation
)
object
.
exclude_self
(
relation
)
end
end
# Handles the possibility that the position is already occupied by a sibling
# Handles the possibility that the position is already occupied by a sibling
...
@@ -114,7 +114,7 @@ module RelativePositioning
...
@@ -114,7 +114,7 @@ module RelativePositioning
def
scoped_items
def
scoped_items
r
=
model_class
.
relative_positioning_query_base
(
object
)
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
r
end
end
...
@@ -597,9 +597,9 @@ module RelativePositioning
...
@@ -597,9 +597,9 @@ module RelativePositioning
.
update_all
(
"relative_position = relative_position +
#{
delta
}
"
)
.
update_all
(
"relative_position = relative_position +
#{
delta
}
"
)
end
end
# This method is used to exclude the current self
from a relation. Customize
# This method is used to exclude the current self
(or another object)
# this if `id <> :id` is not sufficient
#
from a relation. Customize
this if `id <> :id` is not sufficient
def
relative_siblings
(
relation
)
def
exclude_self
(
relation
,
excluded:
self
)
relation
.
id_not_in
(
id
)
relation
.
id_not_in
(
excluded
.
id
)
end
end
end
end
ee/app/models/concerns/epic_tree_sorting.rb
View file @
e01dd08e
...
@@ -34,9 +34,13 @@ module EpicTreeSorting
...
@@ -34,9 +34,13 @@ module EpicTreeSorting
end
end
end
end
override
:relative_siblings
override
:exclude_self
def
relative_siblings
(
relation
)
def
exclude_self
(
relation
,
excluded:
self
)
relation
.
where
.
not
(
'object_type = ? AND id = ?'
,
self
.
class
.
table_name
.
singularize
,
self
.
id
)
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
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