Commit f6215fbb authored by Ash McKenzie's avatar Ash McKenzie

Merge branch 'nicolasdular/subscription-plan-redirect' into 'master'

Redirect to customer portal or registration

See merge request gitlab-org/gitlab!22978
parents f0dd6daf 05b45235
...@@ -2,9 +2,17 @@ ...@@ -2,9 +2,17 @@
class SubscriptionsController < ApplicationController class SubscriptionsController < ApplicationController
layout 'checkout' layout 'checkout'
skip_before_action :authenticate_user!, only: :new
def new def new
return redirect_to dashboard_projects_path unless Feature.enabled?(:paid_signup_flow) if experiment_enabled?(:paid_signup_flow)
return if current_user
store_location_for :user, request.fullpath
redirect_to new_user_registration_path
else
redirect_to customer_portal_new_subscription_url
end
end end
def payment_form def payment_form
...@@ -22,4 +30,8 @@ class SubscriptionsController < ApplicationController ...@@ -22,4 +30,8 @@ class SubscriptionsController < ApplicationController
def client def client
Gitlab::SubscriptionPortal::Client Gitlab::SubscriptionPortal::Client
end end
def customer_portal_new_subscription_url
"#{EE::SUBSCRIPTIONS_URL}/subscriptions/new?plan_id=#{params[:plan_id]}&transaction=create_subscription"
end
end end
...@@ -8,33 +8,40 @@ describe SubscriptionsController do ...@@ -8,33 +8,40 @@ describe SubscriptionsController do
describe 'GET #new' do describe 'GET #new' do
subject { get :new, params: { plan_id: 'bronze_id' } } subject { get :new, params: { plan_id: 'bronze_id' } }
context 'with unauthorized user' do context 'with experiment enabled' do
it { is_expected.to have_gitlab_http_status 302 }
it { is_expected.to redirect_to new_user_session_path }
end
context 'with authorized user' do
before do before do
sign_in(user) stub_experiment(paid_signup_flow: true)
stub_experiment_for_user(paid_signup_flow: true)
end
context 'with unauthorized user' do
it { is_expected.to have_gitlab_http_status 302 }
it { is_expected.to redirect_to new_user_registration_path }
it 'stores subscription URL for later' do
subject
expect(controller.stored_location_for(:user)).to eq(new_subscriptions_path(plan_id: 'bronze_id'))
end
end end
context 'with feature flag enabled' do context 'with authorized user' do
before do before do
stub_feature_flags(paid_signup_flow: true) sign_in(user)
end end
it { is_expected.to render_template 'layouts/checkout' } it { is_expected.to render_template 'layouts/checkout' }
it { is_expected.to render_template :new } it { is_expected.to render_template :new }
end end
end
context 'with feature flag disabled' do context 'with experiment disabled' do
before do before do
stub_feature_flags(paid_signup_flow: false) stub_experiment(paid_signup_flow: false)
end stub_experiment_for_user(paid_signup_flow: false)
it { is_expected.to have_gitlab_http_status 302 }
it { is_expected.to redirect_to dashboard_projects_path }
end end
it { is_expected.to redirect_to "#{EE::SUBSCRIPTIONS_URL}/subscriptions/new?plan_id=bronze_id&transaction=create_subscription" }
end end
end end
......
...@@ -16,6 +16,12 @@ module Gitlab ...@@ -16,6 +16,12 @@ module Gitlab
environment: ::Gitlab.dev_env_or_com?, environment: ::Gitlab.dev_env_or_com?,
enabled_ratio: 1, enabled_ratio: 1,
tracking_category: 'Growth::Acquisition::Experiment::SignUpFlow' tracking_category: 'Growth::Acquisition::Experiment::SignUpFlow'
},
paid_signup_flow: {
feature_toggle: :paid_signup_flow,
environment: ::Gitlab.dev_env_or_com?,
enabled_ratio: 0.1,
tracking_category: 'Growth::Acquisition::Experiment::PaidSignUpFlow'
} }
}.freeze }.freeze
......
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