Commit b4b478ca authored by Fabio Pitino's avatar Fabio Pitino

Require credit card info to new users only

When user needs to run a pipeline ensure we don't
affect any user prior to the release day.
parent fb9302b4
......@@ -2,6 +2,8 @@
module Users
class CreditCardValidation < ApplicationRecord
RELEASE_DAY = Date.new(2021, 5, 17)
self.table_name = 'user_credit_card_validations'
belongs_to :user
......
......@@ -397,12 +397,32 @@ module EE
!password_automatically_set?
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?
credit_card_validated_at.present?
end
def requires_credit_card_to_run_pipelines?(project)
return false unless ::Gitlab.com?
return false unless created_after_credit_card_release_day?
root_namespace = project.root_namespace
if root_namespace.free_plan?
......@@ -414,21 +434,6 @@ module EE
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)
::Gitlab::SQL::Union.new([
::Namespace.select(select).where(type: nil, owner: self),
......
......@@ -1683,24 +1683,27 @@ RSpec.describe User do
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
false | false | false | false | true | true | true # paid plan
false | false | false | true | true | true | true # missing CC on trial plan
false | false | false | false | true | true | 0 | true # paid plan
false | false | false | true | true | true | 0 | true # missing CC on trial plan
# saas
true | false | false | false | true | true | true # missing CC on paid plan
true | false | true | false | true | true | false # missing CC on free plan
true | false | true | false | false | true | true # missing CC on free plan - FF off
true | false | false | true | true | true | false # missing CC on trial plan
true | false | false | true | true | false | true # missing CC on trial plan - FF off
true | true | true | false | true | true | true # present CC on free plan
true | true | false | true | true | true | true # present CC on trial plan
true | false | false | false | true | true | 0 | true # missing CC on paid plan
true | false | true | false | true | true | 0 | false # missing CC on free plan
true | false | true | false | true | true | -1 | true # missing CC on free plan but old user
true | false | true | false | false | true | 0 | true # missing CC on free plan - FF off
true | false | false | true | true | true | 0 | false # missing CC on trial plan
true | false | false | true | true | true | -1 | true # missing CC on trial plan but old user
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
with_them do
before do
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(project.namespace).to receive(:free_plan?).and_return(is_free)
allow(project.namespace).to receive(:trial?).and_return(is_trial)
......
......@@ -187,6 +187,7 @@ RSpec.describe Ci::CreatePipelineService, '#execute' do
before do
allow(::Gitlab).to receive(:com?).and_return(true)
namespace.gitlab_subscription.update!(hosted_plan: create(:free_plan))
user.created_at = ::Users::CreditCardValidation::RELEASE_DAY
end
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