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
Boxiang Sun
gitlab-ce
Commits
8cc646fa
Commit
8cc646fa
authored
Jul 15, 2018
by
Reuben Pereira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove nodes_visible_to_user from ProjectParser and memoize readable_project_ids
parent
a08b5144
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
17 deletions
+10
-17
lib/banzai/reference_parser/project_parser.rb
lib/banzai/reference_parser/project_parser.rb
+10
-17
No files found.
lib/banzai/reference_parser/project_parser.rb
View file @
8cc646fa
module
Banzai
module
ReferenceParser
class
ProjectParser
<
BaseParser
include
Gitlab
::
Utils
::
StrongMemoize
self
.
reference_type
=
:project
def
references_relation
Project
end
def
nodes_visible_to_user
(
user
,
nodes
)
nodes_projects_hash
=
lazy
{
projects_for_nodes
(
nodes
)
}
project_attr
=
'data-project'
readable_project_ids
=
projects_readable_by_user
(
nodes_projects_hash
.
values
,
user
)
nodes
.
select
do
|
node
|
if
node
.
has_attribute?
(
project_attr
)
readable_project_ids
.
include?
(
nodes_projects_hash
[
node
].
try
(
:id
))
else
true
end
end
end
private
# Returns an Array of Project ids that can be read by the given user.
#
# projects - The projects to reduce down to those readable by the user.
# user - The User for which to check the projects
def
projects_readable_by_user
(
projects
,
user
)
def
readable_project_ids_for
(
projects
,
user
)
strong_memoize
(
:readable_project_ids_for
)
do
Project
.
public_or_visible_to_user
(
user
).
where
(
"projects.id IN (?)"
,
projects
.
map
(
&
:id
)).
pluck
(
:id
)
end
end
def
can_read_reference?
(
user
,
ref_project
,
node
)
readable_project_ids_for
(
@projects_for_nodes
.
values
,
user
).
include?
(
ref_project
.
try
(
:id
))
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