Commit 0b817a6f authored by mo khan's avatar mo khan

Fix whitespace indentation

parent 7e6135e8
# frozen_string_literal: true # frozen_string_literal: true
module Projects module Projects
class DependenciesController < Projects::ApplicationController class DependenciesController < Projects::ApplicationController
before_action :authorize_read_dependency_list! before_action :authorize_read_dependency_list!
def index def index
respond_to do |format| respond_to do |format|
format.html do format.html do
render status: :ok render status: :ok
end end
format.json do format.json do
::Gitlab::UsageCounters::DependencyList.increment(project.id) ::Gitlab::UsageCounters::DependencyList.increment(project.id)
render json: serializer.represent(dependencies, build: report_service.build) render json: serializer.represent(dependencies, build: report_service.build)
end
end end
end end
end
private private
def can_access_vulnerable? def can_access_vulnerable?
return true unless query_params[:filter] == 'vulnerable' return true unless query_params[:filter] == 'vulnerable'
can?(current_user, :read_vulnerability, project) can?(current_user, :read_vulnerability, project)
end end
def can_collect_dependencies? def can_collect_dependencies?
report_service.able_to_fetch? && can_access_vulnerable? report_service.able_to_fetch? && can_access_vulnerable?
end end
def collect_dependencies def collect_dependencies
found_dependencies = can_collect_dependencies? ? service.execute : [] found_dependencies = can_collect_dependencies? ? service.execute : []
::Gitlab::ItemsCollection.new(found_dependencies) ::Gitlab::ItemsCollection.new(found_dependencies)
end end
def authorize_read_dependency_list! def authorize_read_dependency_list!
return if can?(current_user, :read_dependencies, project) return if can?(current_user, :read_dependencies, project)
respond_to do |format| respond_to do |format|
format.html do format.html do
render_404 render_404
end end
format.json do format.json do
render_403 render_403
end
end end
end end
end
def dependencies def dependencies
@dependencies ||= collect_dependencies @dependencies ||= collect_dependencies
end end
def match_disallowed(param, value) def match_disallowed(param, value)
param == :sort_by && !value.in?(::Security::DependencyListService::SORT_BY_VALUES) || param == :sort_by && !value.in?(::Security::DependencyListService::SORT_BY_VALUES) ||
param == :sort && !value.in?(::Security::DependencyListService::SORT_VALUES) || param == :sort && !value.in?(::Security::DependencyListService::SORT_VALUES) ||
param == :filter && !value.in?(::Security::DependencyListService::FILTER_VALUES) param == :filter && !value.in?(::Security::DependencyListService::FILTER_VALUES)
end end
def pipeline def pipeline
@pipeline ||= report_service.pipeline @pipeline ||= report_service.pipeline
end end
def query_params def query_params
return @permitted_params if @permitted_params return @permitted_params if @permitted_params
@permitted_params = params.permit(:sort, :sort_by, :filter).delete_if do |key, value| @permitted_params = params.permit(:sort, :sort_by, :filter).delete_if do |key, value|
match_disallowed(key, value) match_disallowed(key, value)
end
end end
end
def report_service def report_service
@report_service ||= ::Security::ReportFetchService.new(project, ::Ci::JobArtifact.dependency_list_reports) @report_service ||= ::Security::ReportFetchService.new(project, ::Ci::JobArtifact.dependency_list_reports)
end end
def serializer def serializer
serializer = ::DependencyListSerializer.new(project: project, user: current_user) serializer = ::DependencyListSerializer.new(project: project, user: current_user)
serializer = serializer.with_pagination(request, response) if params[:page] serializer = serializer.with_pagination(request, response) if params[:page]
serializer serializer
end end
def service def service
::Security::DependencyListService.new(pipeline: pipeline, params: query_params) ::Security::DependencyListService.new(pipeline: pipeline, params: query_params)
end
end end
end
end end
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