Commit 265f9a43 authored by Ash McKenzie's avatar Ash McKenzie

Merge branch '215157-framework-api-rest' into 'master'

Add compliance_framework list to project API endpoint

See merge request gitlab-org/gitlab!34709
parents 4d442da5 5795fd10
......@@ -891,6 +891,7 @@ GET /projects/:id
"suggestion_commit_message": null,
"marked_for_deletion_at": "2020-04-03", // Deprecated and will be removed in API v5 in favor of marked_for_deletion_on
"marked_for_deletion_on": "2020-04-03",
"compliance_frameworks": [ "sox" ],
"statistics": {
"commit_count": 37,
"storage_size": 1038090,
......
---
title: Add compliance_frameworks list to project API
merge_request: 34709
author:
type: added
......@@ -6,6 +6,15 @@ module EE
module Project
extend ActiveSupport::Concern
class_methods do
extend ::Gitlab::Utils::Override
override :preload_relation
def preload_relation(projects_relation, options = {})
super(projects_relation).with_compliance_framework_settings
end
end
prepended do
expose :approvals_before_merge, if: ->(project, _) { project.feature_available?(:merge_request_approvers) }
expose :mirror, if: ->(project, _) { project.feature_available?(:repository_mirrors) }
......@@ -22,6 +31,9 @@ module EE
expose :marked_for_deletion_on, if: ->(project, _) { project.feature_available?(:adjourned_deletion_for_projects_and_groups) } do |project, _|
project.marked_for_deletion_at
end
expose :compliance_frameworks do |project, _|
[project.compliance_framework_setting&.framework].compact
end
end
end
end
......
......@@ -4,5 +4,9 @@ FactoryBot.define do
factory :compliance_framework_project_setting, class: 'ComplianceManagement::ComplianceFramework::ProjectSettings' do
project
framework { ComplianceManagement::ComplianceFramework::ProjectSettings.frameworks.keys.sample }
trait :sox do
framework { 'sox' }
end
end
end
......@@ -95,5 +95,9 @@ FactoryBot.modify do
trait :with_compliance_framework do
association :compliance_framework_setting, factory: :compliance_framework_project_setting
end
trait :with_sox_compliance_framework do
association :compliance_framework_setting, factory: :compliance_framework_project_setting, framework: 'sox'
end
end
end
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe ::EE::API::Entities::Project do
let(:project) { create(:project) }
let(:entity) do
::API::Entities::Project.new(project)
end
subject { entity.as_json }
context 'compliance_frameworks' do
context 'when project has a compliance framework' do
let(:project) { create(:project, :with_sox_compliance_framework) }
it 'is an array containing a single compliance framework' do
expect(subject[:compliance_frameworks]).to contain_exactly('sox')
end
end
context 'when project has no compliance framework' do
let(:project) { create(:project) }
it 'is empty array when project has no compliance framework' do
expect(subject[:compliance_frameworks]).to eq([])
end
end
end
end
......@@ -160,6 +160,31 @@ RSpec.describe API::Projects do
end
end
describe 'compliance_frameworks attribute' do
context 'when compliance_framework feature is available' do
context 'when project has a compliance framework' do
before do
project.update!(compliance_framework_setting: create(:compliance_framework_project_setting, :sox))
get api("/projects/#{project.id}", user)
end
it 'exposes framework names as array of strings' do
expect(json_response['compliance_frameworks']).to contain_exactly('sox')
end
end
context 'when project has no compliance framework' do
before do
get api("/projects/#{project.id}", user)
end
it 'returns an empty array' do
expect(json_response['compliance_frameworks']).to eq([])
end
end
end
end
describe 'service desk attributes' do
it 'are exposed when the feature is available' do
stub_licensed_features(service_desk: true)
......
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