Commit e60c2dbb authored by mo khan's avatar mo khan

Allow filtering policies by x AND y classification

parent b3e77e34
...@@ -68,9 +68,10 @@ module Projects ...@@ -68,9 +68,10 @@ module Projects
def matching_policies_from(license_compliance) def matching_policies_from(license_compliance)
if params[:detected] if params[:detected]
license_compliance.detected_policies license_compliance.detected_policies
elsif params[:classifications].present? elsif params[:classification].present?
classifications = Array(params[:classification])
license_compliance.policies.find_all do |policy| license_compliance.policies.find_all do |policy|
params[:classifications].include?(policy.classification) classifications.include?(policy.classification)
end end
else else
license_compliance.policies license_compliance.policies
......
...@@ -178,7 +178,7 @@ describe Projects::LicensesController do ...@@ -178,7 +178,7 @@ describe Projects::LicensesController do
get :index, params: { get :index, params: {
namespace_id: project.namespace, namespace_id: project.namespace,
project_id: project, project_id: project,
classifications: ['allowed'] classification: ['allowed']
}, format: :json }, format: :json
end end
...@@ -193,6 +193,35 @@ describe Projects::LicensesController do ...@@ -193,6 +193,35 @@ describe Projects::LicensesController do
}) })
end end
end end
context "when loading `allowed` and `denied` software policies" do
before do
get :index, params: {
namespace_id: project.namespace,
project_id: project,
classification: ['allowed', 'denied']
}, format: :json
end
it { expect(response).to have_http_status(:ok) }
it { expect(json_response["licenses"].count).to be(2) }
it 'includes `denied` policies' do
expect(json_response.dig("licenses", 0)).to include({
"id" => mit_policy.id,
"spdx_identifier" => mit.spdx_identifier,
"classification" => mit_policy.classification
})
end
it 'includes `allowed` policies' do
expect(json_response.dig("licenses", 1)).to include({
"id" => other_license_policy.id,
"spdx_identifier" => other_license_policy.spdx_identifier,
"classification" => other_license_policy.classification
})
end
end
end end
context 'without existing report' do context 'without existing report' do
......
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