Commit b90a83c2 authored by Sean McGivern's avatar Sean McGivern

Merge branch '11759-move-dependencies-controller' into 'master'

Move DependenciesController to Security namespace

See merge request gitlab-org/gitlab-ee!13897
parents 9b59c91f c1bf4cb1
# frozen_string_literal: true
module Projects
class DependenciesController < Projects::ApplicationController
SORT_BY_PERMITTED_VALUES = %w(name type).freeze
SORT_PERMITTED_VALUES = %w(asc desc).freeze
before_action :ensure_bill_of_materials_feature_flag_enabled
def index
respond_to do |format|
format.json do
render json: paginated_dependecies
end
end
end
private
def ensure_bill_of_materials_feature_flag_enabled
render_404 unless Feature.enabled?(:bill_of_materials, default_enabled: false)
end
def found_dependencies
::Security::DependenciesFinder.new(project: @project, params: query_params).execute
end
def query_params
params.permit(:sort, :sort_by).delete_if do |key, value|
key == :sort_by && !value.in?(::Security::DependenciesFinder::SORT_BY_VALUES) ||
key == :sort && !value.in?(::Security::DependenciesFinder::SORT_VALUES)
end
end
# TODO: add proper implementation of edge cases handling
# format: { report: 'failed' }
# after we'll have more then just mock data
# reference: https://gitlab.com/gitlab-org/gitlab-ee/issues/10075#note_164915787
def paginated_dependecies
Kaminari.paginate_array(found_dependencies).page(params[:page])
end
end
end
# frozen_string_literal: true
module Projects
module Security
class DependenciesController < Projects::ApplicationController
SORT_BY_PERMITTED_VALUES = %w(name type).freeze
SORT_PERMITTED_VALUES = %w(asc desc).freeze
before_action :ensure_bill_of_materials_feature_flag_enabled
def index
respond_to do |format|
format.json do
render json: paginated_dependecies
end
end
end
private
def ensure_bill_of_materials_feature_flag_enabled
render_404 unless Feature.enabled?(:bill_of_materials, default_enabled: false)
end
def found_dependencies
::Security::DependenciesFinder.new(project: @project, params: query_params).execute
end
def query_params
params.permit(:sort, :sort_by).delete_if do |key, value|
key == :sort_by && !value.in?(::Security::DependenciesFinder::SORT_BY_VALUES) ||
key == :sort && !value.in?(::Security::DependenciesFinder::SORT_VALUES)
end
end
# TODO: add proper implementation of edge cases handling
# format: { report: 'failed' }
# after we'll have more then just mock data
# reference: https://gitlab.com/gitlab-org/gitlab-ee/issues/10075#note_164915787
def paginated_dependecies
Kaminari.paginate_array(found_dependencies).page(params[:page])
end
end
end
end
---
title: Move dependencies API endpoint to "security" namespace
merge_request: 13897
author:
type: changed
...@@ -83,7 +83,9 @@ constraints(::Constraints::ProjectUrlConstrainer.new) do ...@@ -83,7 +83,9 @@ constraints(::Constraints::ProjectUrlConstrainer.new) do
end end
end end
resources :dependencies, only: [:index] namespace :security do
resources :dependencies, only: [:index]
end
end end
end end
end end
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
require 'spec_helper' require 'spec_helper'
describe Projects::DependenciesController do describe Projects::Security::DependenciesController do
describe 'GET index.json' do describe 'GET index.json' do
set(:project) { create(:project, :repository, :public) } set(:project) { create(:project, :repository, :public) }
set(:user) { create(:user) } set(:user) { create(:user) }
......
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