Commit ef4d5c50 authored by Mikołaj Wawrzyniak's avatar Mikołaj Wawrzyniak

Merge branch 'service-ping-settings' into 'master'

Service ping settings [RUN ALL RSPEC] [RUN AS-IF-FOSS]

See merge request gitlab-org/gitlab!66223
parents 62b3405b fe78d58b
......@@ -14,20 +14,10 @@ module ServicePing
].to_set.freeze
def execute
return [] unless product_intelligence_enabled?
return [] unless ServicePingSettings.product_intelligence_enabled?
CATEGORIES
end
def product_intelligence_enabled?
pings_enabled? && !User.single_user&.requires_usage_stats_consent?
end
private
def pings_enabled?
::Gitlab::CurrentSettings.usage_ping_enabled?
end
end
end
......
# frozen_string_literal: true
module ServicePing
module ServicePingSettings
extend self
def product_intelligence_enabled?
pings_enabled? && !User.single_user&.requires_usage_stats_consent?
end
private
def pings_enabled?
::Gitlab::CurrentSettings.usage_ping_enabled?
end
end
end
ServicePing::ServicePingSettings.extend_mod_with('ServicePing::ServicePingSettings')
......@@ -18,7 +18,7 @@ module ServicePing
SubmissionError = Class.new(StandardError)
def execute
return unless ServicePing::PermitDataCategoriesService.new.product_intelligence_enabled?
return unless ServicePing::ServicePingSettings.product_intelligence_enabled?
begin
usage_data = BuildPayloadService.new.execute
......
......@@ -13,7 +13,7 @@ module EE
override :execute
def execute
return super unless ::License.current.present?
return [] unless product_intelligence_enabled?
return [] unless ::ServicePing::ServicePingSettings.product_intelligence_enabled?
optional_enabled = ::Gitlab::CurrentSettings.usage_ping_enabled?
customer_service_enabled = ::License.current.customer_service_enabled?
......@@ -23,13 +23,6 @@ module EE
categories << OPERATIONAL_CATEGORY if customer_service_enabled
end.to_set
end
private
override :pings_enabled?
def pings_enabled?
::License.current&.customer_service_enabled? || super
end
end
end
end
# frozen_string_literal: true
module EE
module ServicePing
module ServicePingSettings
extend ::Gitlab::Utils::Override
private
override :pings_enabled?
def pings_enabled?
::License.current&.customer_service_enabled? || super
end
end
end
end
......@@ -3,8 +3,6 @@
require 'spec_helper'
RSpec.describe ServicePing::PermitDataCategoriesService do
using RSpec::Parameterized::TableSyntax
describe '#execute' do
subject(:permitted_categories) { described_class.new.execute }
......@@ -78,6 +76,7 @@ RSpec.describe ServicePing::PermitDataCategoriesService do
before do
# License.current.usage_ping? == true
create_current_license(operational_metrics_enabled: true)
allow(ServicePing::ServicePingSettings).to receive(:product_intelligence_enabled?).and_return(true)
end
it 'returns all categories' do
......@@ -98,38 +97,4 @@ RSpec.describe ServicePing::PermitDataCategoriesService do
end
end
end
describe '#product_intelligence_enabled?' do
where(:usage_ping_enabled, :customer_service_enabled, :requires_usage_stats_consent, :expected_product_intelligence_enabled) do
# Customer service enabled
true | true | false | true
false | true | true | false
false | true | false | true
true | true | true | false
# Customer service disabled
true | false | false | true
true | false | true | false
false | false | false | false
false | false | true | false
# When there is no license it should have same behaviour as ce
true | nil | false | true
false | nil | false | false
false | nil | true | false
true | nil | true | false
end
with_them do
before do
allow(User).to receive(:single_user).and_return(double(:user, requires_usage_stats_consent?: requires_usage_stats_consent))
stub_config_setting(usage_ping_enabled: usage_ping_enabled)
create_current_license(operational_metrics_enabled: customer_service_enabled)
end
it 'has the correct product_intelligence_enabled?' do
expect(described_class.new.product_intelligence_enabled?).to eq(expected_product_intelligence_enabled)
end
end
end
end
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe ServicePing::ServicePingSettings do
using RSpec::Parameterized::TableSyntax
describe '#product_intelligence_enabled?' do
where(:usage_ping_enabled, :customer_service_enabled, :requires_usage_stats_consent, :expected_product_intelligence_enabled) do
# Customer service enabled
true | true | false | true
false | true | true | false
false | true | false | true
true | true | true | false
# Customer service disabled
true | false | false | true
true | false | true | false
false | false | false | false
false | false | true | false
# When there is no license it should have same behaviour as ce
true | nil | false | true
false | nil | false | false
false | nil | true | false
true | nil | true | false
end
with_them do
before do
allow(User).to receive(:single_user).and_return(double(:user, requires_usage_stats_consent?: requires_usage_stats_consent))
stub_config_setting(usage_ping_enabled: usage_ping_enabled)
create_current_license(operational_metrics_enabled: customer_service_enabled)
end
it 'has the correct product_intelligence_enabled?' do
expect(described_class.product_intelligence_enabled?).to eq(expected_product_intelligence_enabled)
end
end
end
end
......@@ -3,8 +3,6 @@
require 'spec_helper'
RSpec.describe ServicePing::PermitDataCategoriesService do
using RSpec::Parameterized::TableSyntax
describe '#execute', :without_license do
subject(:permitted_categories) { described_class.new.execute }
......@@ -41,27 +39,4 @@ RSpec.describe ServicePing::PermitDataCategoriesService do
end
end
end
describe '#product_intelligence_enabled?' do
where(:usage_ping_enabled, :requires_usage_stats_consent, :expected_product_intelligence_enabled) do
# Usage ping enabled
true | false | true
true | true | false
# Usage ping disabled
false | false | false
false | true | false
end
with_them do
before do
allow(User).to receive(:single_user).and_return(double(:user, requires_usage_stats_consent?: requires_usage_stats_consent))
stub_config_setting(usage_ping_enabled: usage_ping_enabled)
end
it 'has the correct product_intelligence_enabled?' do
expect(described_class.new.product_intelligence_enabled?).to eq(expected_product_intelligence_enabled)
end
end
end
end
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe ServicePing::ServicePingSettings do
using RSpec::Parameterized::TableSyntax
describe '#product_intelligence_enabled?' do
where(:usage_ping_enabled, :requires_usage_stats_consent, :expected_product_intelligence_enabled) do
# Usage ping enabled
true | false | true
true | true | false
# Usage ping disabled
false | false | false
false | true | false
end
with_them do
before do
allow(User).to receive(:single_user).and_return(double(:user, requires_usage_stats_consent?: requires_usage_stats_consent))
stub_config_setting(usage_ping_enabled: usage_ping_enabled)
end
it 'has the correct product_intelligence_enabled?' do
expect(described_class.product_intelligence_enabled?).to eq(expected_product_intelligence_enabled)
end
end
end
end
......@@ -100,9 +100,7 @@ RSpec.describe ServicePing::SubmitService do
context 'when product_intelligence_enabled is false' do
before do
allow_next_instance_of(ServicePing::PermitDataCategoriesService) do |service|
allow(service).to receive(:product_intelligence_enabled?).and_return(false)
end
allow(ServicePing::ServicePingSettings).to receive(:product_intelligence_enabled?).and_return(false)
end
it_behaves_like 'does not run'
......@@ -112,9 +110,7 @@ RSpec.describe ServicePing::SubmitService do
before do
stub_usage_data_connections
allow_next_instance_of(ServicePing::PermitDataCategoriesService) do |service|
allow(service).to receive(:product_intelligence_enabled?).and_return(true)
end
allow(ServicePing::ServicePingSettings).to receive(:product_intelligence_enabled?).and_return(true)
end
it 'generates service ping' 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