Commit 36f595bb authored by Robert Speicher's avatar Robert Speicher

Merge branch 'group-coverage-reporting' into 'master'

Empty controller action for GroupCoverage report

See merge request gitlab-org/gitlab!37154
parents 6700aca2 99c0076f
# frozen_string_literal: true
class Groups::Analytics::CoverageReportsController < Groups::Analytics::ApplicationController
check_feature_flag Gitlab::Analytics::CYCLE_ANALYTICS_FEATURE_FLAG
before_action :load_group
before_action -> { check_feature_availability!(:group_coverage_reports) }
def index
respond_to do |format|
format.csv { send_data([].to_csv, type: 'text/csv; charset=utf-8') }
end
end
end
...@@ -77,6 +77,7 @@ class License < ApplicationRecord ...@@ -77,6 +77,7 @@ class License < ApplicationRecord
github_project_service_integration github_project_service_integration
generic_alert_fingerprinting generic_alert_fingerprinting
group_allowed_email_domains group_allowed_email_domains
group_coverage_reports
group_ip_restriction group_ip_restriction
group_project_templates group_project_templates
group_saml group_saml
......
...@@ -25,6 +25,8 @@ constraints(::Constraints::GroupUrlConstrainer.new) do ...@@ -25,6 +25,8 @@ constraints(::Constraints::GroupUrlConstrainer.new) do
namespace :analytics do namespace :analytics do
resource :productivity_analytics, only: :show, constraints: -> (req) { Gitlab::Analytics.productivity_analytics_enabled? } resource :productivity_analytics, only: :show, constraints: -> (req) { Gitlab::Analytics.productivity_analytics_enabled? }
resources :coverage_reports, only: :index, constraints: -> (req) { Gitlab::Analytics.group_coverage_reports_enabled? }
feature_default_enabled = Gitlab::Analytics.feature_enabled_by_default?(Gitlab::Analytics::CYCLE_ANALYTICS_FEATURE_FLAG) feature_default_enabled = Gitlab::Analytics.feature_enabled_by_default?(Gitlab::Analytics::CYCLE_ANALYTICS_FEATURE_FLAG)
constrainer = ::Constraints::FeatureConstrainer.new(Gitlab::Analytics::CYCLE_ANALYTICS_FEATURE_FLAG, default_enabled: feature_default_enabled) constrainer = ::Constraints::FeatureConstrainer.new(Gitlab::Analytics::CYCLE_ANALYTICS_FEATURE_FLAG, default_enabled: feature_default_enabled)
constraints(constrainer) do constraints(constrainer) do
......
...@@ -5,14 +5,17 @@ module Gitlab ...@@ -5,14 +5,17 @@ module Gitlab
# Normally each analytics feature should be guarded with a feature flag. # Normally each analytics feature should be guarded with a feature flag.
CYCLE_ANALYTICS_FEATURE_FLAG = :cycle_analytics CYCLE_ANALYTICS_FEATURE_FLAG = :cycle_analytics
PRODUCTIVITY_ANALYTICS_FEATURE_FLAG = :productivity_analytics PRODUCTIVITY_ANALYTICS_FEATURE_FLAG = :productivity_analytics
GROUP_COVERAGE_REPORTS_FEATURE_FLAG = :group_coverage_reports
FEATURE_FLAGS = [ FEATURE_FLAGS = [
CYCLE_ANALYTICS_FEATURE_FLAG, CYCLE_ANALYTICS_FEATURE_FLAG,
GROUP_COVERAGE_REPORTS_FEATURE_FLAG,
PRODUCTIVITY_ANALYTICS_FEATURE_FLAG PRODUCTIVITY_ANALYTICS_FEATURE_FLAG
].freeze ].freeze
FEATURE_FLAG_DEFAULTS = { FEATURE_FLAG_DEFAULTS = {
PRODUCTIVITY_ANALYTICS_FEATURE_FLAG => true, PRODUCTIVITY_ANALYTICS_FEATURE_FLAG => true,
GROUP_COVERAGE_REPORTS_FEATURE_FLAG => false,
CYCLE_ANALYTICS_FEATURE_FLAG => true CYCLE_ANALYTICS_FEATURE_FLAG => true
}.freeze }.freeze
...@@ -28,6 +31,10 @@ module Gitlab ...@@ -28,6 +31,10 @@ module Gitlab
feature_enabled?(PRODUCTIVITY_ANALYTICS_FEATURE_FLAG) feature_enabled?(PRODUCTIVITY_ANALYTICS_FEATURE_FLAG)
end end
def self.group_coverage_reports_enabled?
feature_enabled?(GROUP_COVERAGE_REPORTS_FEATURE_FLAG)
end
def self.feature_enabled_by_default?(flag) def self.feature_enabled_by_default?(flag)
!!FEATURE_FLAG_DEFAULTS[flag] !!FEATURE_FLAG_DEFAULTS[flag]
end end
......
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Groups::Analytics::CoverageReportsController do
let(:user) { create(:user) }
let(:group) { create(:group) }
context 'without permissions' do
before do
sign_in(user)
end
describe 'GET index' do
it 'responds 403' do
get :index, params: { group_id: group.name, format: :csv }
expect(response).to have_gitlab_http_status(:forbidden)
end
end
end
context 'with permissions' do
before do
group.add_owner(user)
sign_in(user)
end
context 'without a license' do
before do
stub_licensed_features(group_coverage_reports: false)
end
describe 'GET index' do
it 'responds 403 because the feature is not licensed' do
get :index, params: { group_id: group.name, format: :csv }
expect(response).to have_gitlab_http_status(:forbidden)
end
end
end
context 'with the feature flag shut off' do
before do
stub_licensed_features(group_coverage_reports: true)
stub_feature_flags(group_coverage_reports: false)
end
describe 'GET index' do
it 'responds 403 because the feature is not licensed' do
get :index, params: { group_id: group.name, format: :csv }
expect(response).to have_gitlab_http_status(:forbidden)
end
end
end
describe 'GET index' do
before do
stub_licensed_features(group_coverage_reports: true)
end
it 'responds 200 OK' do
get :index, params: { group_id: group.name, format: :csv }
expect(response).to have_gitlab_http_status(:ok)
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