BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
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
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
30 additions
and
11 deletions
+30
-11
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
class
MergeRequestParser
<
BaseParser
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
)
@merge_requests_for_nodes
||=
grouped_objects_for_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
)
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
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