Commit 3235302b authored by Thong Kuah's avatar Thong Kuah

Merge branch '349713-remove-dev_env_or_com' into 'master'

Remove Gitlab.dev_env_or_com? in favor of Gitlab.com?

See merge request gitlab-org/gitlab!81319
parents 80774ffb a4887576
......@@ -178,7 +178,7 @@ module AuthHelper
end
def google_tag_manager_enabled?
return false unless Gitlab.dev_env_or_com?
return false unless Gitlab.com?
if Feature.enabled?(:gtm_nonce, type: :ops)
extra_config.has_key?('google_tag_manager_nonce_id') &&
......
......@@ -5,7 +5,7 @@ module SessionsHelper
def recently_confirmed_com?
strong_memoize(:recently_confirmed_com) do
::Gitlab.dev_env_or_com? &&
::Gitlab.com? &&
!!flash[:notice]&.include?(t(:confirmed, scope: [:devise, :confirmations]))
end
end
......
......@@ -10,7 +10,7 @@ module WhatsNewHelper
end
def display_whats_new?
(Gitlab.dev_env_org_or_com? || user_signed_in?) &&
(Gitlab.org_or_com? || user_signed_in?) &&
!Gitlab::CurrentSettings.current_application_settings.whats_new_variant_disabled?
end
......
......@@ -67,7 +67,7 @@ class BasePolicy < DeclarativePolicy::Base
rule { default }.enable :read_cross_project
condition(:is_gitlab_com, score: 0, scope: :global) { ::Gitlab.dev_env_or_com? }
condition(:is_gitlab_com, score: 0, scope: :global) { ::Gitlab.com? }
end
BasePolicy.prepend_mod_with('BasePolicy')
- return unless Gitlab.dev_env_or_com?
- return unless Gitlab.com?
.gl-mb-3.js-email-opt-in.hidden
.gl-font-weight-bold.gl-mb-3
......
- return unless Gitlab::CurrentSettings.current_application_settings.enforce_terms?
%p.gl-text-gray-500.gl-mt-5.gl-mb-0
- if Gitlab.dev_env_or_com?
- if Gitlab.com?
= html_escape(s_("SignUp|By clicking %{button_text}, I agree that I have read and accepted the GitLab %{link_start}Terms of Use and Privacy Policy%{link_end}")) % { button_text: button_text,
link_start: "<a href='#{terms_path}' target='_blank' rel='noreferrer noopener'>".html_safe, link_end: '</a>'.html_safe }
- else
......
......@@ -49,7 +49,7 @@ Gitlab::Experiment.configure do |config|
#
valid_domains = %w[about.gitlab.com docs.gitlab.com gitlab.com gdk.test localhost]
config.redirect_url_validator = lambda do |url|
Gitlab.dev_env_or_com? && (url = URI.parse(url)) && valid_domains.include?(url.host)
Gitlab.com? && (url = URI.parse(url)) && valid_domains.include?(url.host)
rescue URI::InvalidURIError
false
end
......
......@@ -24,7 +24,7 @@ class AddNewTrailPlans < ActiveRecord::Migration[6.0]
end
def up
return unless Gitlab.dev_env_or_com?
return unless Gitlab.com?
ultimate_trial = Plan.create!(name: 'ultimate_trial', title: 'Ultimate Trial')
premium_trial = Plan.create!(name: 'premium_trial', title: 'Premium Trial')
......@@ -34,7 +34,7 @@ class AddNewTrailPlans < ActiveRecord::Migration[6.0]
end
def down
return unless Gitlab.dev_env_or_com?
return unless Gitlab.com?
Plan.where(name: %w(ultimate_trial premium_trial)).delete_all
end
......
......@@ -29,7 +29,7 @@ class UpdateTrialPlansCiDailyPipelineScheduleTriggers < ActiveRecord::Migration[
end
def up
return unless Gitlab.dev_env_or_com?
return unless Gitlab.com?
if plan_limits_present?
create_or_update_plan_limit('ci_daily_pipeline_schedule_triggers', PREMIUM_TRIAL, EVERY_5_MINUTES)
......@@ -38,7 +38,7 @@ class UpdateTrialPlansCiDailyPipelineScheduleTriggers < ActiveRecord::Migration[
end
def down
return unless Gitlab.dev_env_or_com?
return unless Gitlab.com?
if plan_limits_present?
create_or_update_plan_limit('ci_daily_pipeline_schedule_triggers', PREMIUM_TRIAL, 0)
......
......@@ -24,7 +24,7 @@ class AddOpenSourcePlan < Gitlab::Database::Migration[1.0]
end
def up
return unless Gitlab.dev_env_or_com?
return unless Gitlab.com?
opensource = Plan.create!(name: 'opensource', title: 'Open Source Program')
......@@ -32,7 +32,7 @@ class AddOpenSourcePlan < Gitlab::Database::Migration[1.0]
end
def down
return unless Gitlab.dev_env_or_com?
return unless Gitlab.com?
Plan.where(name: 'opensource').delete_all
end
......
......@@ -256,7 +256,7 @@ module EE
end
def should_check_namespace_plan?
check_namespace_plan? && (Rails.env.test? || ::Gitlab.dev_env_org_or_com?)
check_namespace_plan? && (Rails.env.test? || ::Gitlab.org_or_com?)
end
def elasticsearch_indexing
......
- return unless ::Gitlab.dev_env_org_or_com?
- return unless ::Gitlab.org_or_com?
- form = local_assigns.fetch(:form)
......
......@@ -28,7 +28,7 @@ RSpec.describe TrialsController, :saas do
shared_examples 'a dot-com only feature' do
let(:success_status) { :ok }
context 'when not on gitlab.com ' do
context 'when not on gitlab.com' do
before do
allow(::Gitlab).to receive(:com?).and_return(false)
end
......
......@@ -212,11 +212,11 @@ RSpec.describe ApplicationSetting do
describe '#should_check_namespace_plan?' do
before do
stub_application_setting(check_namespace_plan: check_namespace_plan_column)
allow(::Gitlab).to receive(:dev_env_org_or_com?) { gl_com }
allow(::Gitlab).to receive(:org_or_com?) { gl_com }
# This stub was added in order to force a fallback to Gitlab.dev_env_org_or_com?
# This stub was added in order to force a fallback to Gitlab.org_or_com?
# call testing.
# Gitlab.dev_env_org_or_com? responds to `false` on test envs
# Gitlab.org_or_com? responds to `false` on test envs
# and we want to make sure we're still testing
# should_check_namespace_plan? method through the test-suite (see
# https://gitlab.com/gitlab-org/gitlab-foss/merge_requests/18461#note_69322821).
......
......@@ -368,7 +368,7 @@ RSpec.describe GitlabSubscription, :saas do
end
describe 'callbacks' do
context 'after_commit :index_namespace' do
context 'after_commit :index_namespace', :saas do
let_it_be(:namespace) { create(:namespace) }
let(:gitlab_subscription) { build(:gitlab_subscription, plan, namespace: namespace) }
......
......@@ -88,12 +88,8 @@ module Gitlab
Gitlab::Saas.subdomain_regex === Gitlab.config.gitlab.url
end
def self.dev_env_org_or_com?
dev_env_or_com? || org?
end
def self.dev_env_or_com?
com?
def self.org_or_com?
org? || com?
end
def self.dev_or_test_env?
......
......@@ -13,7 +13,7 @@ module Gitlab
# no inclusions, etc.)
def enabled?
return false unless feature_flag_defined?
return false unless Gitlab.dev_env_or_com?
return false unless Gitlab.com?
return false unless ::Feature.enabled?(:gitlab_experiment, type: :ops, default_enabled: :yaml)
feature_flag_instance.state != :off
......
......@@ -20,7 +20,7 @@ module Gitlab
end
def set_experimentation_subject_id_cookie
if Gitlab.dev_env_or_com?
if Gitlab.com?
return if cookies[:experimentation_subject_id].present?
cookies.permanent.signed[:experimentation_subject_id] = {
......
......@@ -18,7 +18,7 @@ module Gitlab
# Temporary change, we will change `experiment_percentage` in future to `Feature.enabled?
Feature.enabled?(feature_flag_name, type: :experiment, default_enabled: :yaml)
::Gitlab.dev_env_or_com? && experiment_percentage > 0
::Gitlab.com? && experiment_percentage > 0
end
def enabled_for_index?(index)
......
......@@ -40,7 +40,6 @@ module Gitlab
gon.ee = Gitlab.ee?
gon.jh = Gitlab.jh?
gon.dot_com = Gitlab.com?
gon.dev_env_or_com = Gitlab.dev_env_or_com?
if current_user
gon.current_user_id = current_user.id
......
......@@ -243,12 +243,12 @@ RSpec.describe ApplicationExperiment, :experiment do
with_them do
it "returns the url or nil if invalid" do
allow(Gitlab).to receive(:dev_env_or_com?).and_return(true)
allow(Gitlab).to receive(:com?).and_return(true)
expect(application_experiment.process_redirect_url(url)).to eq(processed_url)
end
it "considers all urls invalid when not on dev or com" do
allow(Gitlab).to receive(:dev_env_or_com?).and_return(false)
allow(Gitlab).to receive(:com?).and_return(false)
expect(application_experiment.process_redirect_url(url)).to be_nil
end
end
......
......@@ -8,7 +8,7 @@ RSpec.describe SessionsHelper do
context 'when on .com' do
before do
allow(Gitlab).to receive(:dev_env_or_com?).and_return(true)
allow(Gitlab).to receive(:com?).and_return(true)
end
it 'when flash notice is empty it is false' do
......@@ -29,7 +29,7 @@ RSpec.describe SessionsHelper do
context 'when not on .com' do
before do
allow(Gitlab).to receive(:dev_env_or_com?).and_return(false)
allow(Gitlab).to receive(:com?).and_return(false)
end
it 'when flash notice is devise confirmed message it is false' do
......
......@@ -39,14 +39,14 @@ RSpec.describe WhatsNewHelper do
subject { helper.display_whats_new? }
it 'returns true when gitlab.com' do
allow(Gitlab).to receive(:dev_env_org_or_com?).and_return(true)
allow(Gitlab).to receive(:org_or_com?).and_return(true)
expect(subject).to be true
end
context 'when self-managed' do
before do
allow(Gitlab).to receive(:dev_env_org_or_com?).and_return(false)
allow(Gitlab).to receive(:org_or_com?).and_return(false)
end
it 'returns true if user is signed in' do
......@@ -71,7 +71,7 @@ RSpec.describe WhatsNewHelper do
with_them do
it 'returns correct result depending on variant' do
allow(Gitlab).to receive(:dev_env_org_or_com?).and_return(true)
allow(Gitlab).to receive(:org_or_com?).and_return(true)
Gitlab::CurrentSettings.update!(whats_new_variant: ApplicationSetting.whats_new_variants[variant])
expect(subject).to eq(result)
......
......@@ -11,7 +11,7 @@ RSpec.describe Gitlab::Experiment::Rollout::Feature, :experiment do
before do
stub_feature_flags(gitlab_experiment: true)
allow(subject).to receive(:feature_flag_defined?).and_return(true)
allow(Gitlab).to receive(:dev_env_or_com?).and_return(true)
allow(Gitlab).to receive(:com?).and_return(true)
allow(subject).to receive(:feature_flag_instance).and_return(double(state: :on))
end
......@@ -26,7 +26,7 @@ RSpec.describe Gitlab::Experiment::Rollout::Feature, :experiment do
end
it "isn't enabled if we're not in dev or dotcom environments" do
expect(Gitlab).to receive(:dev_env_or_com?).and_return(false)
expect(Gitlab).to receive(:com?).and_return(false)
expect(subject).not_to be_enabled
end
......
......@@ -17,7 +17,7 @@ RSpec.describe Gitlab::Experimentation::ControllerConcern, type: :controller do
}
)
allow(Gitlab).to receive(:dev_env_or_com?).and_return(is_gitlab_com)
allow(Gitlab).to receive(:com?).and_return(is_gitlab_com)
Feature.enable_percentage_of_time(:test_experiment_experiment_percentage, enabled_percentage)
end
......
......@@ -25,7 +25,7 @@ RSpec.describe Gitlab::Experimentation::Experiment do
describe '#active?' do
before do
allow(Gitlab).to receive(:dev_env_or_com?).and_return(on_gitlab_com)
allow(Gitlab).to receive(:com?).and_return(on_gitlab_com)
end
subject { experiment.active? }
......
......@@ -80,36 +80,42 @@ RSpec.describe Gitlab do
end
describe '.com?' do
it "is true when on #{Gitlab::Saas.com_url}" do
stub_config_setting(url: Gitlab::Saas.com_url)
context 'when not simulating SaaS' do
before do
stub_env('GITLAB_SIMULATE_SAAS', '0')
end
expect(described_class.com?).to eq true
end
it "is true when on #{Gitlab::Saas.com_url}" do
stub_config_setting(url: Gitlab::Saas.com_url)
it "is true when on #{Gitlab::Saas.staging_com_url}" do
stub_config_setting(url: Gitlab::Saas.staging_com_url)
expect(described_class.com?).to eq true
end
expect(described_class.com?).to eq true
end
it "is true when on #{Gitlab::Saas.staging_com_url}" do
stub_config_setting(url: Gitlab::Saas.staging_com_url)
it 'is true when on other gitlab subdomain' do
url_with_subdomain = Gitlab::Saas.com_url.gsub('https://', 'https://example.')
stub_config_setting(url: url_with_subdomain)
expect(described_class.com?).to eq true
end
expect(described_class.com?).to eq true
end
it 'is true when on other gitlab subdomain' do
url_with_subdomain = Gitlab::Saas.com_url.gsub('https://', 'https://example.')
stub_config_setting(url: url_with_subdomain)
it 'is true when on other gitlab subdomain with hyphen' do
url_with_subdomain = Gitlab::Saas.com_url.gsub('https://', 'https://test-example.')
stub_config_setting(url: url_with_subdomain)
expect(described_class.com?).to eq true
end
expect(described_class.com?).to eq true
end
it 'is true when on other gitlab subdomain with hyphen' do
url_with_subdomain = Gitlab::Saas.com_url.gsub('https://', 'https://test-example.')
stub_config_setting(url: url_with_subdomain)
it 'is false when not on GitLab.com' do
stub_config_setting(url: 'http://example.com')
expect(described_class.com?).to eq true
end
expect(described_class.com?).to eq false
it 'is false when not on GitLab.com' do
stub_config_setting(url: 'http://example.com')
expect(described_class.com?).to eq false
end
end
it 'is true when GITLAB_SIMULATE_SAAS is true and in development' do
......@@ -210,31 +216,23 @@ RSpec.describe Gitlab do
end
end
describe '.dev_env_org_or_com?' do
describe '.org_or_com?' do
it 'is true when on .com' do
allow(described_class).to receive_messages(com?: true, org?: false)
expect(described_class.dev_env_org_or_com?).to eq true
expect(described_class.org_or_com?).to eq true
end
it 'is true when org' do
allow(described_class).to receive_messages(com?: false, org?: true)
expect(described_class.dev_env_org_or_com?).to eq true
expect(described_class.org_or_com?).to eq true
end
it 'is false when not dev, org or com' do
allow(described_class).to receive_messages(com?: false, org?: false)
expect(described_class.dev_env_org_or_com?).to eq false
end
end
describe '.dev_env_or_com?' do
it 'is correctly calling com?' do
expect(described_class).to receive(:com?).and_call_original
expect(described_class.dev_env_or_com?).to eq false
expect(described_class.org_or_com?).to eq false
end
end
......
......@@ -16,7 +16,7 @@ RSpec.describe UpdateTrialPlansCiDailyPipelineScheduleTriggers, :migration do
context 'when the environment is dev or com' do
before do
allow(Gitlab).to receive(:dev_env_or_com?).and_return(true)
allow(Gitlab).to receive(:com?).and_return(true)
end
it 'sets the trial plan limits for ci_daily_pipeline_schedule_triggers' do
......@@ -57,7 +57,7 @@ RSpec.describe UpdateTrialPlansCiDailyPipelineScheduleTriggers, :migration do
context 'when the environment is anything other than dev or com' do
before do
allow(Gitlab).to receive(:dev_env_or_com?).and_return(false)
allow(Gitlab).to receive(:com?).and_return(false)
end
it 'does not update the plan limits' do
......@@ -75,7 +75,7 @@ RSpec.describe UpdateTrialPlansCiDailyPipelineScheduleTriggers, :migration do
context 'when the environment is dev or com' do
before do
allow(Gitlab).to receive(:dev_env_or_com?).and_return(true)
allow(Gitlab).to receive(:com?).and_return(true)
end
it 'sets the trial plan limits ci_daily_pipeline_schedule_triggers to zero' do
......@@ -116,7 +116,7 @@ RSpec.describe UpdateTrialPlansCiDailyPipelineScheduleTriggers, :migration do
context 'when the environment is anything other than dev or com' do
before do
allow(Gitlab).to receive(:dev_env_or_com?).and_return(false)
allow(Gitlab).to receive(:com?).and_return(false)
end
it 'does not change the ultimate trial plan limits' do
......
......@@ -7,7 +7,7 @@ require_migration!
RSpec.describe AddNewTrailPlans, :migration do
describe '#up' do
before do
allow(Gitlab).to receive(:dev_env_or_com?).and_return true
allow(Gitlab).to receive(:com?).and_return true
end
it 'creates 2 entries within the plans table' do
......@@ -40,7 +40,7 @@ RSpec.describe AddNewTrailPlans, :migration do
context 'when the instance is not SaaS' do
before do
allow(Gitlab).to receive(:dev_env_or_com?).and_return false
allow(Gitlab).to receive(:com?).and_return false
end
it 'does not create plans and plan limits and returns' do
......@@ -58,7 +58,7 @@ RSpec.describe AddNewTrailPlans, :migration do
context 'when the instance is SaaS' do
before do
allow(Gitlab).to receive(:dev_env_or_com?).and_return true
allow(Gitlab).to receive(:com?).and_return true
end
it 'removes the newly added ultimate and premium trial entries' do
......@@ -77,7 +77,7 @@ RSpec.describe AddNewTrailPlans, :migration do
context 'when the instance is not SaaS' do
before do
allow(Gitlab).to receive(:dev_env_or_com?).and_return false
allow(Gitlab).to receive(:com?).and_return false
table(:plans).create!(id: 1, name: 'ultimate_trial', title: 'Ultimate Trial')
table(:plans).create!(id: 2, name: 'premium_trial', title: 'Premium Trial')
table(:plan_limits).create!(id: 1, plan_id: 1)
......
......@@ -7,7 +7,7 @@ require_migration!
RSpec.describe AddOpenSourcePlan, :migration do
describe '#up' do
before do
allow(Gitlab).to receive(:dev_env_or_com?).and_return true
allow(Gitlab).to receive(:com?).and_return true
end
it 'creates 1 entry within the plans table' do
......@@ -35,7 +35,7 @@ RSpec.describe AddOpenSourcePlan, :migration do
context 'when the instance is not SaaS' do
before do
allow(Gitlab).to receive(:dev_env_or_com?).and_return false
allow(Gitlab).to receive(:com?).and_return false
end
it 'does not create plans and plan limits and returns' do
......@@ -52,7 +52,7 @@ RSpec.describe AddOpenSourcePlan, :migration do
context 'when the instance is SaaS' do
before do
allow(Gitlab).to receive(:dev_env_or_com?).and_return true
allow(Gitlab).to receive(:com?).and_return true
end
it 'removes the newly added opensource entry' do
......@@ -70,7 +70,7 @@ RSpec.describe AddOpenSourcePlan, :migration do
context 'when the instance is not SaaS' do
before do
allow(Gitlab).to receive(:dev_env_or_com?).and_return false
allow(Gitlab).to receive(:com?).and_return false
table(:plans).create!(id: 1, name: 'opensource', title: 'Open Source Program')
table(:plan_limits).create!(id: 1, plan_id: 1)
end
......
......@@ -9,7 +9,7 @@ RSpec.describe 'devise/sessions/new' do
before do
stub_devise
disable_captcha
allow(Gitlab).to receive(:dev_env_or_com?).and_return(true)
allow(Gitlab).to receive(:com?).and_return(true)
end
it 'when flash is anything it renders marketing text' do
......
......@@ -27,7 +27,7 @@ RSpec.describe 'devise/shared/_signup_box' do
context 'when on .com' do
before do
allow(Gitlab).to receive(:dev_env_or_com?).and_return(true)
allow(Gitlab).to receive(:com?).and_return(true)
end
it 'shows expected GitLab text' do
......@@ -39,7 +39,7 @@ RSpec.describe 'devise/shared/_signup_box' do
context 'when not on .com' do
before do
allow(Gitlab).to receive(:dev_env_or_com?).and_return(false)
allow(Gitlab).to receive(:com?).and_return(false)
end
it 'shows expected text without GitLab' do
......@@ -53,7 +53,7 @@ RSpec.describe 'devise/shared/_signup_box' do
context 'when terms are not enforced' do
before do
allow(Gitlab::CurrentSettings.current_application_settings).to receive(:enforce_terms?).and_return(false)
allow(Gitlab).to receive(:dev_env_or_com?).and_return(true)
allow(Gitlab).to receive(:com?).and_return(true)
end
it 'shows expected text with placeholders' 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