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
3fa89854
Commit
3fa89854
authored
Apr 07, 2017
by
Adam Niedzielski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Reuse "merge_requests_for_nodes" in "MergeRequestParser"
parent
c98add15
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
30 additions
and
11 deletions
+30
-11
lib/banzai/reference_parser/merge_request_parser.rb
lib/banzai/reference_parser/merge_request_parser.rb
+30
-11
No files found.
lib/banzai/reference_parser/merge_request_parser.rb
View file @
3fa89854
...
@@ -3,23 +3,42 @@ module Banzai
...
@@ -3,23 +3,42 @@ module Banzai
class
MergeRequestParser
<
BaseParser
class
MergeRequestParser
<
BaseParser
self
.
reference_type
=
:merge_request
self
.
reference_type
=
:merge_request
def
nodes_visible_to_user
(
user
,
nodes
)
merge_requests
=
merge_requests_for_nodes
(
nodes
)
nodes
.
select
do
|
node
|
merge_request
=
merge_requests
[
node
]
merge_request
&&
can?
(
user
,
:read_merge_request
,
merge_request
.
project
)
end
end
def
referenced_by
(
nodes
)
merge_requests
=
merge_requests_for_nodes
(
nodes
)
nodes
.
map
{
|
node
|
merge_requests
[
node
]
}.
compact
.
uniq
end
def
merge_requests_for_nodes
(
nodes
)
def
merge_requests_for_nodes
(
nodes
)
@merge_requests_for_nodes
||=
grouped_objects_for_nodes
(
@merge_requests_for_nodes
||=
grouped_objects_for_nodes
(
nodes
,
nodes
,
MergeRequest
.
all
,
MergeRequest
.
includes
(
:author
,
:assignee
,
{
# These associations are primarily used for checking permissions.
# Eager loading these ensures we don't end up running dozens of
# queries in this process.
target_project:
[
{
namespace: :owner
},
{
group:
[
:owners
,
:group_members
]
},
:invited_groups
,
:project_members
]
}),
self
.
class
.
data_attribute
self
.
class
.
data_attribute
)
)
end
end
def
references_relation
MergeRequest
.
includes
(
:author
,
:assignee
,
:target_project
)
end
private
def
can_read_reference?
(
user
,
ref_project
)
can?
(
user
,
:read_merge_request
,
ref_project
)
end
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