Commit 2a76d851 authored by Adam Hegyi's avatar Adam Hegyi

Merge branch '344279-fix-openstruct-use' into 'master'

Fix silenced Style/OpenStructUse offenses

See merge request gitlab-org/gitlab!73398
parents 6e1b616d 924eb6d0
...@@ -2557,7 +2557,6 @@ Rails/IncludeUrlHelper: ...@@ -2557,7 +2557,6 @@ Rails/IncludeUrlHelper:
# TODO issue: https://gitlab.com/gitlab-org/gitlab/-/issues/344279 # TODO issue: https://gitlab.com/gitlab-org/gitlab/-/issues/344279
Style/OpenStructUse: Style/OpenStructUse:
Exclude: Exclude:
- 'app/finders/snippets_finder.rb'
- 'app/helpers/application_settings_helper.rb' - 'app/helpers/application_settings_helper.rb'
- 'ee/spec/db/production/license_spec.rb' - 'ee/spec/db/production/license_spec.rb'
- 'ee/spec/features/projects/new_project_spec.rb' - 'ee/spec/features/projects/new_project_spec.rb'
......
...@@ -42,12 +42,11 @@ class SnippetsFinder < UnionFinder ...@@ -42,12 +42,11 @@ class SnippetsFinder < UnionFinder
include FinderMethods include FinderMethods
include Gitlab::Utils::StrongMemoize include Gitlab::Utils::StrongMemoize
attr_accessor :current_user, :params attr_reader :current_user, :params
delegate :explore, :only_personal, :only_project, :scope, :sort, to: :params
def initialize(current_user = nil, params = {}) def initialize(current_user = nil, params = {})
@current_user = current_user @current_user = current_user
@params = OpenStruct.new(params) @params = params
if project && author if project && author
raise( raise(
...@@ -77,9 +76,9 @@ class SnippetsFinder < UnionFinder ...@@ -77,9 +76,9 @@ class SnippetsFinder < UnionFinder
private private
def init_collection def init_collection
if explore if explore?
snippets_for_explore snippets_for_explore
elsif only_personal elsif only_personal?
personal_snippets personal_snippets
elsif project elsif project
snippets_for_a_single_project snippets_for_a_single_project
...@@ -110,7 +109,7 @@ class SnippetsFinder < UnionFinder ...@@ -110,7 +109,7 @@ class SnippetsFinder < UnionFinder
# over the resulting SQL query. # over the resulting SQL query.
def snippets_for_personal_and_multiple_projects def snippets_for_personal_and_multiple_projects
queries = [] queries = []
queries << personal_snippets unless only_project queries << personal_snippets unless only_project?
if Ability.allowed?(current_user, :read_cross_project) if Ability.allowed?(current_user, :read_cross_project)
queries << snippets_of_visible_projects queries << snippets_of_visible_projects
...@@ -171,7 +170,7 @@ class SnippetsFinder < UnionFinder ...@@ -171,7 +170,7 @@ class SnippetsFinder < UnionFinder
end end
def visibility_from_scope def visibility_from_scope
case scope.to_s case params[:scope].to_s
when 'are_private' when 'are_private'
Snippet::PRIVATE Snippet::PRIVATE
when 'are_internal' when 'are_internal'
...@@ -206,7 +205,19 @@ class SnippetsFinder < UnionFinder ...@@ -206,7 +205,19 @@ class SnippetsFinder < UnionFinder
end end
def sort_param 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 end
def prepared_union(queries) def prepared_union(queries)
......
...@@ -28,10 +28,10 @@ module EE ...@@ -28,10 +28,10 @@ module EE
# When current_user is nil it returns only public personal snippets # When current_user is nil it returns only public personal snippets
def snippets_of_authorized_projects_or_personal def snippets_of_authorized_projects_or_personal
queries = [] 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) 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 end
prepared_union(queries) prepared_union(queries)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment