Commit 5e4d2bfe authored by Kerri Miller's avatar Kerri Miller

Merge branch 'ask-cc-info-to-new-users' into 'master'

Require credit card info to new users only

See merge request gitlab-org/gitlab!61499
parents 781e21fa b4b478ca
...@@ -2,6 +2,8 @@ ...@@ -2,6 +2,8 @@
module Users module Users
class CreditCardValidation < ApplicationRecord class CreditCardValidation < ApplicationRecord
RELEASE_DAY = Date.new(2021, 5, 17)
self.table_name = 'user_credit_card_validations' self.table_name = 'user_credit_card_validations'
belongs_to :user belongs_to :user
......
...@@ -397,12 +397,32 @@ module EE ...@@ -397,12 +397,32 @@ module EE
!password_automatically_set? !password_automatically_set?
end end
def has_required_credit_card_to_run_pipelines?(project)
has_valid_credit_card? || !requires_credit_card_to_run_pipelines?(project)
end
protected
override :password_required?
def password_required?(*)
return false if group_managed_account?
super
end
private
def created_after_credit_card_release_day?
created_at >= ::Users::CreditCardValidation::RELEASE_DAY
end
def has_valid_credit_card? def has_valid_credit_card?
credit_card_validated_at.present? credit_card_validated_at.present?
end end
def requires_credit_card_to_run_pipelines?(project) def requires_credit_card_to_run_pipelines?(project)
return false unless ::Gitlab.com? return false unless ::Gitlab.com?
return false unless created_after_credit_card_release_day?
root_namespace = project.root_namespace root_namespace = project.root_namespace
if root_namespace.free_plan? if root_namespace.free_plan?
...@@ -414,21 +434,6 @@ module EE ...@@ -414,21 +434,6 @@ module EE
end end
end end
def has_required_credit_card_to_run_pipelines?(project)
has_valid_credit_card? || !requires_credit_card_to_run_pipelines?(project)
end
protected
override :password_required?
def password_required?(*)
return false if group_managed_account?
super
end
private
def namespace_union_for_owned(select = :id) def namespace_union_for_owned(select = :id)
::Gitlab::SQL::Union.new([ ::Gitlab::SQL::Union.new([
::Namespace.select(select).where(type: nil, owner: self), ::Namespace.select(select).where(type: nil, owner: self),
......
...@@ -1683,24 +1683,27 @@ RSpec.describe User do ...@@ -1683,24 +1683,27 @@ RSpec.describe User do
using RSpec::Parameterized::TableSyntax using RSpec::Parameterized::TableSyntax
where(:is_saas, :cc_present, :is_free, :is_trial, :free_ff_enabled, :trial_ff_enabled, :result) do where(:is_saas, :cc_present, :is_free, :is_trial, :free_ff_enabled, :trial_ff_enabled, :days_from_release, :result) do
# self-hosted # self-hosted
false | false | false | false | true | true | true # paid plan false | false | false | false | true | true | 0 | true # paid plan
false | false | false | true | true | true | true # missing CC on trial plan false | false | false | true | true | true | 0 | true # missing CC on trial plan
# saas # saas
true | false | false | false | true | true | true # missing CC on paid plan true | false | false | false | true | true | 0 | true # missing CC on paid plan
true | false | true | false | true | true | false # missing CC on free plan true | false | true | false | true | true | 0 | false # missing CC on free plan
true | false | true | false | false | true | true # missing CC on free plan - FF off true | false | true | false | true | true | -1 | true # missing CC on free plan but old user
true | false | false | true | true | true | false # missing CC on trial plan true | false | true | false | false | true | 0 | true # missing CC on free plan - FF off
true | false | false | true | true | false | true # missing CC on trial plan - FF off true | false | false | true | true | true | 0 | false # missing CC on trial plan
true | true | true | false | true | true | true # present CC on free plan true | false | false | true | true | true | -1 | true # missing CC on trial plan but old user
true | true | false | true | true | true | true # present CC on trial plan true | false | false | true | true | false | 0 | true # missing CC on trial plan - FF off
true | true | true | false | true | true | 0 | true # present CC on free plan
true | true | false | true | true | true | 0 | true # present CC on trial plan
end end
with_them do with_them do
before do before do
allow(::Gitlab).to receive(:com?).and_return(is_saas) allow(::Gitlab).to receive(:com?).and_return(is_saas)
user.created_at = ::Users::CreditCardValidation::RELEASE_DAY + days_from_release.days
allow(user).to receive(:credit_card_validated_at).and_return(Time.current) if cc_present allow(user).to receive(:credit_card_validated_at).and_return(Time.current) if cc_present
allow(project.namespace).to receive(:free_plan?).and_return(is_free) allow(project.namespace).to receive(:free_plan?).and_return(is_free)
allow(project.namespace).to receive(:trial?).and_return(is_trial) allow(project.namespace).to receive(:trial?).and_return(is_trial)
......
...@@ -187,6 +187,7 @@ RSpec.describe Ci::CreatePipelineService, '#execute' do ...@@ -187,6 +187,7 @@ RSpec.describe Ci::CreatePipelineService, '#execute' do
before do before do
allow(::Gitlab).to receive(:com?).and_return(true) allow(::Gitlab).to receive(:com?).and_return(true)
namespace.gitlab_subscription.update!(hosted_plan: create(:free_plan)) namespace.gitlab_subscription.update!(hosted_plan: create(:free_plan))
user.created_at = ::Users::CreditCardValidation::RELEASE_DAY
end end
context 'when user has credit card' do context 'when user has credit card' 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