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
924eb6d0
Commit
924eb6d0
authored
Nov 02, 2021
by
mehulsharma
Committed by
Mehul Sharma
Nov 12, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed OpenStruct use offense
Fixes OpenStruct use in snippets_finder Changelog: changed
parent
b28a328e
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
21 additions
and
11 deletions
+21
-11
.rubocop_manual_todo.yml
.rubocop_manual_todo.yml
+0
-1
app/finders/snippets_finder.rb
app/finders/snippets_finder.rb
+19
-8
ee/app/finders/ee/snippets_finder.rb
ee/app/finders/ee/snippets_finder.rb
+2
-2
No files found.
.rubocop_manual_todo.yml
View file @
924eb6d0
...
...
@@ -2557,7 +2557,6 @@ Rails/IncludeUrlHelper:
# TODO issue: https://gitlab.com/gitlab-org/gitlab/-/issues/344279
Style/OpenStructUse
:
Exclude
:
-
'
app/finders/snippets_finder.rb'
-
'
app/helpers/application_settings_helper.rb'
-
'
ee/spec/db/production/license_spec.rb'
-
'
ee/spec/features/projects/new_project_spec.rb'
...
...
app/finders/snippets_finder.rb
View file @
924eb6d0
...
...
@@ -42,12 +42,11 @@ class SnippetsFinder < UnionFinder
include
FinderMethods
include
Gitlab
::
Utils
::
StrongMemoize
attr_accessor
:current_user
,
:params
delegate
:explore
,
:only_personal
,
:only_project
,
:scope
,
:sort
,
to: :params
attr_reader
:current_user
,
:params
def
initialize
(
current_user
=
nil
,
params
=
{})
@current_user
=
current_user
@params
=
OpenStruct
.
new
(
params
)
@params
=
params
if
project
&&
author
raise
(
...
...
@@ -77,9 +76,9 @@ class SnippetsFinder < UnionFinder
private
def
init_collection
if
explore
if
explore
?
snippets_for_explore
elsif
only_personal
elsif
only_personal
?
personal_snippets
elsif
project
snippets_for_a_single_project
...
...
@@ -110,7 +109,7 @@ class SnippetsFinder < UnionFinder
# over the resulting SQL query.
def
snippets_for_personal_and_multiple_projects
queries
=
[]
queries
<<
personal_snippets
unless
only_project
queries
<<
personal_snippets
unless
only_project
?
if
Ability
.
allowed?
(
current_user
,
:read_cross_project
)
queries
<<
snippets_of_visible_projects
...
...
@@ -171,7 +170,7 @@ class SnippetsFinder < UnionFinder
end
def
visibility_from_scope
case
scope
.
to_s
case
params
[
:scope
]
.
to_s
when
'are_private'
Snippet
::
PRIVATE
when
'are_internal'
...
...
@@ -206,7 +205,19 @@ class SnippetsFinder < UnionFinder
end
def
sort_param
sort
.
presence
||
'id_desc'
params
[
:sort
].
presence
||
'id_desc'
end
def
explore?
params
[
:explore
].
present?
end
def
only_personal?
params
[
:only_personal
].
present?
end
def
only_project?
params
[
:only_project
].
present?
end
def
prepared_union
(
queries
)
...
...
ee/app/finders/ee/snippets_finder.rb
View file @
924eb6d0
...
...
@@ -28,10 +28,10 @@ module EE
# When current_user is nil it returns only public personal snippets
def
snippets_of_authorized_projects_or_personal
queries
=
[]
queries
<<
restricted_personal_snippets
unless
only_project
queries
<<
restricted_personal_snippets
unless
only_project
?
if
current_user
&&
Ability
.
allowed?
(
current_user
,
:read_cross_project
)
queries
<<
snippets_of_authorized_projects
unless
only_personal
queries
<<
snippets_of_authorized_projects
unless
only_personal
?
end
prepared_union
(
queries
)
...
...
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